newLISP Fan Club

Forum => newLISP newS => Topic started by: johnd on April 29, 2008, 10:05:23 AM

Title: pop-assoc, assoc, and lookup
Post by: johnd on April 29, 2008, 10:05:23 AM
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
Title:
Post by: Lutz on April 29, 2008, 01:17:50 PM
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.
Title:
Post by: johnd on April 29, 2008, 01:50:31 PM
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
Title:
Post by: johnd on April 29, 2008, 01:52:06 PM
I mistyped in my last reply



Replace <key> with <key|keylist>



John