43 points · by nadim · 18y ago · 26 comments
edit: Is there anything better than Lisp macros that makes defining an if possible and that supports side-effects?
In Scheme (PLT):
(define lazy-with-side-effect
(delay (begin (print "Hey, a side effect!")
#t)))
> lazy-with-side-effect
#<promise>
> (force lazy-with-side-effect)
"Hey, a side effect!"#t
> (force lazy-with-side-effect)
#t
In the OCaml toplevel: # let lwse = lazy (print_string "(Side effect)\n"; true);;
val lwse : bool lazy_t = <lazy>
# lwse;;
- : bool lazy_t = <lazy>
# Lazy.force lwse;;
(Side effect)
- : bool = true
# Lazy.force lwse;;
- : bool = trueAs for your second question, it's funny that you ask it after mentioning haskell. The solution of course is that a collection of haskell features offer tools that are "better than Lisp macros" and support side effects. Lazy evaluation and monads cover most cases where you would use a macro in lisp. There are also more complex things like comonads and arrows. These solve the problems that lisp macros solve in a different way. And if you really need the ultimate power that lisp macros provide, then the haskell equivalent is template haskell.
The two biggest stumbling blocks people encounter when learning Haskell are monads and the (powerful but complex) type system.
My understanding at the time was that it was only intended for research, and as it was pure, there was no way (at the time ) to do real IO - your program was essentially f(user input as string) = output as a string, and not practical enough.
Since that time they worked out how to use Monads in haskell for a nicer IO experience.
Interesting.
doesn't that apply to any less static -> more static typed language comparison?
If you want to learn Common Lisp and especially to use it effectively I would recommend CL-oriented book, for example Practical Common Lisp by Peter Seibel.
But still I'm recommending SICP (at least watch the videos) to anyone who indends to be real programmer.