Extending polymorphic operations on symbols

Started by Kazimir Majorinc, August 09, 2010, 11:41:49 AM

Previous topic - Next topic

Kazimir Majorinc

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]
  • [*]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)).
  • [/list]



    Example of the code](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)))[/code]



    If I proposed it already, sorry.
    http://kazimirmajorinc.com/\">WWW site; http://kazimirmajorinc.blogspot.com\">blog.

    Lutz

    #1
    Interesting idea! Also enjoyed your last blog post at:



    http://kazimirmajorinc.blogspot.com/2010/08/mccarthys-1960-recursive-functions-lisp.html">http://kazimirmajorinc.blogspot.com/201 ... -lisp.html">http://kazimirmajorinc.blogspot.com/2010/08/mccarthys-1960-recursive-functions-lisp.html



    here is a puzzle for everybody, why is this possible?
    > (map 1 '((a b c d) (e f g h) (i j k l)))
    ((b c d) (f g h) (j k l))
    > (map (curry 1 2) '((a b c d) (e f g h) (i j k l)))
    ((b c) (f g) (j k))
    >

    johu

    #2
    Nobody still post, I try.



    According to http://www.newlisp.org/downloads/newlisp_manual.html">Users Manual and Reference,
    Quote(map exp-functor list-args-1 [list-args-2 ... ])

    Successively applies the primitive function, defined function, or lambda expression exp-functor to the arguments specified in list-args-1, list-args-2-, returning all results in a list.

    Then,

    (map 1 '((a b c d) (e f g h) (i j k l)))
    (map (curry 1 2) '((a b c d) (e f g h) (i j k l)))
          ↓
    (list (1 '(a b c d)) (1 '(e f g h)) (1 '(i j k l)))
    (list ((curry 1 2) '(a b c d)) ((curry 1 2) '(e f g h)) ((curry 1 2) '(e f g h)))

    And,
    QuoteImplicit indexing for rest and slice

    Implicit forms of rest and slice can be created by prepending a list with one or two numbers for offset and length.

    Then,

    (1 '(a b c d)) → (b c d)
    (1 '(e f g h)) → (f g h)
    (1 '(i j k l)) → (j k l)

    Continuously,
    Quote(curry func exp)

    Transforms func from a function f(x, y) that takes two arguments into a function fx(y) that takes a single argument. curry works like a macro in that it does not evaluate its arguments. Instead, they are evaluated during the application of func.

    Then,
    Quote
    ((curry 1 2) '(a b c d)) → (1 2 '(a b c d)) → (b c)

    ((curry 1 2) '(e f g h)) → (1 2 '(e f g h)) → (f g)

    ((curry 1 2) '(i j k l)) → (1 2 '(i j k l)) → (j k)

    Additonally,
    QuoteImplicit indexing for nth

     In original Lisp, the first element in an s-expression list is applied as a function to the rest elements as arguments. In newLISP, a list in the functor position of an s-expression assumes self-indexing functionality using the index arguments following it.

    Then,
    > (map ''(a b c d) '(3 2 1 0))
    (d c b a)
    >

    I'm sorry if my English usage would be wrong or my words would be insufficient.

    Lutz

    #3
    Congratulations! Well done.



    If you want, send me an address and size (as a private message or email), I can send you a newLISP T-shirt :-)