Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

association lists ...

7 views
Skip to first unread message

Juan Jose Flores Romero

unread,
Jun 21, 1997, 3:00:00 AM6/21/97
to

Hi, all,

I found a really bad *feature* in Allegro CL 4.2 for SPARCS.
If an association list has nil as one of the keys, you get weird
behavior. Here's an example,

Allegro CL 4.2 [SPARC; R1] (5/14/96 9:41)
Copyright (C) 1985-1993, Franz Inc., Berkeley, CA, USA. All Rights Reserved.
;; Optimization settings: safety 2, space 1, speed 2, debug 2
;; For a complete description of all compiler switches given the current
;; optimization settings evaluate (EXPLAIN-COMPILER-SETTINGS).
USER(1): (setq alist '((a . 1) (b . 2) (nil . 3) (d . 4) (e . 5)))
((A . 1) (B . 2) (NIL . 3) (D . 4) (E . 5))
USER(2): (sublis alist '(= a b))
(= 1 2 . 3)
USER(3):

Guy and Steele only document the case when a pair is nil, but not
when the key is nil.

Does anyone know what the deal is here? Is it a bug (aka feature)?
--
,=========================================.
// JUAN JOSE FLORES \\
|| Deschutes Hall, Room 354 ||
|| University of Oregon ||
|| Eugene, Oregon ||
|| (541) 346 4416 ||
|| ju...@cs.uoregon.edu ||
\\ http://www.cs.uoregon.edu/~juan/ //
`========================================='

Erik Naggum

unread,
Jun 22, 1997, 3:00:00 AM6/22/97
to

* Juan Jose Flores Romero

| I found a really bad *feature* in Allegro CL 4.2 for SPARCS. If an
| association list has nil as one of the keys, you get weird behavior.

your example consistently yields the same results in _all_ the Lisp
environments I have access to.

(defun sublis-test (test-arg)
(let ((alist '((a . 1) (b . 2) (nil . 3) (d . 4) (e . 5))))
(sublis alist test-arg)))

(sublis-test '(= a b)) => (= 1 2 . 3)
(sublis-test ()) => 3
(sublis-test '(())) => (3 . 3)

I think there lies wisdom in this rewrite of the last example:

(sublis-test (cons nil nil)) => (3 . 3)

#\Erik
--
if we work harder, will obsolescence be farther ahead or closer?

Barry Margolin

unread,
Jun 22, 1997, 3:00:00 AM6/22/97
to

In article <5ohk7h$e...@helix.cs.uoregon.edu>,

Juan Jose Flores Romero <ju...@cs.uoregon.edu> wrote:
> I found a really bad *feature* in Allegro CL 4.2 for SPARCS.
>If an association list has nil as one of the keys, you get weird
>behavior. Here's an example,

Your confusion is about SUBLIS, not about association lists.

>USER(1): (setq alist '((a . 1) (b . 2) (nil . 3) (d . 4) (e . 5)))
>((A . 1) (B . 2) (NIL . 3) (D . 4) (E . 5))
>USER(2): (sublis alist '(= a b))

>(= 1 2 . 3)

This is the correct result. The last cons in a proper list has a cdr
containing NIL. You said to replace NIL with 3, and that's what it did.
Remember, SUBLIS and SUBST operate on trees, not lists.

--
Barry Margolin, bar...@bbnplanet.com
BBN Corporation, Cambridge, MA
Support the anti-spam movement; see <http://www.cauce.org/>

William Paul Vrotney

unread,
Jun 23, 1997, 3:00:00 AM6/23/97
to

In article <5ohk7h$e...@helix.cs.uoregon.edu> ju...@cs.uoregon.edu (Juan Jose
Flores Romero) writes:

>
> Hi, all,


>
> I found a really bad *feature* in Allegro CL 4.2 for SPARCS.
> If an association list has nil as one of the keys, you get weird
> behavior. Here's an example,
>

> Allegro CL 4.2 [SPARC; R1] (5/14/96 9:41)
> Copyright (C) 1985-1993, Franz Inc., Berkeley, CA, USA. All Rights Reserved.
> ;; Optimization settings: safety 2, space 1, speed 2, debug 2
> ;; For a complete description of all compiler switches given the current
> ;; optimization settings evaluate (EXPLAIN-COMPILER-SETTINGS).

> USER(1): (setq alist '((a . 1) (b . 2) (nil . 3) (d . 4) (e . 5)))
> ((A . 1) (B . 2) (NIL . 3) (D . 4) (E . 5))
> USER(2): (sublis alist '(= a b))
> (= 1 2 . 3)

> USER(3):
>
> Guy and Steele only document the case when a pair is nil, but not
> when the key is nil.
>

It means that a key *can* be NIL, so by CLTL your results are correct. This
makes sense to me in that the second argument to SUBLIS is a tree and not a
list.

In your example if you don't want to replace *any* NILs in the tree (and you
can't control alist) you could do something like

(sublis alist '(= a b) :test #'(lambda (x y) (if y (eql x y))))

If you don't want to replace just *cdr* NILs in the tree then it might be
nice if SUBLIS had a keyword argument :IGNORE-NIL-CDRS so that you could do

(sublis alist '(= a b) :ignore-nil-cdrs t)

however I would not like this since it makes SUBLIS less efficient than it
is now and it is easy to write your own version of SUBLIS to ignore NIL
cdrs. Therefore SUBLIS is fine the way it is in CLTL.

--

William P. Vrotney - vro...@netcom.com

0 new messages