removing items from hash table contexts...

Started by cormullion, November 28, 2008, 10:18:54 AM

Previous topic - Next topic

cormullion

You can use contexts as hash tables and see tham as assoc lists (manual: "The contents of the namespace can be shown as an association list:") But it appears you can't use all assoc-list techniques on them:


newLISP v.9.9.95 on OSX IPv4 UTF-8, execute 'newlisp -h' for more info.

> (define Doyle:Doyle)
nil
> (Doyle "baker" 221)
221
> (Doyle "street" 26)
26
>
> (Doyle)
(("baker" 221) ("street" 26))
>
> (pop-assoc "baker" (Doyle))
("baker" 221)
> (Doyle)
(("baker" 221) ("street" 26))


although you can use others:


> (find-all '(? 26) (Doyle) (println $0))
("street" 26)


What's the difference?

Lutz

#1
The list returned from (Doyle) is generated from  the namespace Doyle on the fly every-time you execute (Doyle).



So when you change that list you don't change the namespace, and then calling (Doyle) creates the complete list again.

But of course you could do:


(set 'lst (Doyle))

(pop-assoc "baker" lst)

lst => (("street" 26))


Perhaps the manual should say instead of: "hash tables can be seen as association lists" to: "association lists can be created from hash tables".

cormullion

#2
Thanks - I confused myself with my own writing, it seems... :)



BTW: How about a table for the manual showing which functions work on nested lists, and which on flat lists? I might have a go, but you might know of a shortcut... !