The Egel Language

DIR home
    1: EGEL(1)                     General Commands Manual                    EGEL(1)
    2: 
    3: NAME
    4:        egel - an untyped functional scripting language
    5: 
    6: SYNOPSIS
    7: DESCRIPTION
    8:        Egel  is  an  untyped concurrent functional scripting language based on
    9:        eager combinator rewriting with a concise but remarkably powerful  syn‐
   10:        tax.
   11: 
   12:        Egel's  basic functionality can be extended with your own modules writ‐
   13:        ten in C++. Those modules are dynamically loaded.
   14: 
   15: OPTIONS
   16:        -h, --help
   17:               Prints brief usage information, may list debug options.
   18: 
   19:        -v, --version
   20:               Prints the current version number.
   21: 
   22:        -, --interact
   23:               Enter interactive mode unconditionally.
   24: 
   25:        -e, --eval <command>
   26:               Evaluate the given command.
   27: 
   28:        -I, --include <path>
   29:               Add an include path.
   30: 
   31: TUTORIAL
   32:        Egel is an expression language and the interpreter a  symbolic  evalua‐
   33:        tor.
   34: 
   35:    Expressions
   36:        Egel code consist of expression which are evaluated eagerly.
   37: 
   38:        •   Basic primitives are integers, floats, complex, unicode characters,
   39:            and unicode strings.
   40: 
   41:            0 1 2 , 0.0 3.14 -1.2+3.4j , 'a' '∀' , or "Hello World!"
   42: 
   43:        •   All constants compose.
   44: 
   45:            (0 1) is just as legal as (cons 'a' nil)
   46: 
   47:        •   Rewriting  is done with the pattern-matching anonymous abstraction,
   48:            uppercase letters denote variables.
   49: 
   50:            [ X -> X ] , [ (cons HEAD TAIL) -> HEAD ]
   51: 
   52:            The abstraction consists of a number of matches, it may be variadic
   53:            without penalty.
   54: 
   55:            [ X Y -> 2 | X -> 1 | -> 0]
   56: 
   57:            A backslash \ starts a lambda abstraction.
   58: 
   59:            \(cons X XX) -> X
   60: 
   61:        •   Patterns may match against tags.
   62: 
   63:            [ I:int -> "an int" | C:cons -> "a cons" ]
   64: 
   65:        •   Let expressions assign values to intermediaries.
   66: 
   67:            let X = 1 + 2 in X * X
   68: 
   69:        •   A semicolon separates computations.
   70: 
   71:            print (1+2); "done"
   72: 
   73:        •   Exception handling is  supported,  any  value  may  be  thrown  and
   74:            caught.
   75: 
   76:            try 1 + throw "failure" catch [ EXC -> print EXC ]
   77: 
   78:        •   The do notation composes chains of transformations.
   79: 
   80:            (do ((+) 1) |> foldl (*) 1) (from_to 0 4)
   81: 
   82:        •   Parallell  programming is achieved through the async/await combina‐
   83:            tors. Asynchronous programs start threads that  return  future  ob‐
   84:            jects.
   85: 
   86:            let F = async [ _ -> fib 35 ] in await F
   87: 
   88:        •   Formatting  strings  is  handled  with  the  format combinator, see
   89:            https://fmt.dev/.
   90: 
   91:            print (format "Hello {}" "world")
   92: 
   93:        •   The interpreter implements a term rewriter though has mutable  ref‐
   94:            erences. Cycles won't be garbage collected.
   95: 
   96:            let X = ref 0 in set_ref X 1; get_ref X
   97: 
   98:    Declarations
   99:        Declarations define combinators.
  100: 
  101:        •   A data declaration introduces constants.
  102: 
  103:            data leaf, branch
  104: 
  105:        •   A def declaration introduces a combinator.
  106: 
  107:            def fac = [0 -> 1 | N -> N * fac (N - 1)
  108: 
  109:        •   A  val  declaration introduces a combinator who's body is evaluated
  110:            prior to it's definition.
  111: 
  112:            val global = ref 3.14
  113: 
  114:    Modules
  115:        A module is a series of combinator declarations  possibly  encapsulated
  116:        in a namespace. All combinators are named lowercase, there is some pro‐
  117:        visional  support  for unicode. Modules may import each other. The main
  118:        combinator of the top module drives all computation when present.
  119: 
  120:        Tying it all together:
  121: 
  122:            # A Fibonacci implementation.
  123: 
  124:            import "prelude.eg"
  125: 
  126:            namespace Fibonacci (
  127:              using System
  128: 
  129:              def fib =
  130:                [ 0 -> 0
  131:                | 1 -> 1
  132:                | N -> fib (N- 2) + fib (N- 1) ]
  133: 
  134:            )
  135: 
  136:            using System
  137: 
  138:            def main = Fibonacci::fib (3+2)
  139: 
  140: EXAMPLES
  141:        There are three modes in which the interpreter is used: batch, interac‐
  142:        tive, or command mode.
  143: 
  144:        In batch mode, just supply the top module with a main combinator.
  145: 
  146:            $ egel helloworld.eg
  147:            Hello world!
  148: 
  149:        The interpreter will start in interactive mode when invoked  without  a
  150:        module argument.
  151: 
  152:            $ egel
  153:            > using System
  154:            > 1 + 1
  155:            2
  156: 
  157:        Supply  a  command  to use egel -e as a simple calculator. Double semi‐
  158:        colons are separators.
  159: 
  160:            $ egel fib.eg -e "using Fibonacci;; fib 3"
  161:            5
  162: 
  163: FILES
  164:        The following files should be in the EGEL_PATH directory.
  165: 
  166:        prelude.eg calculate.eg search.eg
  167:               The standard Egel prelude and additional scripts.
  168: 
  169:        random.ego, etc.
  170:               Dynamically loaded libraries.
  171: 
  172: ENVIRONMENT
  173:        EGEL_PATH
  174:               The directories that are searched for inclusion.
  175: 
  176:        EGEL_PS0
  177:               The prompt given by the interpreter in interactive mode.
  178: 
  179: BUGS
  180:        See GitHub Issues: https://github.com/egel-lang/egel/issues
  181: 
  182: AUTHOR
  183:        MIT License (c) 2017 M.C.A. (Marco) Devillers [email protected]
  184: 
  185: SEE ALSO
  186:        c++(1)
  187: 
  188:                                 September 2024                         EGEL(1)
  189: