Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>let me list a <strong>few important details</strong> about how <strong>metaprogramming</strong> works <strong>in lisp</strong> (or <a href="http://schemers.org/" rel="nofollow noreferrer">scheme</a>, or <a href="http://slate.tunes.org/documentation.html" rel="nofollow noreferrer">slate</a>, or pick your favorite "dynamic" language):</p> <ul> <li>when doing metaprogramming in lisp you <strong>don't have to deal with two languages</strong>. the meta level code is written in the same language as the object level code it generates. metaprogramming is not limited to two levels, and it's easier on the brain, too.</li> <li>in lisp you have the <strong>compiler available at runtime</strong>. in fact the compile-time/run-time distinction feels very artificial there and is very much subject to where you place your point of view. in lisp with a mere function call you can compile functions to machine instructions that you can use from then on as first class objects; i.e. they can be unnamed functions that you can keep in a local variable, or a global hashtable, etc...</li> <li><strong>macros</strong> in lisp are very simple: a bunch of functions stuffed in a hashtable and given to the compiler. for each form the compiler is about to compile, it consults that hashtable. if it finds a function then calls it at compile-time with the original form, and in place of the original form it compiles the form this function returns. (modulo some non-important details) so lisp macros <strong>are basically plugins for the compiler</strong>.</li> <li>writing a lisp function in lisp that evaluates lisp code is about two pages of code (this is usually called <strong>eval</strong>). in such a function you have all the power to introduce whatever new rules you want on the meta level. (making it run fast is going to take some effort though... about the same as bootstrapping a new language... :)</li> </ul> <p>random examples of what <strong>you can implement as a user library</strong> using lisp metaprogramming (these are actual examples of common lisp libraries):</p> <ul> <li>extend the language with <strong>delimited continuations</strong> (hu.dwim.delico)</li> <li>implement a <strong>js-to-lisp-rpc</strong> macro that you can use in javascript (which is generated from lisp). it expands into a mixture of js/lisp code that automatically posts (in the http request) all the referenced local variables, decodes them on the server side, runs the lisp code body on the server, and returns back the return value to the javascript side.</li> <li>add prolog like backtracking to the language that very seamlessly integrates with "normal" lisp code (see screamer)</li> <li>an <a href="https://stackoverflow.com/questions/106058/practical-example-of-lisps-flexibility#109131">XML templating extension</a> to common lisp (includes an example of <strong>reader macros</strong> that are plugins for the lisp parser)</li> <li>a ton of small DSL's, like <a href="http://www.lispworks.com/reference/HyperSpec/Body/m_loop.htm" rel="nofollow noreferrer"><em>loop</em></a> or <a href="http://common-lisp.net/project/iterate/" rel="nofollow noreferrer"><em>iterate</em></a> for easy looping</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload