From: Daniel Hogan
Subject: newbie: comparing
Date: 
Message-ID: <8v7ct7$g1m$1@nnrp1.deja.com>
Part of a class assignment I have is to write a program in Lisp.  For
the past four hours, I was going without any problems (other than my
reference guide being in a 1000 pieces), but now I have the following
senario:

(setq foo (read))

(if (equal foo '(a))
  (princ "It worked!!!\n")
  (princ "It did not work!!!\n")
)


What I want is to enter "a" (without quotes) and get "It worked!!!",
but it only happens if I enter "(a)" (without quotes).  How do I fix
this???

Thanks.

--
Daniel


Sent via Deja.com http://www.deja.com/
Before you buy.

From: Daniel Hogan
Subject: Re: newbie: comparing (NEVERMIND)
Date: 
Message-ID: <8v7dem$ged$1@nnrp1.deja.com>
Nevermind.  I do believe that I have learned the true meaning of the
word "idiot" this evening.  Thank you all, and good night.  =D



In article <············@nnrp1.deja.com>,
  Daniel Hogan <······@nls.k12.la.us> wrote:
> Part of a class assignment I have is to write a program in Lisp.  For
> the past four hours, I was going without any problems (other than my
> reference guide being in a 1000 pieces), but now I have the following
> senario:
>
> (setq foo (read))
>
> (if (equal foo '(a))
>   (princ "It worked!!!\n")
>   (princ "It did not work!!!\n")
> )
>
> What I want is to enter "a" (without quotes) and get "It worked!!!",
> but it only happens if I enter "(a)" (without quotes).  How do I fix
> this???
>
> Thanks.
>
> --
> Daniel
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>

--
Daniel Hogan
Computer Technician
Richland Parish Schools


Sent via Deja.com http://www.deja.com/
Before you buy.
From: David Bakhash
Subject: Re: newbie: comparing (NEVERMIND)
Date: 
Message-ID: <m33dgo4av0.fsf@cadet.dsl.speakeasy.net>
Daniel Hogan <······@my-deja.com> writes:

> Nevermind.  I do believe that I have learned the true meaning of the
> word "idiot" this evening.  Thank you all, and good night.  =D

While I didn't understand your post, I definitely _do_ understand that 
READ takes time to grok, and no one should be called an idiot (not
even by themselves). I mean, what does that say about others, if they
have such a question?  Would you call _them_ an idiot for asking?

The HyperSpec page describing the READ function is pretty brief, but
the chapter on the Reader is pretty thorough, and you start to see how
complex it really is, with all the dynamic dependencies on *package*,
*readtable*, the *read-xxx* variables like *read-base*, etc.

Also, there are a lot of auxiliary functions other than READ that you
should know if you're using read.  One might be PEEK-CHAR.  There are
others.  I'm currently in the process of writing a function called
READ*, which returns multiple values, the first value being the object
that READ would have returned, and the 2nd being a string which
contains the whitespace characters preceeding it.  I know how to do
this, but it took me a while to figure out how to do it right -- and
I've been hacking the reader for a while now.  Yet, I don't feel like
an idiot about it.

good luck,
dave
From: Rainer Joswig
Subject: Re: newbie: comparing
Date: 
Message-ID: <joswig-10FAA7.03452319112000@news.is-europe.net>
In article <············@nnrp1.deja.com>, Daniel Hogan 
<······@nls.k12.la.us> wrote:

> Part of a class assignment I have is to write a program in Lisp.  For
> the past four hours, I was going without any problems (other than my
> reference guide being in a 1000 pieces), but now I have the following
> senario:
> 
> (setq foo (read))
> 
> (if (equal foo '(a))
>   (princ "It worked!!!\n")
>   (princ "It did not work!!!\n")
> )
> 
> 
> What I want is to enter "a" (without quotes) and get "It worked!!!",
> but it only happens if I enter "(a)" (without quotes).  How do I fix
> this???
> 
> Thanks.
> 
> --
> Daniel

Is this Common Lisp? In Common Lisp "\n" usually does not
make sense.

But you may want to change '(a) to just 'a .

(let ((foo (read)))
  (print (if (equal foo 'a)
           "It worked!!!"
           "It did not work!!!")))

Anyway, typing this to the top-level is just enough to check it:

? (equal (read) 'a)
a
T

-- 
Rainer Joswig, Hamburg, Germany
Email: ·············@corporate-world.lisp.de
Web: http://corporate-world.lisp.de/
From: Daniel Hogan
Subject: Re: newbie: comparing
Date: 
Message-ID: <8vafvk$lur$1@nnrp1.deja.com>
Just to forfill the curiosity, I'm writing in XLisp.  Also, I have
successfully completed the "introductory to Lisp" assignment.

Thanks.

--
Daniel



In article <····························@news.is-europe.net>,
  Rainer Joswig <······@corporate-world.lisp.de> wrote:
> In article <············@nnrp1.deja.com>, Daniel Hogan
> <······@nls.k12.la.us> wrote:
>
> > Part of a class assignment I have is to write a program in Lisp.
For
> > the past four hours, I was going without any problems (other than my
> > reference guide being in a 1000 pieces), but now I have the
following
> > senario:
> >
> > (setq foo (read))
> >
> > (if (equal foo '(a))
> >   (princ "It worked!!!\n")
> >   (princ "It did not work!!!\n")
> > )
> >
> >
> > What I want is to enter "a" (without quotes) and get "It worked!!!",
> > but it only happens if I enter "(a)" (without quotes).  How do I fix
> > this???
> >
> > Thanks.
> >
> > --
> > Daniel
>
> Is this Common Lisp? In Common Lisp "\n" usually does not
> make sense.
>
> But you may want to change '(a) to just 'a .
>
> (let ((foo (read)))
>   (print (if (equal foo 'a)
>            "It worked!!!"
>            "It did not work!!!")))
>
> Anyway, typing this to the top-level is just enough to check it:
>
> ? (equal (read) 'a)
> a
> T
>
> --
> Rainer Joswig, Hamburg, Germany
> Email: ·············@corporate-world.lisp.de
> Web: http://corporate-world.lisp.de/
>

--
Daniel Hogan
Computer Technician
Richland Parish Schools


Sent via Deja.com http://www.deja.com/
Before you buy.
From: David Bakhash
Subject: Re: newbie: comparing
Date: 
Message-ID: <m3lmuh6yg6.fsf@cadet.dsl.speakeasy.net>
Daniel Hogan <······@nls.k12.la.us> writes:

> (setq foo (read))
> 
> (if (equal foo '(a))
>   (princ "It worked!!!\n")
>   (princ "It did not work!!!\n")
> )
> 
> What I want is to enter "a" (without quotes) and get "It worked!!!",
> but it only happens if I enter "(a)" (without quotes).  How do I fix
> this???

While I have no idea what you're talking about, I might try to give
some suggestions.

The function READ is invoked on a stream to read Lisp objects.
Judging from your post, the Lisp objects are either symbols, strings,
or lists of them:

;;;;;;;;;;;;;;;;;

(with-input-from-string (stream "a")
  (read stream))

==> A           ; the symbol

(with-input-from-string (stream "\"a\"")
  (read stream))

==> "a"         ; the string

(with-input-from-string (stream "(a \"b\" c)")
  (read stream))

==> (A "b" C)     ; the list

;;;;;;;;;;;;;;;;;

Now, if you quote something, you should just know that the Lisp reader 
will macroexpand that out, so:

'a

==> (quote a)

which, when evaluated, returns back the symbol A.

Hope that helps.

dave
From: Kent M Pitman
Subject: Re: newbie: comparing
Date: 
Message-ID: <sfwhf53ygh6.fsf@world.std.com>
David Bakhash <·····@alum.mit.edu> writes:

> Daniel Hogan <······@nls.k12.la.us> writes:
> 
> > (setq foo (read))
> > 
> > (if (equal foo '(a))
> >   (princ "It worked!!!\n")
> >   (princ "It did not work!!!\n")
> > )
> > 
> > What I want is to enter "a" (without quotes) and get "It worked!!!",
> > but it only happens if I enter "(a)" (without quotes).  How do I fix
> > this???
> 
> While I have no idea what you're talking about, I might try to give
> some suggestions. [...]

I'm betting his problem (which he says is already resolved) is simpler than
this.  Newbies from other languages where a+(b*c) is equivalent to a+b*c
but where they think it's more perspicuous like to put parens around things
to get the grouping right in their head even if it's not needed.   I bet
that because singlequote isn't a matchfix operator, he was worried about
where the quotation would stop and so put parens around the thing he wanted
to quote, not realizing that they were structurally significant and would
create a different object.  Just a guess.