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) ,@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))) ,@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 `(,,@gs) `(,,@os)) ,(progn ,@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.
So I check sbcl repl directly on my bash; in that case, the file could be loaded and compiled without any problem. Therefore, SLIME must have the problem.
Actually, if I made the function on REPL on SLIME, NO PROBLEM. The problem is occured when I made a file, load, and compile THE FILE.
I checked the file, then I found both g!-symbol-p and o!-symbol-to-g!-symbol are not recognized by SLIME, either. Then, I concluded functions with "!" are not recognized by SLIME.
Is there any solution about that? I use Ubuntu 9.10, SBCL and Emacs 23 provided by Ubuntu. Also I use cvs version of SLIME(newest).
Here are my lines about SLIME on my .emacs
;;=======================================================================
;; SLIME ;;======================================================================= (setq inferior-lisp-program "/usr/bin/sbcl") (add-to-load-path-recompile (expand-file-name "~/slime")) (add-hook 'lisp-mode-hook (lambda () (inferior-slime-mode t) (global-set-key "\C-cH" 'hyperspec-lookup) (push 'ac-source-slime ac-sources) (auto-complete-mode)))
(require 'slime)
(eval-after-load "slime" '(progn (message "Slime configuration...") (slime-setup '(slime-scratch slime-editing-commands slime-fancy slime-repl slime-asdf anything-slime))) ) ;;
(setq slime-net-coding-system 'utf-8-unix
;; inferior-lisp-program "/usr/bin/sbcl" lisp-indent-function 'common-lisp-indent-function slime-complete-symbol*-fancy t slime-complete-symbol-function 'slime-fuzzy-complete-symbol slime-startup-animation t)
(slime-autodoc-mode) ;;
Thanks
cametan
P.S. I also found SLIME's REPL don't recognized reader macros. Though making reader macro with #foo, SLIME says something like "incomplete input". P.S.2. The author of LOL says he hates Emacs. Then, if he spelled and cursed SLIME, I would give all up.
亀田馬志 masashi.kameda@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) ,@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))) ,@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 `(,,@gs) `(,,@os)) ,(progn ,@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.
亀田馬志 masashi.kameda@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) ,@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))) ,@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)))
Wrap these (and the above) function definitions in an
(EVAL-WHEN (:COMPILE-TOPLEVEL :LOAD-TOPLEVEL :EXECUTE) ...)
;; 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 `(,,@gs) `(,,@os)) ,(progn ,@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.
But its definition is not yet there at compilation time where it is used in DEFMACRO!. The EVAL-WHEN make it also available at compilation time.
So I check sbcl repl directly on my bash; in that case, the file could be loaded and compiled without any problem. Therefore, SLIME must have the problem.
No, it's either a problem of your or that book's author's understanding of the execution model of Common Lisp.
P.S. I also found SLIME's REPL don't recognized reader macros. Though making reader macro with #foo, SLIME says something like "incomplete input".
I think this came up before. What's the exact way to trigger it anyway?
CL-USER> (set-dispatch-macro-character ## #\f (constantly t)) T CL-USER> #f T
seems to work just fine.
-T.c
* 亀田馬志 [2010-04-29 16:23+0200] writes:
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.
Yes, but it's needed "during macroexpansion". If you only compile a function you can't call it yet.
You could try to just load it with C-c C-l. Then every toplevel form is evaluated immediately and available in the following forms. But there are also other missing function like SYMB and FLATTEN.
So I check sbcl repl directly on my bash; in that case, the file could be loaded and compiled without any problem. Therefore, SLIME must have the problem.
If you load it before compiling it you make all definitions available for macroexpansion. If you execute (load (compile-file "lol.chatper_2.lisp")) in a clean session you'll will most likely see the same problem.
Actually, if I made the function on REPL on SLIME, NO PROBLEM. The problem is occured when I made a file, load, and compile THE FILE.
I checked the file, then I found both g!-symbol-p and o!-symbol-to-g!-symbol are not recognized by SLIME, either. Then, I concluded functions with "!" are not recognized by SLIME.
Is there any solution about that? I use Ubuntu 9.10, SBCL and Emacs 23 provided by Ubuntu. Also I use cvs version of SLIME(newest).
When you get more experienced you'll recognize that you need EVAL-WHEN in situations like these. You will also learn the value of adding an IN-PACKAGE form at the beginning of a file.
P.S. I also found SLIME's REPL don't recognized reader macros. Though making reader macro with #foo, SLIME says something like "incomplete input".
Well, yes, SLIME assumes that you want to enter Lisp syntax not some random character noise. C-u RET will accept the current input anyway even if it doesn't look like a complete form.
Helmut
Thank all you guys for the advices.
I see. Macroexpansion before compilation. Then, at that moment, macro-defined couldn't find function-defined... I never imagined that. I appreciate you all to telling me that.
I will check how to use eval-when. Thank you very much.
Also, C-u RET solves reader macro issue.
Thanks a lot.
cametan
2010/4/30 Helmut Eller heller@common-lisp.net
- 亀田馬志 [2010-04-29 16:23+0200] writes:
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.
Yes, but it's needed "during macroexpansion". If you only compile a function you can't call it yet.
You could try to just load it with C-c C-l. Then every toplevel form is evaluated immediately and available in the following forms. But there are also other missing function like SYMB and FLATTEN.
So I check sbcl repl directly on my bash; in that case, the file could be loaded and compiled without any problem. Therefore, SLIME must have the problem.
If you load it before compiling it you make all definitions available for macroexpansion. If you execute (load (compile-file "lol.chatper_2.lisp")) in a clean session you'll will most likely see the same problem.
Actually, if I made the function on REPL on SLIME, NO PROBLEM. The
problem is
occured when I made a file, load, and compile THE FILE.
I checked the file, then I found both g!-symbol-p and
o!-symbol-to-g!-symbol
are not recognized by SLIME, either. Then, I concluded functions with "!" are not recognized by SLIME.
Is there any solution about that? I use Ubuntu 9.10, SBCL and Emacs 23 provided by Ubuntu. Also I use cvs version of SLIME(newest).
When you get more experienced you'll recognize that you need EVAL-WHEN in situations like these. You will also learn the value of adding an IN-PACKAGE form at the beginning of a file.
P.S. I also found SLIME's REPL don't recognized reader macros. Though
making
reader macro with #foo, SLIME says something like "incomplete input".
Well, yes, SLIME assumes that you want to enter Lisp syntax not some random character noise. C-u RET will accept the current input anyway even if it doesn't look like a complete form.
Helmut
slime-devel site list slime-devel@common-lisp.net http://common-lisp.net/mailman/listinfo/slime-devel
2010/4/29 亀田馬志 masashi.kameda@gmail.com:
Thank all you guys for the advices.
I see. Macroexpansion before compilation. Then, at that moment, macro-defined couldn't find function-defined... I never imagined that. I appreciate you all to telling me that.
I will check how to use eval-when. Thank you very much.
Also, C-u RET solves reader macro issue.
Thanks a lot.
cametan
Masashi,
you can read more about eval-when here: http://www.gigamonkeys.com/book/the-special-operators.html
Mirko