Boolean in newLISP

In newLISP, true represents Boolean true:

> (if true (println "yes") (println "no"))
yes
"yes"

while nil represents Boolean false:

> (if nil (println "yes") (println "no"))
no
"no"

Like lua, 0 is evaluated true:

> (if 0 (println "yes") (println "no"))
yes
"yes"

empty list is also treated as false:

> (if '() (println "yes") (println "no"))
no
"no"

Check the following result:

> (if false (println "yes") (println "no"))
no
"no"

The reason is false is not defined here and its value is nil:

> false
nil

You can assign true to false and do some crazy thing:

> (let (false true) (if false (println "yes") (println "no")))
yes
"yes"

 

First taste of newLISP

Occasionally, I bumped into newLISP through the following twitter:

Capture

What attracted me is the newLISP‘s small size and fruitful APIs. Because I am fascinated with functional programming now, I decide to stop to peek at newLISP.

I never get my feet wet on Lisp/Scheme before, so I can’t compare the difference between them and newLISP. As an absolute novice, the key point to master newLISP I think is to be accustomed to parentheses. By default, the first element in parentheses should be a function, like this:

> (println "Hello" " World!")
Hello World!

Or this:

> (+ 4 8)
12

So if you just want a literal, remember to use ':

> '(println "Hello" " World!")
(println "Hello" " World!")

Once you remember this rule, you can understand the newLISP‘s program structure easily. Then the next thing is make your hands dirty, leverage the APIS, lego bricks provided by newLISP to practice writing small programs. For example, it cost me only a quarter to write abase64 encoder/decoder.

Happy hacking newLISP!