* bug fixes for the new namespace hash functions
* changes and refinements in the 'wait-pid' functionality
* default values in 'lookup'
files and changes notes: http://newlisp.org/download/development/
ps: Mac Users, click on uninstall first if experiencing difficulties to insta;;. The script also removes the receipt for newLISP in /Library/Receipts
development release newLISP v. 9.3.6
Dictionnary in NL-9.3.6
Hello,
How to delete an association in a dictionnary (newLisp-3.9.6)?
To remove an association I must do this:
instead of:
The following attempt doesn't work either:
Where do I err? ;-)
How to delete an association in a dictionnary (newLisp-3.9.6)?
Code: Select all
(define invent:invent)
(map invent '("apples" "bananas" "oranges" "pears") '(430 312 274 137))
(println (invent)) ;-> (("apples" 430) ("bananas" 312) ("oranges" 274) ("pears" 137))
Code: Select all
(set 'lst (invent))
(pop-assoc (lst "apples"))
(println lst) ; -> (("bananas" 312) ("oranges" 274) ("pears" 137))
Code: Select all
(pop-assoc ((invent) "apples"))
Code: Select all
(define (remove ctx key)
(pop-assoc (ctx key)))
(remove (invent) "apples")
(println (invent)) ; -> (("apples" 430) ("bananas" 312) ("oranges" 274) ("pears" 137))
Bertrand − newLISP v.10.7.6 64-bit on Linux (Linux Mint 20.1)
pop-assoc is for association lists not hashes. See here:
http://www.newlisp.org/downloads/newlis ... #pop-assoc
to remove hash associations, just set them to nil:
The list you get when executing (invent) is an association list, but the method used to created hash associations stores the key-values pairs in a namespace:
Associations in list are a different method of dealing with associations, and you can use pop-assoc here:
Perhpas what confuses you, is the fact that in namespace hashing (invent) recturns an association list. This is just for convenience, its a practical way to convert a hash namespace into an association list and vice versa:
So you can convert one data representation into the other. Namespace hashes are good for big data quantities, e.g. maintaining thousands or millions of key-value pairs. For a hundred or less, old fashioned association lists are faster.
http://www.newlisp.org/downloads/newlis ... #pop-assoc
to remove hash associations, just set them to nil:
Code: Select all
> (invent "apples" nil)
nil
> (invent)
(("bananas" 312) ("oranges" 274) ("pears" 137))
>
The list you get when executing (invent) is an association list, but the method used to created hash associations stores the key-values pairs in a namespace:
Code: Select all
> (symbols invent)
(invent:_bananas invent:_oranges invent:_pears invent:invent)
>
Code: Select all
> (set 'Alist '(("apples" 430) ("bananas" 312) ("oranges" 274) ("pears" 137)))
(("apples" 430) ("bananas" 312) ("oranges" 274) ("pears" 137))
> (pop-assoc (Alist "apples"))
("apples" 430)
> Alist
(("bananas" 312) ("oranges" 274) ("pears" 137))
>
Code: Select all
; and association list
(set 'Alist '(("apples" 430) ("bananas" 312) ("oranges" 274) ("pears" 137)))
; convert it into a hash namespace
> (define invent:invent)
> (invent Alist)
invent
> (invent)
(("apples" 430) ("bananas" 312) ("oranges" 274) ("pears" 137))
> (invent "bananas")
323
>
Ah, and it's even simpler than I thought :)Lutz wrote:To remove hash associations, just set them to nil
Yes and, for my purpose, association lists are quite sufficient and more convenient. But I'll remember that hash tables are ...Lutz wrote:Perhpas what confuses you, is the fact that in namespace hashing (invent) recturns an association list.
Many thanksLutz wrote:... just for convenience, its a practical way to convert a hash namespace into an association list and vice versa
:)
Bertrand − newLISP v.10.7.6 64-bit on Linux (Linux Mint 20.1)