Extending polymorphic operations on symbols
Posted: Mon Aug 09, 2010 6:41 pm
Some operations defined for lists and strings can be extended on symbols. For example
(append 'x 'y) => xy
(chop 'zonk) => zon
also rest, find etc. Arguments pro:
Example of the code:[/color]
If I proposed it already, sorry.
(append 'x 'y) => xy
(chop 'zonk) => zon
also rest, find etc. Arguments pro:
- some programs can be both shorter and at least slightly faster: (append x0 y0) instead (sym (append (string x0) (string y0))),
- treatment of symbols as data seems to be in spirit of Lisp,
- as current behaviour is erroneous, proposed extension should be safe, except for programs relying on (throw-error (append 'x 'y)).
Example of the code:
Code: Select all
(setf CR (lambda(x)x))
(setf CAR first CDR rest L '(CAR CDR))
(do-while(< counter 1024)
(setf s (pop L))
(dolist(i '(CAR CDR))
(set 's0 (sym (append (chop (string i)) (rest (string s)))))
(set s0 (expand (lambda(x)(i (s x))) 's 'i))
(println (inc counter) ". " s0 "=" (eval s0))
(push s0 L -1)))
If I proposed it already, sorry.