Mailing List Archive

Support open source code!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ++CD-ROM drive



>>>>> "Darren" == Darren Cook <darrenj@example.com> writes:

    Darren> Is this how lisp does generic code as well?

No.  Lisp has much stronger typing, although it is dynamic.

Lisp has two mechanisms for generic code.  One is polymorphic
functions.  That means that the function will accept different kinds
of arguments, and do the right thing with them.  Like Python, most
Lisps provide lists, vectors, and strings.  Also like Python, most
Lisps provide functions which will accept any of those and do the
right thing with them, or even mixtures.

The second is macros.  A macro takes the arguments without
interpreting them, and computes an expression involving them.  This
expression is then evaluated to get the value of the macro call.  The
reason this is efficient is that at compile time you don't need to
know the values of the arguments, so the macro expansion is done at
compile time and inlined into the compiled code.

I know of no other language with this feature.  You can of course
compute Python (or Perl or sh) expressions as strings and recursively
evaluate them, but AFAIK all those languages can only do the expansion
at runtime.  Because a Lisp program is also valid Lisp data and
vice-versa, it is almost trivial to build it into the language, and
thus allow efficiently compiled macros.

    Darren> Lisp is also interpreted rather than compiled isn't it?

Almost all Lisp implementations do provide interpreters, but almost
all do compile to a virtual machine (and not always so virtual).  A few
compile to C or whatever (I've never used them, though).

-- 
University of Tsukuba                Tennodai 1-1-1 Tsukuba 305-8573 JAPAN
Institute of Policy and Planning Sciences       Tel/fax: +81 (298) 53-5091
_________________  _________________  _________________  _________________
What are those straight lines for?  "XEmacs rules."


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links