Home
Main website
Display Sidebar
Hide Ads
Recent Changes
View Source:
GCBot
Edit
PageHistory
Diff
Info
LikePages
[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]. The language is trivial. Everything is either a symbol, a function call, a list, a string or a number. The grammar is very simple: <verbatim> <literal>::= "string" | 'string' | [0-9]\.[0-9] <symbol> ::= [^,()\[\]] <comma-expression> ::= <expression> | <expression> ',' <comma-expression> <symbol-or-literal> ::= <symbol> | <literal> <term> ::= '[' <comma-expression> ']' | <symbol-or-literal> <expression> ::= <term> | <term> '(' <comma-expression ')' </verbatim> 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>. !!! Builtins: __<tt>+(''arguments...'')</tt>__: Returns the sum of all of its arguments. __<tt>/(''arguments...'')</tt>__: Returns the first argument divided by the second etc. __<tt><(''a'',''b'')</tt>__: Returns non-zero if <tt>''a''</tt> is less than <tt>''b''</tt>, 0 otherwise. __<tt>->string(''arg'')</tt>__: Returns the string representation of <tt>''arg''</tt>. Beware, this does not evaluate <tt>''arg''</tt>. __<tt>apply(''expression'',''arguments...'')</tt>__: Calls <tt>''expression''</tt> with <tt>''arguments''</tt>. Eg: <verbatim> apply(+,[1,2,3]) </verbatim> __<tt>at(''list'',''expression'')</tt>__: Returns the item at position <tt>''expression''</tt> in the <tt>''list''</tt>. __<tt>catch(''expression'',''exceptionhandler'')</tt>__: Calls <tt>''expression''</tt>, then calls <tt>''exceptionhandler''</tt> (passing it the exception) if one was raised. __<tt>decompose(''functioncall'')</tt>__: Decomposes <tt>''functioncall''</tt> into a list with the function as head and the list of the arguments as tail. Eg: <verbatim> decompose(+(1,2,3)) => [+,[1,2,3]] </verbatim> __<tt>define(''name'',''vars'',''expression'')</tt>__: This works like <tt>lambda()</tt>, but also binds the resulting anonymous function to a name. In effect it is the same as <verbatim> set(define,lambda([name,vars,expression],set(name,lambda(vars,expression)))) </verbatim> __<tt>head(''list'')</tt>__: Returns the first item of <tt>''list''</tt>. __<tt>ifelse(''cond'',''true-expr'',''false-expr'')</tt>__: This function evaluates <tt>''cond''</tt> to decide whether to evaluate <tt>''true-expr''</tt> or <tt>''false-expr''</tt>. Any result from evaluating <tt>''cond''</tt> other than 0 is considered true. __<tt>lambda(''vars'',''expression'')</tt>__: Given a list of <tt>''vars''</tt>, replaces each variable with its corresponding positional argument everywhere in <tt>''expression''</tt>. 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. As an example you could create an anonymous function that takes two arguments (a and b) and returns their sum: <verbatim> lambda([a,b],+(a,b)) </verbatim> Then call it: <verbatim> lambda([a,b],+(a,b))(1,2) => 3 </verbatim> __<tt>now()</tt>__: 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. __<tt>say(''channel'',''expression'')</tt>__: Evaluates <tt>''expression''</tt> and says the result in <tt>''channel''</tt>. __<tt>set(''name'',''expression'')</tt>__: Binds <tt>''expression''</tt> to <tt>''name''</tt>. __<tt>syms()</tt>__: Returns the list of all symbols that are currently defined in the symbol table. __<tt>tail(''list'')</tt>__: Returns everything but the first item of <tt>''list''</tt>. __<tt>throw(''string'')</tt>__: Throws an exception given by <tt>''string''</tt>. __<tt>undef(''name'')</tt>__: Unbinds <tt>''name''</tt>, returning the previous expression that name was bound to, eg: <verbatim> define(rename,[old,new],set(new,undef(old))) </verbatim> ---- Part of CategoryProgrammingLanguages, CategoryFunctionalProgrammingLanguages
No page links to
GCBot
.