A minimal, sciencefriendly Lisp implemented in C, inspired by C and Python
Jules 1436d9d392 Major updates to parser and lexer.  4 months ago  

lib  4 months ago  
.gitignore  4 months ago  
CONTRIBUTING.md  4 months ago  
LICENSE  5 months ago  
Makefile  4 months ago  
README.md  4 months ago  
changelog.md  4 months ago  
lex.c  4 months ago  
licp.c  4 months ago  
parse.c  4 months ago 
# you'll never guess what that does
(print "Hello, world!")
# automatic promotion of ints to floats
(+ 5 2 3.141592)
# arbitraryprecision ints. tyvm, GMP!
(set bignum 10e50)
# it can do all the stuff normal languages can, like define functions
# (type safety + annotations coming soon)
(def some_func (a b c)
(if (a `has_trait` reversible)
(reverse a))
(sum b)
(sum (map (* c) a) b)) # partial application?! you betcha!
# Haskellstyle infix notation for twoargument functions, too!
(5 `mod` 2)
# traitor!
(instance strfy (MyType as m)
(return (cat
(strfy m.val1)
(sp)
(strfy m.val2)
(sp)
(strfy m.val3))))
sum
(AKA +
). Takes n >= 2 numerical arguments and promotes them all to the
type preserving as much precision as possible.
prod
(AKA *
). Takes n >= 2 numerical arguemnts and promotes them all to the
type preserving as much precision as possible.
dif
(AKA 
). Takes 2 numerical arguments (a and b) and computes the
difference, ab
.
div
(AKA /
). Takes 2 numerical arguments (a and b) and performs
floatingpoint division. e.g., (/ 5 2)
yields 2.5
.
idiv
(AKA //
). Takes 2 numerical arguments (a and b) and performs
integer division. e.g., (// 5 2)
yields 2
.
mod
(AKA %
). Modulo/remainder division. Takes 2 arguments (a and b)
and computes their modulo. e.g., (% 5 2)
yields 1
.
~
(AKA NOT
). Unary operator, returns the binary NOT
of its argument.
^
(AKA XOR
). Binary operator, returns the binary XOR
of its of arguments.

(AKA OR
). Binary operator, returns the binary OR
of its arguments.
&
(AKA AND
). Binary operator, returns the binary AND
of its arguments.
>>
is a right arithmetic (unsigned) shift. Returns its first argument
shifted by its secont argument.
>>>
is a right logical (signed) shift. Returns its first argument shifted by
its second argument.
<<
is a left arithmetic (unsigned) shift. Returns its first argument
shifted by its secont argument.
<<<
is a left logical (signed) shift. Returns its first argument shifted by
its second argument.
print
takes n arguments of arbitrary type and concatenates their string
representations. If a string representation isn't available (via an instance
of strfy
defined over that type), an autogenned string of form <object of
type MYTYPE located at ADDRESS>
will be substituted. Writes to STDOUT
.
read
takes a strfy
able value as its first argument, which is displayed as
a prompt. It then returns the value which is inputted into STDIN
during its
execution.
eprint
just like print
, but instead writes to STDERR
.
fopen
opens a file (first argument) in a given mode (second argument). File
modes are a subset of those available in Python (for now):
r
, for readingw
, for writing (truncates the file if it exists)a
, for appendingx
, for exclusive creation (fails if the file already exists)+
, for updating (to be combined with any of the above). File is open for
reading and writing.
Can also include a third parameter to specify input file encoding from any of
the following (for now):ascii
, ASCII
utf8
, UTF8
, utf8
, UTF8
utf16
, UTF16
, utf16
, UTF16
This function returns a reference to an open file which is automatically
closed when a program is terminated cleanly.fread
loads the contents of the file into a string and returns the string.
fwrite
takes a reference to a file (as created by fopen
) and a string, and
writes the string to the file, overwriting or appending it depending on the
file opening mode.
int
: an arbitraryprecision integer, supplied via the GPM library.float
: a doubleprecision IEEE 754 floatingpoint number.string
: an arbitrarylength array of characters. Implemented as a (char)
array.tuple(t0, t1)
: a staticallytyped, optionally heterogeneous, fixedlength
collection of data. Similar to a tuple
in other languages or a struct
in
C.(int, int) > string
for a function taking two ints and
returning a string.