I've rewritten the article, but not yet on the Wiki. I cleaned up a lot of unnecessary markup stuff. I'll post it within this mail.Please comment before I put it up on the Wiki!
The de-function ------------------------------ Reference: https://software-lab.de/doc/refD.html#de ------------------------------ Notes upfront - before each example, PicoLisp is restarted to avoid side effects - nil and t are just symbols (yoy could define a function using those as names). NIL and T are the boolean values for False and True - NIL is equal to the empty list () since: (= NIL ()) ------------------------------ Value of symbol 'de' :de -> 266836 returns the address of function 'de' in memory ------------------------------ Function 'de' accepts 2 arguments, which are by default NIL :(de) !? (de) NIL -- Protected symbol is equivalent to : (de NIL NIL) !? (de NIL NIL) NIL -- Protected symbol redefining NIL is not allowed ------------------------------ First argument of 'de' must be a (unprotected) symbol : (de 1) !? (de 1) 1 -- Symbol expected ------------------------------ Function 'de' just sets a symbol to some value (which *can* be a function definition) : (de x a b c) -> x : x -> (a b c) which is (under the hood) equivalent to : (de x . (a b c)) -> x : x -> (a b c) which explains why a function can have multiple body expressions : (de x (a b) (println a) (println b) (println (+ a b)) (+ 5 6)) -> x : x -> ((a b) (println a) (println b) (println (+ a b)) (+ 5 6)) where a and b are the formal parameters and we also see 4 expressions in the function body : (x 1 2) 1 -> output of first 'println' 2 -> output of second 'println' 3 -> output of third 'println' -> 11 -> result of the expression (+ 5 6) ------------------------------ The function 'de' isn't really needed (e.g. for creating a function definition) : (setq x '((p q) (println p) (println q) (+ p q))) -> ((p q) (println p) (println q) (+ p q)) : x -> ((p q) (println p) (println q) (+ p q)) : (x 1 2) 1 2 -> 3 ------------------------------ Also a function definition is nothing special, It is just a list : (de x (x y) (println x) (println y) (+ x y)) -> x : x -> ((x y) (println x) (println y) (+ x y)) : (car x) -> (x y) : (cadr x) -> (println x) : (caddr x) -> (println y) : (cadddr x) -> (+ x y) ------------------------------ Conclusion So in general, 'de' is a very uninteresting function. You could use 'set' or 'setq' instead: (set 'x '(a b c)) or (setq x '(a b c)) -- Alexander Burger 2018-05-25 12:39 GMT+02:00 Alexander Burger <[email protected]>: > Hi Arie, > > > In order to get things right, I will rewrite the article and put it on > the > > Wiki. > > Personally I find this a very nice way to try and also learn a lot, even > > with "very uninteresting functions". > > Indeed! And "uninteresting" was perhaps the wrong word :) > > ♪♫ Alex > > -- > UNSUBSCRIBE: mailto:[email protected]?subject=Unsubscribe >
