Question about quoted list syntax...

1 view
Skip to first unread message

jdiamond

unread,
Sep 2, 2008, 10:19:22 PM9/2/08
to utexas-cs389r-fall2008
I noticed that an expression like:
(cons 1 '(2 3))
is illegal in both LISP and ACL2. In both environments, they see the
' as a strange extra parameter.

Some legal (accepted versions) are:
(cons 1 (list 2 3))
(cons 1 (quote (2 3))

but not

(cons 1 ('(2 3)))

even though
'(2 3)
by itself is accepted.

I thought a quoted list was a valid term, but it seems like it is not
allowed as an argument.

Any comments as to the scope where you can use a quoted list?
Thanks,
- Jeff

Sandip Ray

unread,
Sep 3, 2008, 12:58:30 AM9/3/08
to utexas-cs38...@googlegroups.com, Warren A. Hunt Jr.
Hi,

(cons 1 '(2 3)) is a well-defined thing and it stands for (cons '1
(cons '2 (cons '3 nil))) which actually evaluates to the object (1
. (2 . (3 . nil))) that is abbreviated as the list (1 2 3).

I believe the mistake you made is with an extra parenthesis. You
wrote (cons 1 ('(2 3))), which is indeed illegal. This is because
('(2 3)) does not mean anything. If we start with an open parenthesis
without a quote in front then what is expected is a function symbol.
But this is not provided. It's worth noting that '(2 3) is a way of
writing (quote 2 3), but ('(2 3)) is not. If instead you write
(cons 1 '(2 3)), that is legal and accepted.

Let me know if anything is still unclear.

-- Sandip

DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=googlegroups.com; s=beta;
h=domainkey-signature:received:received:x-sender:x-apparently-to
:mime-version:content-type:received:date:x-ip:user-agent
:x-http-useragent:message-id:subject:from:to:reply-to:sender
:precedence:x-google-loop:mailing-list:list-id:list-post:list-help
:list-unsubscribe:x-beenthere-env:x-beenthere;
bh=z2koPgdW5njxXkoTqe+zXixTnBNMc+hAkv1LfsnDhSQ=;
b=o7CoKj2BJE6jbeH91pAMs6zUcJsDX+SiYnOOXsDe6/ujJUrkcG806/qs/YZQnsPiqJ
lNPaKqfg0PpgeK0P4VADomnzZuTMKG4Z8c2aCPL08Kr/eDVN8C9fu1Q3drVkLoY1SOKK
AounmuoNYjqRwJAMqCACXJKmIgbAXIVxw4QD0=
DomainKey-Signature: a=rsa-sha1; c=nofws;
d=googlegroups.com; s=beta;
h=x-sender:x-apparently-to:mime-version:content-type:date:x-ip
:user-agent:x-http-useragent:message-id:subject:from:to:reply-to
:sender:precedence:x-google-loop:mailing-list:list-id:list-post
:list-help:list-unsubscribe:x-beenthere-env:x-beenthere;
b=6Q0R6WVCwAKftXFtCiUibVCUE4vqx6XRAMH4EQ03zNejt5Jyfi/ZQ7gQkL7nJHeNhH
oJXnFeez+wLIWTtY0EwNkgkYPs90NIVVXr7m7AAho4Y6II5N8dUSXCg6c98iJHNtZTuc
/yCM6kH30C+vRW6jmW13OyjzymJV2DY6u2SKY=
X-Sender: jeffrey...@gmail.com
X-Apparently-To: utexas-cs38...@googlegroups.com
Date: Tue, 2 Sep 2008 19:19:22 -0700 (PDT)
X-IP: 128.62.161.131
X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.1) Gecko/2008070206 Firefox/3.0.1,gzip(gfe),gzip(gfe)
From: jdiamond <jeffrey...@gmail.com>
Reply-To: utexas-cs38...@googlegroups.com
Sender: utexas-cs38...@googlegroups.com
X-Google-Loop: groups
Mailing-List: list utexas-cs38...@googlegroups.com;
contact utexas-cs389r-...@googlegroups.com
X-BeenThere-Env: utexas-cs38...@googlegroups.com
X-SpamAssassin-Status: No, hits=0.6 required=5.0
X-UTCS-Spam-Status: No, hits=-110 required=165

jdiamond

unread,
Sep 4, 2008, 4:35:59 PM9/4/08
to utexas-cs389r-fall2008
As mentioned in another email, I was having false negatives due to a
character translation error when I cut and pasted text - my quotes got
marred.

But here is a VERY KEY PRINCIPLE you need to correctly evaluate this
stuff:
Expand Macros BEFORE abbreviations.

This is something taken for granted by experienced LISP people, but
it's the only way that you can take a definition like this:
'(a . b) => (cons 'a 'b)
and apply it logically to a situation like this:
'(a b) => ???
Apply the list defmacro first:
'(cons a (cons b nil))
and only then apply the abbreviation revursively:
=> (cons 'a '(cons b nil)) => (cons 'a (cons 'b 'nil))

So far, it looks like defmacro is very similar to the C preprocessor -
> it happens before any interpretation takes place.
Reply all
Reply to author
Forward
0 new messages