Actually not the whole program.

Here is a brief overview. Take with a grain of salt since this is coming from someone just learning Lisp (yes, I am filling in another hole in my programming experience). And for the many people who do know Lisp, corrections are welcome...

The fundamental unit of Lisp looks like this:
(OPERATOR DATA HERE)
It is surrounded by parens, starts with the operator, and then has 0 or more pieces of data. For example:
(+ 2 2)
would give 4. Now if you look at Lisp, you may think I am clearly wrong because you know darned well that there are some special things that look slightly different, for instance in:
'(+ 2 2)
the ' changes the construct inside so it is kept "as is". But what is really happening is that there is an input filter (called a reader macro) that transforms this before it hits Lisp, so what you actually entered looks like this:
(QUOTE + 2 2)
which follows the usual form, and QUOTE is a built-in operator that returns its data structure unevaluated and unmodified.

This is about the only syntactic sugar you see in the language. Which leads to a syntax that in Larry Wall's words looks like "Toenail clippings in oatmeal."

Now there are 2 basic choices for what the OPERATOR will do. The first thing is that you can take the various expressions that make the data, evaluate them in order, and then pass them to the function named by the operator. For instance if we had a function named factorial we could call it like this:

(factorial 10)
and if we wanted factorial of some expression we might call it like this:
(factorial (- n 1))
and given that we define functions with defun, and given that there is something called if out there, it comes as little surprise that we can define factorial by:
(defun factorial (n) (if (= 0 n) 1 (* n (factorial (- n 1)))))
(Ever wondered (why Lisp (is famous for (parens))) ?)

OK, so we have this dain-bramaged syntax which (not entirely coincidentally) looks like you are just directly typing in the parse-tree for your code, and we can do functions. Well what is other thing that I said we might want to do?

Well let us digress to Perl for a second. Suppose that you wanted a new control structure in Perl? What do you do? Well step 1 is talk to a real wizard and convince him that your control structure would really be a Good Thing. Then see him generalize it beyond all belief, then set out to implement it. And the way that he will implement it is to write a module that will read your code, parse it, find the new control structure, rewrite that, and leave everything else alone, then hand it off to perl to sort out the details. Then all will hail him as a really cool hacker, but since only perl can parse Perl he will fail. And the result will be bugs. Plus note that now if anyone else wants to add new control structures, it is now harder because they have to take into account the control structures that he added, as well as the (already unparseable) original mess that is Perl.

So new control structures in Perl are hard to do.

Now back to that other thing you would want to do with an operator in Lisp.

If the first thing that you might want to do with an operator in Lisp is to evaluate your arguments then pass the result to a function, the other natural thing to do is to rewrite your arguments and then evaluate again. This is called a macro and allows creating new control structures. Note that, unlike with Perl, there is no need to parse the whole file to do this - the parens tell Lisp the extent of your control structure. Note that there can be lots and lots of these control structures. (You name them, there are lots of names out there.) Note that the result is not inherently buggy because the things that went wrong for Perl are all non-issues.

So while in Perl a new control structure is a community undertaking (since we likely will all be living with it at some point in the future), in Lisp anyone can create a new control structure. For instance if you wanted to associate a bunch of lexical variables with fields from a query, you could create a control structure that makes that trivial. In Perl if you want the protection of a lexical, you have to manually synchronize the names of the variables with what fields they go to.

Or, to take another example, the vast majority of the looping and iteration constructs that people use in Perl are designed by Larry Wall and written into the language. The ones in Lisp are written by macros similar to ones that any user of the language can write themselves.

In short, at the cost of having virtually no syntactic sugar, Lisp has made the very idea of a control structure an abstract concept that you can write in code.

(Background: Those who wonder why this came up should read the article I linked to at Choose the most powerful language.)

UPDATE
petral pointed out that I should mention that you define macros with defmacro. Also I wanted to give READMORE tag in notes a try. :-)


In reply to Re (tilly) 2: Perlmonk Oedipus Complex? by tilly
in thread Perlmonk Oedipus Complex? by Sherlock

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.