finally I got around to investing some time to really learn Lisp. I
picked Scheme mostly because of "Structure and Interpretation of
Computer Programs". Since I always wondered how macros in Lisp work, I
As an exercise I implemented my version of "cond" and would like to hear
criticism from more experienced people with regard to what I could have
made better, what might be inefficient or un-idiomatic.
(define (rk:cond->if conditions)
(if (null? conditions)
(error "empty list of conditions")
(let ((first (car conditions))
(remaining (cdr conditions)))
(let ((cond (car first)) ;; this condition
(cmds (cdr first)) ;; commands for this condition
(last (null? remaining))) ;; flag for last entry
(if (eq? cond 'else)
(if last
(cons begin cmds)
(error "else not at end!"))
(cons if (cons cond (cons (cons begin cmds)
(if last
'()
(list (rk:cond->if remaining)))))))))))
(define-macro (rk:cond . conditions)
(rk:cond->if conditions))
So far it seems to work exactly like "cond" (apart from different error
messages :-)).
Thanks a lot!
Kind regards
robert
PS: I case anybody wonders, I use guile as Scheme implementation.