pop-assoc, assoc, and lookup

Started by johnd, April 29, 2008, 10:05:23 AM

Previous topic - Next topic

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

#1
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

#2
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

#3
I mistyped in my last reply



Replace <key> with <key|keylist>



John