define from dump

Started by newdep, April 20, 2007, 04:01:08 AM

Previous topic - Next topic

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

#1
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

#2
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

#3
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

#4
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

#5
Quote 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:


(filter (fn (s) (lambda? (eval s))) (symbols))

but careful, somebody could do this:


> (set 'p '(+ 3 4))
(+ 3 4)
> (eval p)
7
>


and write programs without lambda expressions



Lutz

newdep

#6
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))