(global) bug and question

For the Compleat Fan
Locked
Dmi
Posts: 408
Joined: Sat Jun 04, 2005 4:16 pm
Location: Russia
Contact:

(global) bug and question

Post by Dmi »

First, the bug:

Code: Select all

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
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

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

Code: Select all

(define (global? s)
        (let (mask (if (= (pack "d" 1) "\000\001") 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
Last edited by Lutz on Sat Apr 08, 2006 8:28 pm, edited 2 times in total.

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

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

Dmi
Posts: 408
Joined: Sat Jun 04, 2005 4:16 pm
Location: Russia
Contact:

Post by Dmi »

Thanks!
WBR, Dmi

Dmi
Posts: 408
Joined: Sat Jun 04, 2005 4:16 pm
Location: Russia
Contact:

Post by Dmi »

Hmm... on my little endian (i belive ;-) Intel Celeron the test shows following:

Code: Select all

> (pack "\d" 1)
"\001\000"
so the rule for mask should be inversed:

Code: Select all

(let (mask (if (= (pack ">d" 1) "\000\001") 0x00000200 0x02000000))
WBR, Dmi

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

Post by Lutz »

actually it should be like this:

Code: Select all

define (global? s)
        (let (mask (if (= (pack "d" 1) "\000\001") 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
Posts: 408
Joined: Sat Jun 04, 2005 4:16 pm
Location: Russia
Contact:

Post by Dmi »

It does. Thanks again.
WBR, Dmi

Locked