new to newLISP

Started by Ormente, August 31, 2010, 08:14:27 AM

Previous topic - Next topic

Lutz

#15
Perhaps nested association lists are better in your case:


(set 'MyVar '(
("keyA" ("subkey1" ("endkey1" "value1") ("endkey2" "value2")))
("keyB" ("subkey1" ("endkey1" "value3") ("endkey2" "value4")))
)
)

(assoc "keyA" MyVar) ;=> ("keyA" ("subkey1" ("endkey1" "value1") ("endkey2" "value2")))

; return both endkeys
(assoc (list "keyA" "subkey1") MyVar) ;=> ("subkey1" ("endkey1" "value1") ("endkey2" "value2"))

; return only one specific endkey
(assoc (list "keyA" "subkey1" "endkey2") MyVar) ;=> ("endkey2" "value2")

when retrieving the endkey and not a list, then lookup may be better:
; return the value only
(lookup (list "keyA" "subkey1" "endkey2") MyVar) ;=> "value2"

using (list "foo" "bar") instead of '("foo" "bar") allows you to use variables for keys:
(set 'k2 "endkey2")
(lookup (list "keyA" "subkey1" k2) MyVar) ;=> "value2"

Association lists are not as fast as dictionaries formed with name-space contexts, but if you only have a few hundred entries, the speed difference can be neglected.



You also could have a mixed arrangement, e.g. using "keyA", "keyB" as keys in a dictionary which stores association lists in each entry:
(new Tree 'MyVar) ; or as an alternative just (define MyVar:MyVar) which does the same

(MyVar "keyA"  '("subkey1" ("endkey1" "value1") ("endkey2" "value2")))
(MyVar "keyA"  '("subkey1" ("endkey1" "value1") ("endkey2" "value2")))

(MyVar "keyA") ;=> ("subkey1" ("endkey1" "value1") ("endkey2" "value2")

(assoc "endkey2" (MyVar "keyA")) ;=> ("endkey2" "value2")

(lookup "endkey2" (MyVar "keyA")) ;=> "value"


this solution does a very fast access of the top level key (e.g. millins of records) then uses associative access inside the record itself.



you also can modify entries easily using 'setf'


(setf (lookup "endkey2" (MyVar "keyA")) "newValue2")

(lookup "endkey2" (MyVar "keyA")) ;=> "newVAlue2")

This last solution, using a hash tree for the top level and using associations for the sub levels, is also the most readable and probably the best solution.

Ormente

#16
Thanks a lot Lutz. That's what i ended doing for my website generator, but i was wondering if better ways were availlable.



In this case i can have a lot of documents, each one is stored in a context as an association list of fields. This is ok, because each doc have few fileds, even if i can have a lot of docs. But i can't see this as an efficient and straitforward solution for the general case.

cormullion

#17
Quote from: "Ormente"i'm wondering how much people use it, and what they build in the real world with it.


Hi! I use newLISP for various things, including web sites and text processing. Currently I'm not able to use it very much - my current work doesn't allow for any computer use and I seem to have little time outside work either. Also, my newLISP work seems to have got stuck recently - the development versions broke some of the code in my toolchain but I can't work out how or when to fix it (I seem to be stuck on v10.1).



One of the most interesting newLISP developments at the moment is kane-box over at http://lifezero.com/">//http://lifezero.com/.



Have fun.

kanen

#18
Thanks for the kind words!



It's actually http://www.lifezero.org">http://www.lifezero.org (or Kane-Box.com). :)


Quote from: "cormullion"
Quote from: "Ormente"i'm wondering how much people use it, and what they build in the real world with it.


Hi! I use newLISP for various things, including web sites and text processing. Currently I'm not able to use it very much - my current work doesn't allow for any computer use and I seem to have little time outside work either. Also, my newLISP work seems to have got stuck recently - the development versions broke some of the code in my toolchain but I can't work out how or when to fix it (I seem to be stuck on v10.1).



One of the most interesting newLISP developments at the moment is kane-box over at http://lifezero.com/">//http://lifezero.com/.



Have fun.
. Kanen Flowers http://kanen.me[/url] .

cormullion

#19
Sorry, Kanen! I went there once by mistake. It's all electronics, interestingly...

newBert

#20
Quote from: "Ormente"Hi everybody !



I'm a new newLISPer from France, and very happy to have found this pragmatic LISP.

Hello Ormente,

I'm a french NewLisper too ... a kind of ghost, in french "revenant" (= who is coming back), because I had given up programing a while ago.

I'm not a pro but I like NewLisp even if I made some diversions to Rebol, Lua, Euphoria, etc.

At present I use above all http://www.fbsl.net/homepage.html">FBSL, http://www.elica.net/site/index.html">ELICA and of course NewLISP ... just for the fun, most of the time.

:-)



NewLISP-GS[/i] is quite usable despite that, and in any case easy to use.
<r><I>>Bertrand<e></e></I> − <COLOR color=\"#808080\">><B>newLISP<e></e></B> v.10.7.6 64-bit <B>>on Linux<e></e></B> (<I>>Linux Mint 20.1<e></e></I>)<e></e></COLOR></r>