# How to Add System Functions to GNU APL

Jürgen Sauermann, GNU APL

## Abstract

In order to add a system function, say ⎕FOO, to GNU APL the following steps are needed.

## configure.ac

If ⎕FOO depends on a libraries (say LIBFOO) then add check for them in configure.ac.

## src/Id.def

Add a macro for ⎕FOO in src/Id.def:

    qf( FOO           , "⎕FOO"    ,          )

The position in the file is important: append to the group of IDs for the letter F (first character in FOO). qf is the macro for Quad-functions.

## "src/Quad_FOO.hh

create this file:

    #ifndef __Quad_FOO_DEFINED__
    #define __Quad_FOO_DEFINED__

    #include "QuadFunction.hh"
    ...

    class Quad_FOO : public QuadFunction
    {
    public:
       /// Constructor.
       Quad_FOO()
          : QuadFunction(TOK_Quad_FOO),
            system_wisdom_loaded(false)
       {}

       static Quad_FOO * fun;          ///< Built-in function.
       static Quad_FOO  _fun;          ///< Built-in function.

    protected:
       /// overloaded Function::eval_AB()
       Token eval_AB(Value_P A, Value_P B);

       /// overloaded Function::eval_B()
       Token eval_B(Value_P B);

       ...
    };

    #endif // __Quad_FOO_DEFINED__

## "src/Quad_FOO.cc

create this file:

    #include "Quad_FOO.hh"

    Quad_FOO  Quad_FOO::_fun;
    Quad_FOO * Quad_FOO::fun = &Quad_FOO::_fun;

    #if defined(HAVE_LIBFOO) && defined(HAVE_FOO_H)

    ...
    #else // no LIBFOO...

    //-----------------------------------------------------------------------------
    Token
    Quad_FOO::eval_B(Value_P B)
    {
        MORE_ERROR() <<
    "⎕FOO is not available because either no libpcre2 libfftw3 was found on
    this\n"
    "system when GNU APL was compiled, or because it was disabled in
    ./configure.";

       SYNTAX_ERROR;
       return Token();
    }
    //-----------------------------------------------------------------------------
    Token
    Quad_FOO::eval_AB(Value_P A, Value_P B)
    {
        MORE_ERROR() <<
    "⎕FOO is not available because either no libfftw3 library was found on this\n"
    "system when GNU APL was compiled, or because it was disabled in
    ./configure.";

       SYNTAX_ERROR;
       return Token();
    }
    //-----------------------------------------------------------------------------

    #endif // HAVE_FOO_H

SVN: add the new giles to the repository:

    svn add Quad_FOO.cc Quad_FOO.hh
    svn commit

## src/Id.cc

add:

    #include "Quad_FOO.hh"

## src/QuadFunction.cc

add:

    #include "Quad_FOO.hh"

## src/Workspace.cc

add:

    #include "Quad_FOO.hh"

## src/Makefile.am

add Quad_FOO.cc and Quad_FOO.hh to common_SOURCES:

    Quad_FOO.cc                                     Quad_FOO.hh             \

## src/Token.def

Add a TD() macro for ⎕FOO in src/Token.def:

    TD(TOK_Quad_FOO      , TC_FUN2      , TV_FUN  , ID::Quad_FOO     )

## src/SystemVariable.def

add a sf_def() macro:

      sf_def(Quad_FOO,   "FOO",   "Definitely not ⎕BAR"          )

## Finalize

    autoreconf
    ./configure
    make