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