Differences between version 9 and revision by previous author of GCBot.
Other diffs: Previous Major Revision, Previous Revision, or view the Annotated Edit History
Newer page: | version 9 | Last edited on Friday, December 3, 2004 4:12:33 pm | by AristotlePagaltzis | Revert |
Older page: | version 4 | Last edited on Thursday, December 2, 2004 3:25:45 pm | by CraigBox | Revert |
@@ -1,95 +1,138 @@
-GCBot is an [IRC] bot that [Isomer|
PerryLorier]
made to see what happens if you give a bunch of programmers a shared programming environment (
IRC) and what happens
.
+[
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]
.
-GCBot's programming
language is very simple, everything
is either a symbol, a function call, a list, a string or a number.
+The
language is trivial. Everything
is either a symbol, a function call, a list, a string or a number. The grammar is very simple:
-The grammer is very simple
:
+<verbatim>
+<literal>
::= "string"
+ | 'string'
+ | [-9]\.[-9]
-
<literal
>::= "string"
- | 'string'
- |
[[-9
]\.[[-9
]
+<symbol
> ::= [^,()\
[\
]]
-
<symbol
> ::= [[^
,()\[[\]]
+<comma-expression
> ::= <expression>
+ | <expression> '
,' <comma-expression>
-
<comma
-expression
> ::= <expression
>
- | <expression> ',' <comma-expression
>
+<symbol
-or-literal
> ::= <symbol
>
+ | <literal
>
-
<symbol-or-literal
> ::= <symbol
>
-
| <literal>
+<term
> ::= '['
<comma-expression
> ']'
+
| <symbol-or-
literal>
-
<term
> ::= '[[
' <comma-expression>
']
'
- |
<symbol-or-literal
>
+<expression
> ::= <term>
+ | <term>
'(
' <comma-expression ')
'
+</verbatim
>
- <expression>
::=
<term
>
- |
<term
> '(' <comma-expression ')'
+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
>.
-* strings, lists and numbers, when called with no arguments evaluate to themselves
-* everything is prefix notation, eg
: to add four numbers, you need to do +(1,2,3,4)
+!!! Builtins
:
-!!!Builtins:
-!!
+(args
...)
-Returns the sum of all of it
's arguments
+__<tt>
+(''arguments
...'')</tt>__:
-!!/(args...)
-
Returns the first argument divided by the second etc
.
+
Returns the sum of all of its arguments
.
-!!
<(a,b)
-Returns non zero if a is less than b, 0 otherwise
.
+__
<tt>/
(''arguments
...'')</tt>__:
-!!->string(x)
-
Returns the string representation of x. Beware, this does not evaluate x
.
+
Returns the first argument divided by the second etc
.
-!!apply
(''expression
'',''list of arguments
'')
-Calls ''expression'' with ''arguments''.
-eg
:
- apply(+,[[1,2,3])
+__<tt><
(''a
'',''b
'')</tt>__
:
-!!at(''list'',''expression'')
-
Returns the
''expression
''th item in
''list
''
+
Returns non-zero if <tt>
''a
''</tt> is less than <tt>
''b
''</tt>, 0 otherwise.
-!!catch
(''expression'',''exception handler
'')
-Calls expression, if an exception is raised, then exception handler is called with the exception passed as the only argument.
+__<tt>->string
(''arg
'')</tt>__:
-!!decompose(
''functioncall
'')
-Returns a list of the head of the function call, a the list of the arguments
.
-eg:
- decompose(+(1,2
,3)) =
> [[+,[[1,2,3]]
+ Returns the string representation of <tt>
''arg
''</tt>
. Beware
, this does not evaluate <tt
>''arg''</tt>.
-!!define
(''name
'',''vars'',''expression
'')
-This works like lambda, however it also binds it to a name. define could have been implemented as
:
- lambda([[name,vars,expression],set(name,lambda(vars,expression)))
+__<tt>apply
(''expression
'',''arguments...
'')</tt>__
:
-!!head(
''list
'')
-Returns the first item of list
.
+ Calls <tt>
''expression
''</tt> with <tt>''arguments''</tt>
. Eg:
-!!ifelse
(cond
,true
,false
)
-This function evaluates cond, then evaluates either true or false depending on the result of cond. Anything that isn't 0 is considered true.
+ <verbatim>
+ apply
(+
,[1
,2,3]
)
+ </verbatim>
-!!lambda
(''vars
'',''expression'')
-Takes a list of variables, and when called replaces each variable with it's corresponding positional argument everywhere in the expression. For example
:
- lambda([[a,b],+(a,b))
-will create an anonymous function that takes two arguments (a and b) and returns their sum. eg:
- lambda([[a,b],+(a,b))(1,2) => 3
-beaware that the bindings of lambda's variables can be cached, so if a function can return different values every time it's called, you may end up with some unexpected results.
+__<tt>at
(''list
'',''expression'')</tt>__
:
-!!now()
-
Returns the number of seconds since 1970-01-01. Beaware that this function changes it
's result everytime you call it, and may interact badly with lambda
's primative caching
.
+
Returns the item at position <tt>
''expression''</tt> in the <tt>''list''</tt>
.
-!!say
(''channel
'',''expression
'')
-Will say in ''channel'' the result of expression
+__<tt>catch
(''expression
'',''exceptionhandler
'')</tt>__:
-!!set(
''name
'',''expression
'')
-Binds expression to name
.
+ Calls <tt>
''expression
''</tt>
, then calls <tt>
''exceptionhandler
''</tt> (passing it the exception
) if one was raised
.
-!!syms
()
-Returns the list of all symbols that are currently defined in the symbol table.
+__<tt>decompose
(''functioncall''
)</tt>__:
-!!tail(
''list
'')
-Returns everything but
the first item
of ''list''
.
+ Decomposes <tt>
''functioncall
''</tt> into a list with
the function as head and the list
of the arguments as tail
. Eg:
-!!throw
(''string''
)
-Throws an exception given by string.
+ <verbatim>
+ decompose
(+(1,2,3)
) => [+,[1,2,3]]
+ </verbatim>
-!!
undef(''name'')
-Unbinds name, returning the previous expression that name was bound to.
-
eg:
- define(rename,[
[old,new],set(new,undef(old)))
+__<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>
+
+----
+CategoryProgrammingLanguages