| Rev | Author | # | Line |
|---|---|---|---|
| 9 | AristotlePagaltzis | 1 | [GCBot] is an [IRC] bot and a ProgrammingLanguage by PerryLorier made to see what happens if you give a bunch of programmers a shared programming environment, ie [IRC]. |
| 2 | |||
| 3 | The language is trivial. Everything is either a symbol, a function call, a list, a string or a number. The grammar is very simple: | ||
| 4 | |||
| 5 | <verbatim> | ||
| 6 | <literal>::= "string" | ||
| 7 | | 'string' | ||
| 8 | | [0-9]\.[0-9] | ||
| 9 | |||
| 10 | <symbol> ::= [^,()\[\]] | ||
| 11 | |||
| 12 | <comma-expression> ::= <expression> | ||
| 13 | | <expression> ',' <comma-expression> | ||
| 14 | |||
| 15 | <symbol-or-literal> ::= <symbol> | ||
| 16 | | <literal> | ||
| 17 | |||
| 18 | <term> ::= '[' <comma-expression> ']' | ||
| 19 | | <symbol-or-literal> | ||
| 20 | |||
| 21 | <expression> ::= <term> | ||
| 22 | | <term> '(' <comma-expression ')' | ||
| 23 | </verbatim> | ||
| 24 | |||
| 25 | Strings, lists and numbers can be called without arguments and evaluate to themselves. Everything is prefix notation, eg: to add four numbers, you need <tt>+(1,2,3,4)</tt>. | ||
| 26 | |||
| 27 | !!! Builtins: | ||
| 28 | |||
| 29 | __<tt>+(''arguments...'')</tt>__: | ||
| 30 | |||
| 31 | Returns the sum of all of its arguments. | ||
| 32 | |||
| 33 | __<tt>/(''arguments...'')</tt>__: | ||
| 34 | |||
| 35 | Returns the first argument divided by the second etc. | ||
| 36 | |||
| 37 | __<tt><(''a'',''b'')</tt>__: | ||
| 38 | |||
| 39 | Returns non-zero if <tt>''a''</tt> is less than <tt>''b''</tt>, 0 otherwise. | ||
| 40 | |||
| 41 | __<tt>->string(''arg'')</tt>__: | ||
| 42 | |||
| 43 | Returns the string representation of <tt>''arg''</tt>. Beware, this does not evaluate <tt>''arg''</tt>. | ||
| 44 | |||
| 45 | __<tt>apply(''expression'',''arguments...'')</tt>__: | ||
| 46 | |||
| 47 | Calls <tt>''expression''</tt> with <tt>''arguments''</tt>. Eg: | ||
| 48 | |||
| 49 | <verbatim> | ||
| 50 | apply(+,[1,2,3]) | ||
| 51 | </verbatim> | ||
| 52 | |||
| 53 | __<tt>at(''list'',''expression'')</tt>__: | ||
| 54 | |||
| 55 | Returns the item at position <tt>''expression''</tt> in the <tt>''list''</tt>. | ||
| 56 | |||
| 57 | __<tt>catch(''expression'',''exceptionhandler'')</tt>__: | ||
| 58 | |||
| 59 | Calls <tt>''expression''</tt>, then calls <tt>''exceptionhandler''</tt> (passing it the exception) if one was raised. | ||
| 60 | |||
| 61 | __<tt>decompose(''functioncall'')</tt>__: | ||
| 62 | |||
| 63 | Decomposes <tt>''functioncall''</tt> into a list with the function as head and the list of the arguments as tail. Eg: | ||
| 64 | |||
| 65 | <verbatim> | ||
| 66 | decompose(+(1,2,3)) => [+,[1,2,3]] | ||
| 67 | </verbatim> | ||
| 68 | |||
| 69 | __<tt>define(''name'',''vars'',''expression'')</tt>__: | ||
| 70 | |||
| 71 | This works like <tt>lambda()</tt>, but also binds the resulting anonymous function to a name. | ||
| 72 | |||
| 73 | In effect it is the same as | ||
| 74 | |||
| 75 | <verbatim> | ||
| 76 | set(define,lambda([name,vars,expression],set(name,lambda(vars,expression)))) | ||
| 77 | </verbatim> | ||
| 78 | |||
| 79 | __<tt>head(''list'')</tt>__: | ||
| 80 | |||
| 81 | Returns the first item of <tt>''list''</tt>. | ||
| 82 | |||
| 83 | __<tt>ifelse(''cond'',''true-expr'',''false-expr'')</tt>__: | ||
| 84 | |||
| 85 | This function evaluates <tt>''cond''</tt> to decide whether to evaluate <tt>''true-expr''</tt> or <tt>''false-expr''</tt>. | ||
| 86 | Any result from evaluating <tt>''cond''</tt> other than 0 is considered true. | ||
| 87 | |||
| 88 | __<tt>lambda(''vars'',''expression'')</tt>__: | ||
| 89 | |||
| 90 | Given a list of <tt>''vars''</tt>, replaces each variable with its corresponding positional argument everywhere in <tt>''expression''</tt>. | ||
| 91 | Beware that the bindings of the lambda's variables can be cached, so if a function's return value may vary across calls with identical arguments, you are likely to end up with unexpected results. | ||
| 92 | |||
| 93 | As an example you could create an anonymous function that takes two arguments (a and b) and returns their sum: | ||
| 94 | |||
| 95 | <verbatim> | ||
| 96 | lambda([a,b],+(a,b)) | ||
| 97 | </verbatim> | ||
| 98 | |||
| 99 | Then call it: | ||
| 100 | |||
| 101 | <verbatim> | ||
| 102 | lambda([a,b],+(a,b))(1,2) => 3 | ||
| 103 | </verbatim> | ||
| 104 | |||
| 105 | __<tt>now()</tt>__: | ||
| 106 | |||
| 107 | Returns the number of seconds since 1970-01-01. This function is not cachable; pay attention if you use it in <tt>lambda</tt> constructs. | ||
| 108 | |||
| 109 | __<tt>say(''channel'',''expression'')</tt>__: | ||
| 110 | |||
| 111 | Evaluates <tt>''expression''</tt> and says the result in <tt>''channel''</tt>. | ||
| 112 | |||
| 113 | __<tt>set(''name'',''expression'')</tt>__: | ||
| 114 | |||
| 115 | Binds <tt>''expression''</tt> to <tt>''name''</tt>. | ||
| 116 | |||
| 117 | __<tt>syms()</tt>__: | ||
| 118 | |||
| 119 | Returns the list of all symbols that are currently defined in the symbol table. | ||
| 120 | |||
| 121 | __<tt>tail(''list'')</tt>__: | ||
| 122 | |||
| 123 | Returns everything but the first item of <tt>''list''</tt>. | ||
| 124 | |||
| 125 | __<tt>throw(''string'')</tt>__: | ||
| 126 | |||
| 127 | Throws an exception given by <tt>''string''</tt>. | ||
| 128 | |||
| 129 | __<tt>undef(''name'')</tt>__: | ||
| 130 | |||
| 131 | Unbinds <tt>''name''</tt>, returning the previous expression that name was bound to, eg: | ||
| 132 | |||
| 133 | <verbatim> | ||
| 134 | define(rename,[old,new],set(new,undef(old))) | ||
| 135 | </verbatim> | ||
| 13 | JohnMcPherson | 136 | |
| 11 | JohnMcPherson | 137 | |
| 9 | AristotlePagaltzis | 138 | ---- |
| 139 | Part of CategoryProgrammingLanguages, CategoryFunctionalProgrammingLanguages |
lib/blame.php:177: Warning: Invalid argument supplied for foreach()