From: Bonham PR
Subject: confused newbie (in asbestos Y-fronts...)
Date: 
Message-ID: <3BFAA16F.C481ADD5@city.ac.uk>
I'm trying to teach myself lisp by working through 'AI with common lisp'
by James L. Noyes using XEmacs v.21.1.  I'm trying to write a bit of
code to return the root string of a word with a given ending.  (e.g
(suffix-match 'ing 'match) should return "match" (if no match then
"nil"))

;;;(I've labelled the ending 'e' and the word 'w')

(defun suffix-match (e w)
    (if (string= (subseq (reverse w) 0 (length e)) (reverse e))
    (subseq w 0 (- (length w) (length e))) nil))

when i try to run it it returns an error - "listp, w".  Can anyone tell
me of the errors in my code and why w has to be a list when I'm using
string-processing "tools".

From: Barry Wilkes
Subject: Re: confused newbie (in asbestos Y-fronts...)
Date: 
Message-ID: <87n11h44za.fsf@orton.bew.org.uk>
Bonham PR <·····@city.ac.uk> writes:

> I'm trying to teach myself lisp by working through 'AI with common lisp'
> by James L. Noyes using XEmacs v.21.1.  I'm trying to write a bit of
> code to return the root string of a word with a given ending.  (e.g
> (suffix-match 'ing 'match) should return "match" (if no match then
> "nil"))

OK - first off, it isn't clear to me what the actual version of common lisp
you are using is - PLEASE be aware that the lisp in XEmacs is NOT common lisp
(although from the error you are getting, I don't think you are evaluating the
above expression in XEmacs). My advice (and others will doubtless differ) is
that for learning common lisp, you should get hold of one of the commercial
vendors 'Trial' versions for the platform you are interested in. I personally
use LispWorks professional from Xanalys, and can recommend
the trial version they ship, which I used before purchasing their professional
product. It's available from :

http://www.xanalys.com/software_tools/downloads/lw-personal-edition.html. 

While you are there, you should also grab a copy of the HyperSpec:  

http://www.xanalys.com/software_tools/reference/HyperSpec/HyperSpec-4-0.tar.gz

But, in answer to your question - the call you give :

(suffix-match 'ing 'match) 

is passing two (quoted) SYMBOLS to suffix match, rather than two STRINGS. You
need (eg) to call (suffix-match "ing" "match"). Please also be aware of
another possible (future) source of confusion - what you refer to as "nil" is
NOT a string. For this reason, it is rare to write it as such, but rather to
write nil or NIL.

> ;;;(I've labelled the ending 'e' and the word 'w')
> 
> (defun suffix-match (e w)
>     (if (string= (subseq (reverse w) 0 (length e)) (reverse e))
>     (subseq w 0 (- (length w) (length e))) nil))
> 
> when i try to run it it returns an error - "listp, w".  Can anyone tell
> me of the errors in my code and why w has to be a list when I'm using
> string-processing "tools".

Bearing in mind what I have said above, the error you get is due to 
(reverse w) being called with w a symbol. reverse actually takes as its
argument a sequence - of which lists are one kind and strings are
another. Take a look at the entry in the HyperSpec for more information.

I'm not familiar with the book you mention, but I can recommend 'ANSI Common
Lisp' by Paul Graham as a good introduction to the language, or alternatively,
Franz distribute a good introduction to common lisp by David Cooper. It's
available from :

http://www.franz.com/resources/educational_resources/cooper.book.pdf

Finally, there are many good sources of information on Lisp linked at 
the ALU website, www.lisp.org.

Regards,

Barry.
From: Martti Halminen
Subject: Re: confused newbie (in asbestos Y-fronts...)
Date: 
Message-ID: <3BFAC41A.7FFFC4E@kolumbus.fi>
Bonham PR wrote:
> 
> I'm trying to teach myself lisp by working through 'AI with common lisp'
> by James L. Noyes using XEmacs v.21.1.  I'm trying to write a bit of
> code to return the root string of a word with a given ending.  (e.g
> (suffix-match 'ing 'match) should return "match" (if no match then
> "nil"))
> 
> ;;;(I've labelled the ending 'e' and the word 'w')
> 
> (defun suffix-match (e w)
>     (if (string= (subseq (reverse w) 0 (length e)) (reverse e))
>     (subseq w 0 (- (length w) (length e))) nil))
> 
> when i try to run it it returns an error - "listp, w".  Can anyone tell
> me of the errors in my code and why w has to be a list when I'm using
> string-processing "tools".

- The other reply handled most of your questions. For this particular
piece, it seems to run OK in a Common Lisp when called with strings
instead of symbols.

- All this reverse/subseq stuff seems superfluous, this seems to work,
too:

(defun suffix-match2 (e w)
    (if (string=  w e :start1 (- (length w) (length e)))
	(subseq w 0 (- (length w) (length e)))
      nil))

--