removing items from hash table contexts...

Notices and updates
Locked
cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

removing items from hash table contexts...

Post by 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:

Code: Select all

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:

Code: Select all

> (find-all '(? 26) (Doyle) (println $0))
("street" 26)
What's the difference?

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

Post by Lutz »

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:

Code: Select all

(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
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

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... !

Locked