newLISP Fan Club

Forum => Anything else we might add? => Topic started by: Jeff on June 29, 2007, 06:08:23 AM

Title: Defining types
Post by: Jeff on June 29, 2007, 06:08:23 AM
Is it possible to define new types in newlisp?
Title:
Post by: Lutz on June 29, 2007, 06:52:01 AM
no two symbols in newLISP point to the same, except when pointing to symbols. So if you do:


(set 'x "hello"
(set 'y x) => "hello"


those are two different memory pieces containing "hello". But when doing


(set 's "content of s")
(set 'x 's) => s
(set 'y x) => s

(eval x) => "content of s"
(eval y) => "content of s"


The two strings are the identical piece of memory, as you can show:


(pop s) => "c"
(eval x) => "ontent of s"
(eval y) => "ontent of s"

(pop (evall x)) = "o"
(eval y) => "ntent of s"


QuoteIs there a way to discover symbols that point to a value?


yes, you still could do this:


(set 'x "hello")
 (set 'y "hello")

(filter (fn (s) (= "hello" (eval s))) (symbols)) => (x y)


but of course this is just a linear lookup, nothing is indexed here.


QuoteOoo! A reverse lookup! Interesting idea. Lutz?


yes that would be possible, you could create a reversed index:


(set 'x "hello")
(set 'y 123)

; create a reverse index in Idx
(map (fn (s) (set (sym (string (eval s)) 'Idx) s )) (symbols))

(context Idx "hello") => x
(context Idx "123") => y


Lutz