Learning Lisp Syntax

Discussion of Common Lisp
Post Reply
laserblue
Posts: 2
Joined: Sun Oct 03, 2010 2:11 pm

Learning Lisp Syntax

Post by laserblue » Wed Oct 06, 2010 2:39 pm

I'm running the SLIME + EMACS Lispbox with CLISP. The SLIME menu has a link to LISP Hyperspec but I can't find how to convert the value of a symbol to a string. I'm thinking about using coerce, defvar or defparameter or something else like a fill-pointer but the Hyperspec examples given don't help much. What is the best way to work out how to do what I want? I am trying to refactor and extend a very old program in which a word from a sentence (without enclosing quotes) is assigned to a global variable called *curr-w* (for 'current word being processed'). I want to detect a specific suffix such as "ly" and create a lemmatized stem of *curr-w* if the original word is not in my lexicon. I know about the porter and snowball algorithms and CL-PPCRE but for now I just want to figure something out on my own. I have source code for a porter stemmer to possibly emulate it and eventually incorporate it later but it uses double quoted words.E.g. (stem "slowly")
If I try

Code: Select all

(setf morph (string *curr-w*))
where *curr-w* is the word 'slowly' without the quotes, the value returned is "slowly" which seems like what I want since

Code: Select all

(string-left-trim "yl" "ylwols") 
returns "wols" which is what I want. However, when I reverse morph and use (string-left-trim "yl" morph), the value returned is "ylwols" (unchanged) or an error message appears that says *curr-w* or morph is not a sequence. I have reversed the word to use string= and string-left-trim because I don't know what the length of the words will be and I'm not sure how to use string= running from the right side. I've tried adding quote before morph and (string morph) etc. Eventually, I want something like (string-left-trim suffix morph) that returns the stem of the word so that it can be checked for in the lexicon or ignored as an unknown word.

ramarren
Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland
Contact:

Re: Learning Lisp Syntax

Post by ramarren » Wed Oct 06, 2010 10:51 pm

laserblue wrote:but it uses double quoted words.E.g. (stem "slowly")
You seem to not understand the concept of source literals. It doesn't use "double quoted words", double quotes are just a syntax for a string source literal. When they encountered by the reader algorithm, which converts the text representation into an in-memory representation, they produce a string. Therefore the concept of "is the word 'slowly' without the quotes" is meaningless, or at least unclear. You might mean symbols, but symbols are not words, and in general their names are human oriented and should rarely be manipulated by the program.
laserblue wrote:convert the value of a symbol to a string
What do you mean by that? A symbol is somewhat complex structure associated with many things, many of which cannot be very meaningfully converted to strings. SYMBOL-NAME can, but as I said it not usually something you should need.
laserblue wrote:use (string-left-trim "yl" morph), the value returned is "ylwols" (unchanged) or an error message appears that says *curr-w* or morph is not a sequence
STRING-LEFT-TRIM doesn't do what you seem to think it does. In general you don't really seem to know how Common Lisp works at a fairly basic level. Rather that trying to learn a language by randomly changing things I would suggest reading a book like Common Lisp: A Gentle Introduction to Symbolic Computation and/or Practical Common Lisp. There is also Paradigms of Artificial Intelligence Programming: Case Studies in Common Lisp, but it is not available for free.

laserblue
Posts: 2
Joined: Sun Oct 03, 2010 2:11 pm

Re: Learning Lisp Syntax

Post by laserblue » Thu Oct 07, 2010 9:42 am

Thanks! I don't need your help now. I think I found the answer in "Notes on Lisp" (http://www-users.cselabs.umn.edu/classe ... cheme.html) and looking through the Hyperspec again.

I've been reading Practical Common Lisp and it doesn't contain the answer to my question at
http://www.gigamonkeys.com/book/numbers ... rings.html

This looks like what I want.

Code: Select all

(string 'walks) =>  "WALKS"
http://www.lispworks.com/documentation/ ... string.htm

The STEM function of the porter stemmer is not useful to me yet because it takes a string as an argument (E.g. "SLOWLY" )and the words of the sentence I am parsing and the lexicon word definitions don't have double quotes around them.

Code: Select all

(parse '(john walks to the store))

Post Reply