[slime-devel] SLIME's readline problem?

Stas Boukarev stassats at gmail.com
Thu Apr 29 15:15:34 UTC 2010


亀田馬志 <masashi.kameda at gmail.com> writes:

> Hi.
>
> I saw something strange about SLIME and tried googling about it. But couldn't
> find any clues.
> Please allow me to post here.
>
> I read "Let Over Lambda", a book about macros, and noticed function, named with
> "!", on a file couldn't be recognized nor compiled through using SLIME.
>
> The codes are listed below, using some utilities from the book "On Lisp",
> written by Paul Graham.
>
>
>     ;; *-SIMBOL-P-GENERATOR
>     ;; (defmacro *-symbol-p-generator (str)
>     ;;   (let ((len (1+ (length str)))
>     ;;     (init-part (string-upcase str)))
>     ;;     `(defun ,(intern (concatenate 'string init-part "-SYMBOL-P")) (s)
>     ;;        (and (symbolp s)
>     ;;         (> (length (symbol-name s)) ,len)
>     ;;         (string= (symbol-name s)
>     ;;              ,init-part
>     ;;              :start1 0
>     ;;              :end1 ,len)))))
>
>     ;; G-BANG-SYMBOL-PREDICATE
>     ;; (*-symbol-p-generator "g!")
>
>     (defun g!-symbol-p (s)
>       (and (symbolp s)
>            (> (length (symbol-name s)) 2)
>            (string= (symbol-name s)
>             "G!"
>             :start1 0
>             :end1 2)))
>
>     ;; DEFMACRO-WITH-G-BANG!
>     (defmacro defmacro/g! (name args &body body)
>       (let ((syms (remove-duplicates
>                (remove-if-not #'g!-symbol-p
>                       (flatten body)))))
>         `(defmacro ,name ,args
>            (let ,(mapcar
>               (lambda (s)
>             `(,s (gensym ,(subseq
>                        (symbol-name s)
>                        2))))
>               syms)
>          , at body))))
>
>     ;; ONCE-ONLY
>     (defmacro once-only ((&rest names) &body body)
>       (let ((gensyms (loop for n in names collect (gensym))))
>         `(let (,@(loop for g in gensyms collect `(,g (gensym))))
>            `(let (,,@(loop for g in gensyms for n in names collect ``(,,g
>     ,,n)))
>           ,(let (,@(loop for n in names for g in gensyms collect `(,n ,g)))
>             , at body)))))
>
>     ;; O-BANG-SYMBOLS
>     ;; (*-symbol-p-generator "o!")
>
>     (defun o!-symbol-p (s)
>       (and (symbolp s)
>            (> (length (symbol-name s)) 2)
>            (string= (symbol-name s)
>             "O!"
>             :start1 0
>             :end1 2)))
>
>     (defun o!-symbol-to-g!-symbol (s)
>       (symb "G!"
>         (subseq (symbol-name s) 2)))
>
>     ;; DEFMACRO-BANG
>     (defmacro defmacro! (name args &body body)
>       (let ((os (remove-if-not #'o!-symbol-p args)))
>         (let ((gs (mapcar #'o!-symbol-to-g!-symbol os)))
>           `(defmacro/g! ,name ,args
>          `(let ,(mapcar #'list `(,, at gs) `(,, at os))
>             ,(progn , at body))))))
>
>     ;; NIF
>     (defmacro! nif (o!expr pos zero neg)
>       `(cond ((plusp ,g!expr) ,pos)
>          ((zerop ,g!expr) ,zero)
>          (t ,neg)))
>
>      
>
>     ;;; This  is the end of file
>
>  
> C-c C-k shows such a message below.
>
>
>     ; in: DEFMACRO! NIF
>     ;     (DEFMACRO! NIF (O!EXPR POS ZERO NEG)
>     ;                `(COND ((PLUSP ,G!EXPR) ,POS) ((ZEROP ,G!EXPR) ,ZERO) (T
>     ,NEG)))
>     ;
>     ; caught ERROR:
>     ;   (during macroexpansion of (DEFMACRO! NIF ...))
>     ;   The function O!-SYMBOL-P is undefined.
>     ;
>     ; compilation unit finished
>     ;   caught 1 ERROR condition
>
>     ; /home/cametan/lol.chapter_2.fasl written
>     ; compilation finished in 0:00:00.091
>
>
> Strange. The function O!-SYMBOL-P was THERE on the file.
This problem is unrelated to Slime.

That happens because macroexpansion is happening before that function is
defined. Macroexpansion happens before compiling, but the function will
be defined only when you load a fasl. Put
(eval-when (:compile-toplevel :load-toplevel :execute) ...)
around function definitions which you want to use at macroexpansion
time.

-- 
With Best Regards, Stas.


More information about the slime-devel mailing list