define from dump

Pondering the philosophy behind the language
Locked
newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

define from dump

Post by newdep »

Hi Lutz,

having i.e.

> (define (a) (+ 1 1))
(lambda () (+ 1 1))

> (dump a)
(134727136 316 134721408 134721408 134727152)

But how do I retrieve the lambda "name" (in this case 'a)
when i only have -> (134727136 316 134721408 134721408 134727152)


Regards,
Norman.
-- (define? (Cornflakes))

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

Post by Lutz »

You do a dump of the lambda expression inside 'a, not 'a itself. When you define a function you assign a lambda expression to a symbol/variable.

Lutz

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

Post by newdep »

I must be doing something realy wrong..

From a dump i would like to see and the function name and its lambda..

..sofar im only hitting Memory-bank edges ;-)
-- (define? (Cornflakes))

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

Post by Lutz »

A (dump x) shows you the lisp cell contained in x. The contents knows nothing about the name of its container. Just like in (set 'x 123) the 123 doesn't know that it is in 'x, the <expression> in (define (foo) <expression>) doesn't know that it is contained in 'foo.

You have to distinguish between the symbol/variable and its content. Just like a number or string doesn't know which symbol/variable it holds a lambda expression doesn't know by which symbol it is owned. A 'define' is just like an assignment of a lambda expressin to a symbol/variable.

'dump' evaluates its argument, so (dump foo) does a dump of the lambda expression in foo, but (dump 'foo) shows the lisp cell of the symbol 'foo.

What are you trying to do? Why would you need the memory addresses of a lisp cell contents? 'dump' and 'cpymem' are used to hack newLISP internals.

Lutz

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

Post by newdep »

Hi Lutz,

Thanks for the feedback, I thought i had a mindgab here ;-)

>What are you trying to do? Why would you need the memory addresses of a lisp >cell contents? 'dump' and 'cpymem' are used to hack newLISP internals.

like 'save does, I want to be able to destiguish inside a running newlisp program
what the new defines are. A kind of control on new functions added.


My program accepts net-eval, the program wants to know what users add, so
i want actualy to know what they added by scanning with (dump) to catch the
function-name or symbols they added..

perhpas I should switch to namespaces and use context...
-- (define? (Cornflakes))

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

Post by Lutz »

i want actualy to know what they added by scanning with (dump) to catch the function-name or symbols they added..
This would give you a list of all symbols containing lambda expressions:

Code: Select all

(filter (fn (s) (lambda? (eval s))) (symbols))
but careful, somebody could do this:

Code: Select all

> (set 'p '(+ 3 4))
(+ 3 4)
> (eval p)
7
> 
and write programs without lambda expressions

Lutz

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

Post by newdep »

Aaaaaaaaagrrrrrr I completly forgot 'symbols... how is that possible!..pfffffff...
Im moving rocks while the water is already there ;-)

yes the symbol define is indeed my concern ;-)

thanks..
-- (define? (Cornflakes))

Locked