the perens in lisp dilects is there for a reson... macros.

Discussion in 'Perl Misc' started by atbusbook@aol.com, Aug 5, 2006.

  1. Guest

    macros are sort of like c macros but more powerful. they are the
    manafestation of treating code like data. lisp code is just a textual
    representation of a data structure that is the list. this means that
    you can manipulate code to emulate structured controll constructs and
    elemanate boilerplate code. to show you the power of a macro heer is a
    while loop

    <code>
    (defmacro while (test &body body)
    `(do ()
    ((not ,test))
    ,@body)
    </code>

    Another one would be untill

    <code>
    (defmacro untill (test &body body)
    `(while (not ,test) ,@body))
    </code>

    wich is defined on top of while

    another test to wead out programers would be lisp stile macros because
    of variable capture
    and other perls of the macro world. but higenic macros can not have the
    power of true macros

    i also hear you talk about introspection. in lisp you use eval list

    lets define a sum function to show you

    <code>
    (defun sum (lst)
    (eval (append '(+) lst)))
    </code>

    another example would be this

    <code>
    (loop (print (eval (read))))
    </code>
    this is an interactive top level in 1 line

    another use is for calling of functions

    <code>
    (defvar cmds `('foo ,(lambda () (format t "hello world")))
    (funcall (getf cmds (read-from-string (read-line))))
    </code>
    of corse no error checking for comas and other things that could crash
    the program
    , Aug 5, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    278
    Terry Reedy
    Aug 5, 2006
  2. ekzept
    Replies:
    0
    Views:
    356
    ekzept
    Aug 10, 2007
  3. nanothermite911fbibustards
    Replies:
    0
    Views:
    364
    nanothermite911fbibustards
    Jun 16, 2010
  4. nanothermite911fbibustards
    Replies:
    0
    Views:
    309
    nanothermite911fbibustards
    Jun 16, 2010
  5. Replies:
    85
    Views:
    767
    Rick DeNatale
    Aug 21, 2006
Loading...

Share This Page