From: Leif Dyvik
Subject: Problem with Practical Common Lisp + sbcl
Date: 
Message-ID: <1137535845.573998.45480@g47g2000cwa.googlegroups.com>
Hello!

I have been reding the book 'Practical Common Lisp':
http://www.gigamonkeys.com/book/

And now I have a problem I dont understand. In this chapter on Macros:

   http://www.gigamonkeys.com/book/macros-defining-your-own.html

One eventually have this code

==== Begin

(defun primep (number)
  (when (> number 1)
    (loop for fac from 2 to (isqrt number) never (zerop (mod number
fac)))))


(defun next-prime (number)
  (loop for n from number when (primep n) return n))


(defmacro with-gensyms ((&rest names) &body body)
  `(let ,(loop for n in names collect `(,n (gensym)))
     ,@body))


(defmacro do-primes ((var start end) &body body)
  (with-gensyms (ending-value-name)
		`(do ((,var (next-prime ,start) (next-prime (1+ ,var)))
		      (,ending-value-name ,end))
		     ((> ,var ,ending-value-name))
		   ,@body)))
==== end

When I am in Emacs/SLIME and press C-c-k, It gives me this:

; file: /home/leif/Projekt/Lisp/hello.lisp
; in: DEFUN PRIMEP
;     (MOD NUMBER FAC)
; --> BLOCK LET IF AND IF AND IF PLUSP >
; ==>
;   NUMBER
;
; note: deleting unreachable code
;
; compilation unit finished
;   printed 1 note

; /home/leif/Projekt/Lisp/hello.fasl written
; compilation finished in 0:00:00
STYLE-WARNING: redefining PRIMEP in DEFUN
STYLE-WARNING: redefining NEXT-PRIME in DEFUN

==============

Does this not work in SBCL? Because It worked in CLISP. I tried it in
SBCL 0.9.4 and 0.9.8.

Is C-c-k not the right way to load the file? I usually use C-c-c for
just functions etc.

Any help would be nice :) !

From: Zach Beane
Subject: Re: Problem with Practical Common Lisp + sbcl
Date: 
Message-ID: <m3u0c2bilk.fsf@unnamed.xach.com>
"Leif Dyvik" <··········@gmail.com> writes:


> (defun primep (number)
>   (when (> number 1)
>     (loop for fac from 2 to (isqrt number) never (zerop (mod number
> fac)))))
[snip]
> ; file: /home/leif/Projekt/Lisp/hello.lisp
> ; in: DEFUN PRIMEP
> ;     (MOD NUMBER FAC)
> ; --> BLOCK LET IF AND IF AND IF PLUSP >
> ; ==>
> ;   NUMBER
> ;
> ; note: deleting unreachable code
[snip]
> Does this not work in SBCL? Because It worked in CLISP. I tried it in
> SBCL 0.9.4 and 0.9.8.

As I understand it, this is due to an implementation detail that is
getting confused by the symbol you are using in this case
("number"). The note can safely be ignored.

Zach
From: Leif Dyvik
Subject: Re: Problem with Practical Common Lisp + sbcl
Date: 
Message-ID: <1137537316.699576.283210@g44g2000cwa.googlegroups.com>
I changed 'number' to 'n', and that seem to work. Odd! Thanks anyway
for the pointer!
From: RMC
Subject: Re: Problem with Practical Common Lisp + sbcl
Date: 
Message-ID: <1137551606.680118.103440@g14g2000cwa.googlegroups.com>
(ODDp (CHANGE ("number" "n"))) returns NIL in this case, I'm afraid.
For common programming practice: don't *ever* be surprised when an
error occurs around an identifier named exactly like any keyword used
by the language, libraries, etc. If there is anything that differs
between language dialects, it's the way 'implicit interpreting' is
done. Better still, don't use any of the names dialects use [sic]!

By the way, can someone explain to me what the difference is between
the two types of quote marks (' and `)? I know the first one (the
apostrophe), but I keep seeing the second one (which I consider to bo
obsolete) without any explanation.
From: Eli Gottlieb
Subject: Re: Problem with Practical Common Lisp + sbcl
Date: 
Message-ID: <nXhzf.104181$ME5.24493@twister.nyroc.rr.com>
RMC wrote:
> (ODDp (CHANGE ("number" "n"))) returns NIL in this case, I'm afraid.
> For common programming practice: don't *ever* be surprised when an
> error occurs around an identifier named exactly like any keyword used
> by the language, libraries, etc. If there is anything that differs
> between language dialects, it's the way 'implicit interpreting' is
> done. Better still, don't use any of the names dialects use [sic]!
> 
> By the way, can someone explain to me what the difference is between
> the two types of quote marks (' and `)? I know the first one (the
> apostrophe), but I keep seeing the second one (which I consider to bo
> obsolete) without any explanation.
> 
The backquote ` is used to make an entire expression quoted /except for 
those portions marked by a comma ","!/  The sub-expressions marked with 
commas are evaluated, and their values are inserted into the larger 
quoted expression as though they'd been there in the first place.

`(,(cadr some-list) some-list 3) for a value of some-list '(1 * 3 4) 
will return:
'(* some-list 3) because the expression "(cadr some-list)" has a comma 
and is therefore evaluated.
From: Edi Weitz
Subject: Re: Problem with Practical Common Lisp + sbcl
Date: 
Message-ID: <uek36fe66.fsf@agharta.de>
On 17 Jan 2006 18:33:26 -0800, "RMC" <······@gmail.com> wrote:

> (ODDp (CHANGE ("number" "n"))) returns NIL in this case, I'm afraid.
> For common programming practice: don't *ever* be surprised when an
> error occurs around an identifier named exactly like any keyword
> used by the language, libraries, etc. If there is anything that
> differs between language dialects, it's the way 'implicit
> interpreting' is done. Better still, don't use any of the names
> dialects use [sic]!

Nonsense.  Common Lisp doesn't have "keywords" in that sense.  (It has
keywords, but they aren't what you think they are.)  It is perfectly
OK and legal to name a variable NUMBER.

> By the way, can someone explain to me what the difference is between
> the two types of quote marks (' and `)? I know the first one (the
> apostrophe), but I keep seeing the second one (which I consider to
> bo obsolete) without any explanation.

You might consider it obsolete but it's nevertheless part of the ANSI
standard and in heavy use:

  <http://www.lispworks.com/documentation/HyperSpec/Body/02_df.htm>

Cheers,
Edi.

-- 

Lisp is not dead, it just smells funny.

Real email: (replace (subseq ·········@agharta.de" 5) "edi")
From: RMC
Subject: Re: Problem with Practical Common Lisp + sbcl
Date: 
Message-ID: <1137552754.581347.184490@z14g2000cwz.googlegroups.com>
Thanks! I must say, I'm rather new to the terminology that is any
different from VB; learning, though. And of course, I meant 'key words'
when I typed 'keywords', as a general term for any
symbol/name/identifier/etc. in a language.
From: Edi Weitz
Subject: Re: Problem with Practical Common Lisp + sbcl
Date: 
Message-ID: <uacdufd8d.fsf@agharta.de>
On 17 Jan 2006 18:52:34 -0800, "RMC" <······@gmail.com> wrote:

> Thanks! I must say, I'm rather new to the terminology that is any
> different from VB; learning, though. And of course, I meant 'key
> words' when I typed 'keywords', as a general term for any
> symbol/name/identifier/etc. in a language.

Yes, I think I understood what you meant.  Note, however, that Common
Lisp doesn't have "reserved words" like C for example.  There are only
a couple of constraints on the COMMON-LISP package.  See this page

  <http://www.lispworks.com/documentation/HyperSpec/Body/11_aba.htm>

and the ones following it.

Cheers,
Edi.

-- 

Lisp is not dead, it just smells funny.

Real email: (replace (subseq ·········@agharta.de" 5) "edi")
From: Ivan Boldyrev
Subject: Re: Problem with Practical Common Lisp + sbcl
Date: 
Message-ID: <snc4a3-49h.ln1@ibhome.cgitftp.uiggm.nsc.ru>
On 9358 day of my life Edi Weitz wrote:
> Note, however, that Common Lisp doesn't have "reserved words" like C
> for example.

CL has no reserved words but implementation glitches :)

-- 
Ivan Boldyrev

                        Today is the first day of the rest of your life.