(global) bug and question

Started by Dmi, April 08, 2006, 08:27:51 AM

Previous topic - Next topic

Dmi

First, the bug:
dmi@dc:dmi$ newlisp
newLISP v.8.8.0-p2 on linux, execute 'newlisp -h' for more info.

> (global)
Segmentation fault


Second, a question:

How can I get a list of symbos of MAIN, that are maden global (either by

default or through (global sym))?
WBR, Dmi

Lutz

#1
There is no streight way to get a list of all global symbols, but you could do the following hack for a 'global?' predicate which you could 'map' on to (symbols) and filter for not primitive?:



(define (global? s)
        (let (mask (if (= (pack "d" 1) "0001") 0x02000000 0x00000200))
                (= (& (get-int (last (dump s))) mask) mask)))

> (global? 'x)
nil
> (global 'x)
x
> (global? 'x)
true
>


This tests the global bit of a symbol type field and works on both: big-endian and little-endia systems.



Lutz

newdep

#2
aaaaaaaa....your on the right track ;-)
-- (define? (Cornflakes))

Dmi

#3
Thanks!
WBR, Dmi

Dmi

#4
Hmm... on my little endian (i belive ;-) Intel Celeron the test shows following:
> (pack "d" 1)
"0100"

so the rule for mask should be inversed:
(let (mask (if (= (pack ">d" 1) "0001") 0x00000200 0x02000000))
WBR, Dmi

Lutz

#5
actually it should be like this:



define (global? s)
        (let (mask (if (= (pack "d" 1) "0001") 0x02000000 0x00000200))
                (= (& (get-int (last (dump s))) mask) mask)))


The '>' would always produce bigh-endian and the '<' always little-endian. So when testing for endianess, no '<' or '>' should be put. This should work for you.



Lutz

Dmi

#6
It does. Thanks again.
WBR, Dmi