Re: possibly silly question re quoting of function arguments...



"birlinn@xxxxxxxxx" <birlinn@xxxxxxxxx> writes:

Hi,

i'm writing my first lisp programme and am trying to work out how to do
this:

i have a bunch of variables that look like:

(defvar myvar-x1 nil
"1st x variable")

(defvar myvar-y1 nil
"1st y variable")

i want to be able to push and pop items onto & out of myvar-x1 etc.

i want a predicate function that tells me whether a given list is of x
or y (e.g. myvar-x1 or myvar-y1)

(defun dest-is-xvar-p (alist)
(if (eq alist myvar-x1)
't
'nil))

You can just write that:

(defun dest-is-xvar-p (alist)
(eq alist myvar-x1))

Though I subscribe to the school of thought that you should always use
EQL and never EQ. And a lisper is going to read alist as an
abbreviation for "association list" rather than "a list". But luckily
this isn't Scheme so we can use the 'list' as a variable name. So I'd
write it:

(defun dest-is-xvar-p (list)
(eql list myvar-x1))

such that:

(dest-is-xvar-p myvar-x1) ;; this doesn't work...

returns true.

What did you expect it to return. You asked, (eq myvar-x1 myvar-x1);
of course it's true.

i can't work out how to do this without quoting the argument to
dest-is-xvar-p:

(defun dest-is-xvar-p (alist)
(if (eq alist 'myvar-x1)
't
'nil))

(dest-is-xvar-p 'myvar-x1)

Doesn't this also return true? Now you're asking (eq 'myvar-x1
'myvar-x1) which is also true but for a different reason.

works, but i want to have a function which doesn't require me to
quote the argument.

can anyone suggest a simple lisp-ish way of doing this?

It's not clear what "this" is. Maybe you can step back and explain
what you're really trying to do.

-Peter

--
Peter Seibel * peter@xxxxxxxxxxxxxxx
Gigamonkeys Consulting * http://www.gigamonkeys.com/
Practical Common Lisp * http://www.gigamonkeys.com/book/
.



Relevant Pages

  • possibly silly question re quoting of function arguments...
    ... (defvar myvar-x1 nil ... i want to be able to push and pop items onto & out of myvar-x1 etc. ... i want a predicate function that tells me whether a given list is of x ... (defun dest-is-xvar-p (alist) ...
    (comp.lang.lisp)
  • Re: possibly silly question re quoting of function arguments...
    ... i want a predicate function that tells me whether a given list is of x ... or y (e.g. myvar-x1 or myvar-y1) without having to quote the argument i ... (defun dest-is-xvar-p (list) ... and myvar-y1 without having to quote the function argument... ...
    (comp.lang.lisp)