unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* association list bug? -- version 1.6.4
@ 2005-11-15  2:00 Jon Wilson
  2005-11-15  5:01 ` Tomas Zerolo
  0 siblings, 1 reply; 8+ messages in thread
From: Jon Wilson @ 2005-11-15  2:00 UTC (permalink / raw)


Hi y'all,
The following doesn't seem correct.
We have an association list defined such that:

(assoc '+ forms)
=>
(+ . "+")

But,

(assoc-ref '+ forms)
=>
#f

However, if we look at how assoc-ref is supposed to be defined 
according to the guile manual 
("http://www.gnu.org/software/guile/docs/guile-ref/Retrieving-Alist-Entries.html#Retrieving%20Alist%20Entries"), 
we have

(let ((ent (assoc '+ forms)))
     (and ent (cdr ent)))
=>
"+"

Is this a known bug with 1.6.4 and I just need to get off my duff and 
upgrade?

What more information could I provide that might help diagnose this?
Regards,
Jon


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: association list bug? -- version 1.6.4
  2005-11-15  2:00 association list bug? -- version 1.6.4 Jon Wilson
@ 2005-11-15  5:01 ` Tomas Zerolo
  2005-11-15 16:49   ` Jon Wilson
  0 siblings, 1 reply; 8+ messages in thread
From: Tomas Zerolo @ 2005-11-15  5:01 UTC (permalink / raw)
  Cc: guile-user


[-- Attachment #1.1: Type: text/plain, Size: 491 bytes --]

On Mon, Nov 14, 2005 at 08:00:13PM -0600, Jon Wilson wrote:
> Hi y'all,
> The following doesn't seem correct.
> We have an association list defined such that:
> 
> (assoc '+ forms)
> =>
> (+ . "+")
> 
> But,
> 
> (assoc-ref '+ forms)
> =>
> #f

Heh. The arguments are backwards. You want (assoc-ref forms '+)

Yeah, that has bitten others before you.

Consider vector-ref string-ref, list-ref, which take the vector,
string, list as first argument.

Regards
-- tomas

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

[-- Attachment #2: Type: text/plain, Size: 140 bytes --]

_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: association list bug? -- version 1.6.4
  2005-11-15  5:01 ` Tomas Zerolo
@ 2005-11-15 16:49   ` Jon Wilson
  2005-11-15 17:21     ` Ludovic Courtès
  0 siblings, 1 reply; 8+ messages in thread
From: Jon Wilson @ 2005-11-15 16:49 UTC (permalink / raw)


Hi Tomas,

 > Heh. The arguments are backwards. You want (assoc-ref forms '+)
 >
 > Yeah, that has bitten others before you.
 >
 > Consider vector-ref string-ref, list-ref, which take the vector,
 > string, list as first argument.
 >
 > Regards
 > -- tomas

Thanks for pointing that out!

Hmmm, perhaps a special note needs to be included in the 
documentation, since the argument order is exactly reversed from assoc 
assv assq.

Or, perhaps in some future version, the argument order for assoc and 
friends should be changed to match assoc-ref et al.

Regards,
Jon


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: association list bug? -- version 1.6.4
  2005-11-15 16:49   ` Jon Wilson
@ 2005-11-15 17:21     ` Ludovic Courtès
  2005-11-15 19:11       ` Jon Wilson
  0 siblings, 1 reply; 8+ messages in thread
From: Ludovic Courtès @ 2005-11-15 17:21 UTC (permalink / raw)
  Cc: guile-user

Hi,

Jon Wilson <j85wilson@fastmail.fm> writes:

> Or, perhaps in some future version, the argument order for assoc and 
> friends should be changed to match assoc-ref et al.

This is clearly not possible because `assq' et al. are part of R5RS and
`assoc-ref' has been part of Guile for a very, very long time.

One just has to be very careful when reading the manual.  ;-)

Thanks,
Ludovic.


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: association list bug? -- version 1.6.4
  2005-11-15 17:21     ` Ludovic Courtès
@ 2005-11-15 19:11       ` Jon Wilson
  2005-11-15 21:41         ` Kevin Ryde
  2005-11-17 16:10         ` Thien-Thi Nguyen
  0 siblings, 2 replies; 8+ messages in thread
From: Jon Wilson @ 2005-11-15 19:11 UTC (permalink / raw)


Hi Ludovic,

> This is clearly not possible because `assq' et al. are part of R5RS and
> `assoc-ref' has been part of Guile for a very, very long time.

Fair enough.

> One just has to be very careful when reading the manual.  ;-)

The manual says

"Like assq, assv and assoc, except that only the value associated with 
key in alist is returned."

which seems to suggest (incorrectly, obviously) that the arguments to 
both assoc and assoc-ref should be the same.  Perhaps, given that it 
seems that a fairly large number of people have misread the manual and 
gotten confused about this, it would be helpful to add a phrase 
explicitly pointing out that the argument order is reversed.  For example,

"Like assq, assv, and assoc (with argument order reversed), except 
that only the value associated with key in alist is returned."

One shouldn't have to be quite so very careful when reading the manual.
Regards,
Jon


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: association list bug? -- version 1.6.4
  2005-11-15 19:11       ` Jon Wilson
@ 2005-11-15 21:41         ` Kevin Ryde
  2005-11-16  0:00           ` Jon Wilson
  2005-11-17 16:10         ` Thien-Thi Nguyen
  1 sibling, 1 reply; 8+ messages in thread
From: Kevin Ryde @ 2005-11-15 21:41 UTC (permalink / raw)
  Cc: guile-user

Jon Wilson <j85wilson@fastmail.fm> writes:
>
> which seems to suggest (incorrectly, obviously) that the arguments to
> both assoc and assoc-ref should be the same.  Perhaps, given that it
> seems that a fairly large number of people have misread the manual and
> gotten confused about this, it would be helpful to add a phrase
> explicitly pointing out that the argument order is reversed.

I'll change the section to something like below.  Both shorter and
clearer I think.



5.6.11.3 Retrieving Alist Entries
.................................

`assq', `assv' and `assoc' find the entry in an alist for a given key,
and return the `(KEY . VALUE)' pair.  `assq-ref', `assv-ref' and
`assoc-ref' do a similar lookup, but return just the VALUE.

 -- Scheme Procedure: assq key alist
 -- Scheme Procedure: assv key alist
 -- Scheme Procedure: assoc key alist
 -- C Function: scm_assq (key, alist)
 -- C Function: scm_assv (key, alist)
 -- C Function: scm_assoc (key, alist)
     Return the first entry in ALIST with the given KEY.  The return is
     the pair `(KEY . VALUE)' from ALIST.  If there's no matching entry
     the return is `#f'.

     `assq' compares keys with `eq?', `assv' uses `eqv?' and `assoc'
     uses `equal?'.

 -- Scheme Procedure: assq-ref alist key
 -- Scheme Procedure: assv-ref alist key
 -- Scheme Procedure: assoc-ref alist key
 -- C Function: scm_assq_ref (alist, key)
 -- C Function: scm_assv_ref (alist, key)
 -- C Function: scm_assoc_ref (alist, key)
     Return the value from the first entry in ALIST with the given KEY,
     or `#f' if there's no such entry.

     `assq-ref' compares keys with `eq?', `assv-ref' uses `eqv?' and
     `assoc-ref' uses `equal?'.

     Notice these functions have the KEY argument last, like other
     `-ref' functions, but this is opposite to what what `assq' etc
     above use.

     When the return is `#f' it can be either KEY not found, or an
     entry which happens to have value `#f' in the `cdr'.  Use `assq'
     etc above if you need to differentiate these cases.


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: association list bug? -- version 1.6.4
  2005-11-15 21:41         ` Kevin Ryde
@ 2005-11-16  0:00           ` Jon Wilson
  0 siblings, 0 replies; 8+ messages in thread
From: Jon Wilson @ 2005-11-16  0:00 UTC (permalink / raw)


Hi Kevin,

> I'll change the section to something like below.  Both shorter and
> clearer I think.

Looks excellent to me!
Regards,
Jon


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: association list bug? -- version 1.6.4
  2005-11-15 19:11       ` Jon Wilson
  2005-11-15 21:41         ` Kevin Ryde
@ 2005-11-17 16:10         ` Thien-Thi Nguyen
  1 sibling, 0 replies; 8+ messages in thread
From: Thien-Thi Nguyen @ 2005-11-17 16:10 UTC (permalink / raw)
  Cc: guile-user

   From: Jon Wilson <j85wilson@fastmail.fm>
   Date: Tue, 15 Nov 2005 13:11:22 -0600

   One shouldn't have to be quite so very careful
   when reading the manual.

`read' is easy, `eval' is the tricky part...

thi


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2005-11-17 16:10 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-11-15  2:00 association list bug? -- version 1.6.4 Jon Wilson
2005-11-15  5:01 ` Tomas Zerolo
2005-11-15 16:49   ` Jon Wilson
2005-11-15 17:21     ` Ludovic Courtès
2005-11-15 19:11       ` Jon Wilson
2005-11-15 21:41         ` Kevin Ryde
2005-11-16  0:00           ` Jon Wilson
2005-11-17 16:10         ` Thien-Thi Nguyen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).