"santi" <scarbonell@...> writes:
> Hello,
>
> You are right that I do not know much lisp. It is more complicated
> than other languages like Java or C #. For example to use a structure
> if / then / else structures should use macro PROG1 and PROG2 that are
> more complicated.
Not at all! You can write a different macro:
(defmacro if* (test &rest body)
(let* ((else (member :else body))
(then (ldiff body else)))
(when (and (eq :then (first then))
(rest then))
(pop then))
(pop else)
`(if ,test
(progn
,@then)
(progn
,@else))))
(macroexpand '(if* (= 1 a)
:then (print 1)
42
:else (print a)
33))
--> (if (= 1 a)
(progn (print 1) 42)
(progn (print a) 33))
(let ((a 22))
(if* (= 1 a)
:then (print 1)
42
:else (print a)
33))
prints: 22
--> 33
> About the procedure / function babylon-read that comment, I understand
> that this function gets a char from the user and compares it with
> special-keys. Whatever you do this procedure, I understand that in the
> end it does is a simple assignment with a let. Really assign the
> character y or n to indicate whether a statement is true or false.
>
> I do not understand is that I rewrite this function to simply pass a
> character and does not work. That's the reason why I ask if the char
> does something more.
>
> This is the original procedure
>
> (def$ method (tty-dialog-mixin: babylon-read) (& optional special-keys)
> "reads in a character or a lisp form from dialog-stream.
> Those characters occurring only in the special list-keys are read. "
>
> (let ((char (read-char dialog-stream)))
> (cond ((member special char-keys: test 'char-equal)
> (clear-input dialog-stream)
> char)
> (t (prog2 (unread-char char dialog-stream)
> (read dialog-stream)
> (clear-input dialog-stream))))))
>
>
> And this is overwritten
>
> (def$ method (tty-dialog-mixin: babylon-read) (& optional special-keys)
> "Redefining the method to see if I can get the y/n"
> (let ((char #\y))))
http://www.lispworks.com/documentation/HyperSpec/Body/s_let_l.htm#let
http://www.lispworks.com/documentation/HyperSpec/Body/s_progn.htm#progn
The syntax is (LET (bindings…) body…)
LET wraps the body… in an implicit PROGN.
So (let ((char #\y))) is equivalent to (let ((char #\y)) (progn))
PROGN returns the values returned by its last body form.
The result when the PROGN body is empty is not specified formally, but
the Example section says: (progn) => NIL
so we can assume that was the intention of the authors of the standard.
Therefore (let ((char #\y)) (progn)) returns NIL
and therefore (let ((char #\y))) returns NIL.
http://cliki.net/
Those tutorials are around a hundred page each, so you should have no
problem reading them:
http://clisp.hg.sourceforge.net/hgweb/clisp/clisp/raw-file/tip/doc/LISP-tutorial.txt
http://www.franz.com/resources/educational_resources/cooper.book.pdf
--
__Pascal Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.
|