-
Notifications
You must be signed in to change notification settings - Fork 0
Home
To get started run python init.py in the src folder. The Ispy spec so far is simple in design. To those unfamiliar with the fundamentals of lisp, lisp is essentially a paradigm free language with a basis in functional programming. It is made up of s expressions i.e (command args) which is comparable to a statement in an imperative language (java, c, python etc..). Arguments are separated by spaces. S expressions can be nested inside each other for example (out (+ 4 5)). An addition in ispy is the ability to use square brackets [] for easier typing, any parentheses can be replaced by a bracket for example (+ 4 5) == [+ 4 5]
In the REPL expressions are outputted by default but when interpreting a file an explicit output expression is needed i.e (out arg).
Note: strings must be double quoted
(out "Hello Aliens!")
We can also use an arbitrary number of arguments
(out "hello" " evil " "but yet awesome aliens!")
=> hello evil but yet awesome aliens!
(out "glassworks" " red")
=> glassworks red
[out "Beautifully falling" " apart"]
line comments are denotated by ' however it must be the first character on the line, unlike other languages line comments must take up the entire line ' this is a comment
Note: => is not part of the language, it indicates what an expression evaluates to.
The math expressions [/, *, +, -] can have an arbitrary number of arguments, for example (+ 5 3 2 4 8 6 4 2 2 6 7) is perfectly legal and will simply sum all the arguments.
addition and summation
(+ 4 5)
=> 9
subtraction
(- 9 2)
=> 7
(- 9 1 2 3)
=> 9 - 1 - 2 - 3 = 3
division
(/ 10 2)
=> 5
multiplication
(* 3 2)
=> 6
absolute value
(abs -5)
=> 5
square root
(sqrt 25)
=> 5
square
(sq 9)
=> 81
In addition we can evaluate lists
fst returns first element in a list
(fst (4 3 5 6))
=> 4
since Ispy is written in python it is trivial to implement
a python eval expression pyeval, python statements must be in double quotes and thus strings.
This also allows some extension into python functionality (expressions that return values work,
imports and complex statements don't)
(pyeval "5+4")
= 9
so far there is only one conditional, if.
(if cond exp else-exp) if cond is true evaluate exp else evaluate else-exp
(if (> 4 2) (out "4 > 2") (out "4 < 2"))
=> 4 > 2
In addition to > there is also = and <
(= 5 5)
=> true
(< 42 90)
=> true
boolean values are represented by true, false
(if true [out "is true"] [out "is false"])
=> is true
There is also one constant, pi, however it must be used as an expression by itself (pi)
example: the diameter of a circle with d=9.2 is (* (pi) 9.2)
= 28.902652413
use the (in)
expression
i.e: (out (in))
simply prints out the value of the input.
(atoi arg)
converts arg from string to integer.
(atoi "5")
=> 5
Note: because python has no type system there is no distinguishing
between a float and an integer thus I could do this (+ (atoi "5") 4.3)
= 9.3
In v0.2 there is now support for global variables through set.
(set var val)
i.e (set new-variable (abs (- 2 8)))
to get the value of a variable use get.
(get new-variable)
=> 6
Edit: Im having lot's of bugs with functions so I would advise not to use them. Functions are set up using the set syntax, but use a func expression
(set func-name (func (args) expr))
example:
(set add-to-5 (func (x) (+ x 5))))
There is no need for a return statement because the expression
automatically returns.
to call it use
(add-to-5 3)
=> 8