Defining types

For the Compleat Fan
Locked
Jeff
Posts: 604
Joined: Sat Apr 07, 2007 2:23 pm
Location: Ohio
Contact:

Defining types

Post by Jeff »

Is it possible to define new types in newlisp?
Jeff
=====
Old programmers don't die. They just parse on...

Artful code

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

Post by Lutz »

no two symbols in newLISP point to the same, except when pointing to symbols. So if you do:

Code: Select all

(set 'x "hello"
(set 'y x) => "hello"
those are two different memory pieces containing "hello". But when doing

Code: Select all

(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:

Code: Select all

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

(pop (evall x)) = "o"
(eval y) => "ntent of s"
Is there a way to discover symbols that point to a value?
yes, you still could do this:

Code: Select all

 (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.
Ooo! A reverse lookup! Interesting idea. Lutz?
yes that would be possible, you could create a reversed index:

Code: Select all

(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

Locked