Re:PicoLisp
by crasch4 on Wednesday May 02, 2018 @04:32PM
(#16980889)
Neat! How would you differentiate picolisp from say, Clojure (which also interoperates well with Java libraries). When would you use picolisp vs Clojure?
[ Parent
| on HN ]
One thing about PicoLisp that might stick out for people coming from CL,
Scheme, or Clojure is that it's dynamically scoped (like most Lisps,
historically), so you can't make closures. Compare this Scheme session:
#;1> (define (make-counter)
(let ((i 0))
(lambda () (set! i (+ i 1)) i))))
#;2> (define counter (make-counter))
#;3> (counter)
1
#;4> (counter)
2
#;5> (counter)
3
To this PicoLisp one: ? (de make-counter ()
(let (i 0)
'(() (setq i (+ i 1)) i)))
-> make-counter
? (setq counter (make-counter))
-> (NIL (setq i (+ i 1)) i)
? (counter)
-> NIL
? (setq i 10)
-> 10
? (counter)
-> 11
Using `curry` and patterns, you can do substitutions into a "lambda", which
can look like a closure, or not: ? (de make-adder (@base)
(curry (@base) (n) (+ @base n)))
-> make-adder
? (setq add-three (make-adder 3))
-> ((n) (+ 3 n))
? (add-three 5)
-> 8
? (de make-counter ()
(let (@i 0)
(curry (@i) () (setq @i (+ @i 1)) @i)))
-> make-counter
? (setq counter (make-counter))
-> (NIL (setq 0 (+ 0 1)) 0)
? (counter)
!? (setq 0 (+ 0 1))
0 -- Variable expected ; oops, we're trying to redefine 0There are 3 flavors of picolisp: the 32-bit version written in gcc-specific C, the "Ersatz" version written in Java, and the 64-bit version written in its own high-level assembly-language that can target x86-64, PPC, ARM64 and "emulation" in C.
The Ersatz version has good Java integration. The 64-bit version has some more recent Java integration:
Lots of discussion last time:
https://news.ycombinator.com/item?id=12363608
I think Clojure has much tighter Java interop, which you might like or loathe.
Clojure compiles to JVM bytecode, so it should run much much faster than an interpreted picolisp. Clojure works on Windows too, while Picolisp needs Cygwin I think. Picolisp is really simple from a language point of view. It has a small group of core users who think very differently about software. There aren't many picolisp libraries, but you can hook into C & Java libraries when needed. It has an integrated prolog like DB. Clojure runs Walmart during black Friday online sales...I would not recommend that with picolisp.
"Erzats" PicoLisp runs anywhere Java runs, that was it's original reason for existance - to be used in bootstrapping the compilation of PicoLisp, IIRC.
However, nowadays, I think Erzats PicoLisp, AKA the Java version of PicoLisp, gots too little love. It's an interesting way of accessing the JVM, just like Groovy or Clojure. Also, I don't have benchmarks, but PicoLisp is pretty damn fast owing to minimal datastructures and I would expect that to spill over into the Java implementation.
Alexander has a "Need for Speed" article where he shows it's in the neighborhood of Clisp, but Clisp isn't really all that fast. Comparing to SBCL would be more useful as it is very fast.