Declare lambda inside a loop?
Posted: Sun May 08, 2011 5:00 am
Hello, I'm curious about whether it is possible, and if so, then how would I declare a lambda within a loop. Here's an example I tried. It compiled, but gives a runtime error, saying it didn't bind lambda to the variable.
Sorry, that's not what you'd call a clean code... but, hope, it explains what I'm looking for
Code: Select all
(defun handle-incoming (stream)
(loop for char = (code-char (read-byte stream nil 0))
with handled = nil
with message = nil
with write-response = #'(lambda ()
(when word (setf message (append message (list word)))) nil)
for word = (if (or (char= char +null+) (char= char +pipe+))
(write-response) ; This will look for a function with the name "write-response" elsewhere
; while I wanted it to call the lambda declared before in this loop
(progn (setf handled nil)
(concatenate 'string word (string char))))
when (and (char= char +null+) (not handled))
do (progn (write-response)
(funcall 'call-handler message stream)
(setf handled t))))