pop-assoc, assoc, and lookup

Notices and updates
Locked
johnd
Posts: 18
Joined: Mon May 09, 2005 7:54 pm
Location: San Francisco, CA

pop-assoc, assoc, and lookup

Post by johnd »

With the introduction in 9.3 of pop-assoc and modifications to assoc, I was wondering why they don't have the same syntax. Why not allow a form of pop-assoc that allows one to pop based on on key, like the first syntax of assoc?

What I'm proposing is this.

(pop-assoc (<list> <key>)) be equivalent to (pop-assoc <key> <list>)

This is how assoc works now. A single key can be done in a special case.

Also, why not extend this behavior to lookup as well, i.e. implement lookup so that it is again parallel to assoc?

John

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

The ( ... (L spec) ...) syntax was introduced for better readability when using multiple keys or indices. Visually it relates to implicit indexing. 'lookup' could have this too. Another possibility would be to eliminate 'lookup' and instead add an optional index to 'assoc'.

Recently introduced 'set-assoc' and 'pop-assoc' both don't have the flat syntax. There is also the possibility of eliminating the flat syntax entirely. Thoughts on all of this are still in process and there is now conclusion yet.

johnd
Posts: 18
Joined: Mon May 09, 2005 7:54 pm
Location: San Francisco, CA

Post by johnd »

One option would be to treat them all the same

(<command> <key> <list> [<options>])

assoc simply copies out of string, pop-assoc removes from the string, and lookup works just like assoc except doesn't return the <key>.

Roughly translated, do <command> with this <key> on <list>

Lookup could even be handled as an option to assoc.

More generally, all the commands that do something with key-value pair in a list -- e.g. extract it, copy it, set it, or copy the value only -- should have a similar syntax.

John

johnd
Posts: 18
Joined: Mon May 09, 2005 7:54 pm
Location: San Francisco, CA

Post by johnd »

I mistyped in my last reply

Replace <key> with <key|keylist>

John

Locked