What are mdl and estack?
-
- Posts: 388
- Joined: Thu May 08, 2008 1:24 am
- Location: Croatia
- Contact:
What are mdl and estack?
These symbols are in (symbols) but I do not know their purpose.
For convenience newLISP contains a predefined 'module' function to load modules from the standard location:
'estack' is an undocumented experimental function returning the contents of the environment stack, which stores the binding of variables before entering a user defined function. Bindings are stored in an association list:
You could query the prior stat of a variable doing: (lookup 'var (estack)). The function may disappear at some point and there are no plans to make the environment stack writable by the user, as some programming languages allow. This would only encourage to write unreadable hard to understand code.
Code: Select all
(set (global 'module) (fn (mdl)
(load (append (env "NEWLISPDIR") "/modules/" mdl))))
; example
(module "mysql.lsp")
Code: Select all
(define (foo x y z)
(println "-> " (estack)) (bar x))
(define (bar x)
(println "->" (estack)) x)
(set 'x 1 'y 2 'z 3)
> (foo 11 22 33 44 55)
-> (($args ()) (z 3) (y 2) (x 1))
->(($args (44 55)) (x 11) ($args ()) (z 3) (y 2) (x 1))
11
>
-
- Posts: 388
- Joined: Thu May 08, 2008 1:24 am
- Location: Croatia
- Contact:
Code: Select all
> (foo 11 22 33 44 55)
-> (($args ()) (z 3) (y 2) (x 1))
->(($args (44 55)) (x 11) ($args ()) (z 3) (y 2) (x 1))
11
>
But it could be fun!... This would only encourage to write unreadable hard to understand code.
hehehe yeah we could rewrite the 99-bottle-of-beer in args ;-)
Would look even worse then this one ;-)
Would look even worse then this one ;-)
Code: Select all
(set 'y 99 'z '( " bottles" " of beer on the wall" "no more" "Take one down and pass it around, "
"Go to the store and buy some more, " ".\n" ))
(set 'a (z 0) 'b (z 1) 'c (z 2) 'd (z 3) 'e (z 4) 'f (z 5) 'g (0 -1 a) 'h (0 8 b) 'i (-2 d))
(for (x y 0)
(println
(if (> x 0) x (title-case c)) (if (= x 1) g a) b i (if (= x 0) c x) (if (= x 1) g a) h f
(if (= x 0) e d) (case x (0 y) (1 c) (true (- x 1))) (if (= x 2) g a) b f ))
-- (define? (Cornflakes))