From: vavavoomy2
Subject: is lisp unique?
Date: 
Message-ID: <c5e42899.0209060913.77d8d6f8@posting.google.com>
Hello I was just looking at Kawa, the efforts to compile scheme to
Java.

One thing I am wondering about.  I heard that in Lisp, it is possible
to feed code as data and have the interpreter execute it as code.

As far as I know this is not possible in interpreted languages like
java.  How can scheme be compiled to java bytecode in that case?

Is there a name for this ability to execute data as code?  (Want to
search for info on the net but don't know what it's referred to.)

Farah

From: Oleg
Subject: Re: is lisp unique?
Date: 
Message-ID: <alautm$10g$1@newsmaster.cc.columbia.edu>
vavavoomy2 wrote:

> Hello I was just looking at Kawa, the efforts to compile scheme to
> Java.
> 
> One thing I am wondering about.  I heard that in Lisp, it is possible
> to feed code as data and have the interpreter execute it as code.
> 
> As far as I know this is not possible in interpreted languages like
> java.  How can scheme be compiled to java bytecode in that case?
> 
> Is there a name for this ability to execute data as code?  (Want to
> search for info on the net but don't know what it's referred to.)

Run-time compilation (Run-time interpretation OTOH is ubiquitous in 
interpreted languages :) Run-time compilation is easier in Lisp, but, 
technically, is possible in any language/system that allows dynamic 
linking/loading of DLLs.

I'm curious whether other people find this feature particularly useful. 
Examples?

Cheers,
Oleg
From: Nils Goesche
Subject: Re: is lisp unique?
Date: 
Message-ID: <lkadmvc4cp.fsf@pc022.bln.elmeg.de>
Oleg <············@myrealbox.com> writes:

> Run-time compilation (Run-time interpretation OTOH is ubiquitous in 
> interpreted languages :) Run-time compilation is easier in Lisp, but, 
> technically, is possible in any language/system that allows dynamic 
> linking/loading of DLLs.
> 
> I'm curious whether other people find this feature particularly useful. 
> Examples?

See Peter Norvig's PAIP for examples for how to convert things like
rule sets to compilable Common Lisp code.

Regards,
-- 
Nils Goesche
"Don't ask for whom the <CTRL-G> tolls."

PGP key ID 0x0655CFA0
From: Oleg
Subject: Re: is lisp unique?
Date: 
Message-ID: <albc1m$a6u$1@newsmaster.cc.columbia.edu>
Nils Goesche wrote:

> Oleg <············@myrealbox.com> writes:
> 
>> Run-time compilation (Run-time interpretation OTOH is ubiquitous in
>> interpreted languages :) Run-time compilation is easier in Lisp, but,
>> technically, is possible in any language/system that allows dynamic
>> linking/loading of DLLs.
>> 
>> I'm curious whether other people find this feature particularly useful.
>> Examples?
> 
> See Peter Norvig's PAIP for examples for how to convert things like
> rule sets to compilable Common Lisp code.
>

I haven't read the whole book (far from it). Are you referring to "9.6 A 
Case Study in Efficiency: The SIMPLIFY Program" ?

Oleg
From: Nils Goesche
Subject: Re: is lisp unique?
Date: 
Message-ID: <87wupxlsvp.fsf@darkstar.cartan>
Oleg <············@myrealbox.com> writes:

> Nils Goesche wrote:
> 
> > Oleg <············@myrealbox.com> writes:
> > 
> >> Run-time compilation (Run-time interpretation OTOH is ubiquitous in
> >> interpreted languages :) Run-time compilation is easier in Lisp, but,
> >> technically, is possible in any language/system that allows dynamic
> >> linking/loading of DLLs.
> >> 
> >> I'm curious whether other people find this feature particularly useful.
> >> Examples?
> > 
> > See Peter Norvig's PAIP for examples for how to convert things like
> > rule sets to compilable Common Lisp code.
> >
> 
> I haven't read the whole book (far from it). Are you referring to "9.6 A 
> Case Study in Efficiency: The SIMPLIFY Program" ?

That and chapter 12: ``Compiling Logic Programs''.

Regards,
-- 
Nils Goesche
Ask not for whom the <CONTROL-G> tolls.

PGP key ID #xD26EF2A0
From: Tim Bradshaw
Subject: Re: is lisp unique?
Date: 
Message-ID: <ey38z2c9u7y.fsf@cley.com>
* oleg inconnu wrote:

> I'm curious whether other people find this feature particularly
> useful.  Examples?

Our internal documentation system, DTML, is essentially a less-painful
SGML-like syntax (based on a news article by Erik Naggum) together
with tree-rewriting macros, implemented in Lisp.  These macros end up
as little Lisp function definitions, which get compiled on the fly.  I
used to stress about compilation time since in the worst case these
can get compiled every time a document is processed, but it turns out
to be a non-issue.

--tim
From: Luke Gorrie
Subject: Re: is lisp unique?
Date: 
Message-ID: <lh4rd0jmnu.fsf@bluetail.com>
Tim Bradshaw <···@cley.com> writes:

> * oleg inconnu wrote:
> 
> > I'm curious whether other people find this feature particularly
> > useful.  Examples?
> 
> Our internal documentation system, DTML, is essentially a less-painful
> SGML-like syntax (based on a news article by Erik Naggum) together
> with tree-rewriting macros, implemented in Lisp.  These macros end up
> as little Lisp function definitions, which get compiled on the fly.  I
> used to stress about compilation time since in the worst case these
> can get compiled every time a document is processed, but it turns out
> to be a non-issue.

FYI, this is done in Erlang too. For example, the Yaws
(yaws.hyber.org) webserver compiles dynamic web pages into Erlang
modules and (re)loads the code any time the file itself is
modified. This technique is also common in Java webservers.

In these cases the files being processed aren't macro-implemented
little languages, so that still distinguishes lisp. But they do have a
compiler available at runtime and put it to good use.

To answer the previous question about how Kawa works: java does let
you feed in data and use it as code at at runtime, it's just that the
data format is low-level java bytecodes (being passed to
ClassLoader.defineClass()). So you need to compile your source
language into bytecodes first, which is what Kawa does.

Cheers,
Luke
From: Reini Urban
Subject: Re: is lisp unique?
Date: 
Message-ID: <3D7BD372.7080802@x-ray.at>
Luke Gorrie schrieb:
> FYI, this is done in Erlang too. For example, the Yaws
> (yaws.hyber.org) webserver compiles dynamic web pages into Erlang
> modules and (re)loads the code any time the file itself is
> modified. This technique is also common in Java webservers.

Also with perl, esp. with mod_perl.
-- 
Reini Urban
http://xarch.tu-graz.ac.at/home/rurban/
From: Oleg
Subject: Re: is lisp unique?
Date: 
Message-ID: <alglv8$6dr$1@newsmaster.cc.columbia.edu>
Reini Urban wrote:

> Luke Gorrie schrieb:
>> FYI, this is done in Erlang too. For example, the Yaws
>> (yaws.hyber.org) webserver compiles dynamic web pages into Erlang
>> modules and (re)loads the code any time the file itself is
>> modified. This technique is also common in Java webservers.
> 
> Also with perl, esp. with mod_perl.

But none of these compile to NATIVE CODE at run-time, do they?

Oleg
From: Thomas Lindgren
Subject: Re: is lisp unique?
Date: 
Message-ID: <lz8z2bqu7t.fsf@no-longer-at.bluetail.com>
Oleg <············@myrealbox.com> writes:

> But none of these compile to NATIVE CODE at run-time, do they?

Erlang does, if you tell it to. Dynamic native (re-)linking, etc.,
that is, not fancy runtime code generation with partial evaluation and
whatnot.

I presume Java does too. (Isn't that where the term just-in-time
compilation came from, after all?)

I'd say all of this is a quality-of-implementation issue, though.

Best,
			Thomas
-- 
						Thomas Lindgren
I'd rather write programs that write programs than write programs-[R. Sites]
From: Joe Marshall
Subject: Re: is lisp unique?
Date: 
Message-ID: <3csjw972.fsf@ccs.neu.edu>
Oleg <············@myrealbox.com> writes:

> 
> But none of these compile to NATIVE CODE at run-time, do they?

Native code?  What's that?
From: Oleg
Subject: Re: is lisp unique?
Date: 
Message-ID: <alik29$ctf$1@newsmaster.cc.columbia.edu>
Joe Marshall wrote:

> Oleg <············@myrealbox.com> writes:
> 
>> 
>> But none of these compile to NATIVE CODE at run-time, do they?
> 
> Native code?  What's that?

I would define it as the property of not having a considerable efficiency 
upper bound while implementing the same algorithms compared to C (Until I 
can come up with something better)

Oleg
From: Christopher Browne
Subject: Re: is lisp unique?
Date: 
Message-ID: <alib8v$1q0331$1@ID-125932.news.dfncis.de>
A long time ago, in a galaxy far, far away, Joe Marshall <···@ccs.neu.edu> wrote:
> Oleg <············@myrealbox.com> writes:
>
>> 
>> But none of these compile to NATIVE CODE at run-time, do they?
>
> Native code?  What's that?

That's where the code localizes itself to the local native language.
When in France, that's French.  When in England, that's English.  When
in Japan, Kanji.

In Canada, it gets really confused, as there are two official
languages.  In the United States, it's even worse, as there is _no_
official language...
-- 
(reverse (concatenate 'string ··········@" "enworbbc"))
http://www3.sympatico.ca/cbbrowne/internet.html
CONNECTION CLOSED BY GOD.
From: Joe Schaefer
Subject: Re: is lisp unique?
Date: 
Message-ID: <m33csj6rnu.fsf@mumonkan.sunstarsys.com>
Oleg <············@myrealbox.com> writes:

> Reini Urban wrote:
> 
> > Luke Gorrie schrieb:
> >> FYI, this is done in Erlang too. For example, the Yaws
> >> (yaws.hyber.org) webserver compiles dynamic web pages into Erlang
> >> modules and (re)loads the code any time the file itself is
> >> modified. This technique is also common in Java webservers.
> > 
> > Also with perl, esp. with mod_perl.
> 
> But none of these compile to NATIVE CODE at run-time, do they?

Perl code needs a perl interpreter.  In the case of mod_perl,
the interpreter is embedded into apache.  This allows perl modules 
to be interpreted, compiled, and dynamically loaded into the 
webserver at runtime, and you can repeat the process as many times 
as you like without ever having to restart apache.

IIRC, a popular perl templating (HTML::Template?) module is able to 
compile (using say gcc) a template (plaintext) file directly into a 
shared C-library, and load it right into apache.  It keeps track
of updates to the template file, and will recompile/reload it as 
necessary.

-- 
Joe Schaefer
From: Reini Urban
Subject: Re: is lisp unique?
Date: 
Message-ID: <3D834B8F.1080308@inode.at>
Oleg schrieb:
> Reini Urban wrote:
>>Luke Gorrie schrieb:
>>
>>>FYI, this is done in Erlang too. For example, the Yaws
>>>(yaws.hyber.org) webserver compiles dynamic web pages into Erlang
>>>modules and (re)loads the code any time the file itself is
>>>modified. This technique is also common in Java webservers.
>>
>>Also with perl, esp. with mod_perl.
> 
> But none of these compile to NATIVE CODE at run-time, do they?

As already answered, perl up to 5 normally compiles itself to bytecode, 
which when loading a "dumped image" saves only startup time.
You can compile it to native code via a cc backend on non-windows 
platforms.
See perlcc, perldoc B:CC (badly optimising compiler to C, since they 
have no strict types) and perldoc B:C (just a bytecode dump to C).
On windows you have to manually fix a dynaloader problem.
This is similar to e.g. Gambit, calling cc at run-time.

perl6 will have a native code compiler backend (similar to java 
just-in-time compilers), but this will need some time. For now there's 
just the assembler ready, called parot. This time they try "To do  the 
right thing" (R), so it will need some more years...
-- 
Reini Urban - Programmer - http://inode.at
From: Pascal Costanza
Subject: Re: is lisp unique?
Date: 
Message-ID: <alapqo$o2a$1@newsreader2.netcologne.de>
vavavoomy2 wrote:
> Hello I was just looking at Kawa, the efforts to compile scheme to
> Java.
> 
> One thing I am wondering about.  I heard that in Lisp, it is possible
> to feed code as data and have the interpreter execute it as code.
> 
> As far as I know this is not possible in interpreted languages like
> java.  How can scheme be compiled to java bytecode in that case?

No, in fact this is possible in Java but it is extremely complicated and 
requires a lot of effort. For example, the dynamic proxy classes in Java 
are implemented like that, and there are some frameworks available that 
allow you to do it. (One of those frameworks emerged from a project I 
have worked on; see http://javalab.cs.uni-bonn.de/research/jmangler.) I 
won't go into the details here because this would be very off-topic.

> Is there a name for this ability to execute data as code?  (Want to
> search for info on the net but don't know what it's referred to.)

You might want to look for "meta-circular interpreter". Two interesting 
articles about this topic are "The Roots of Lisp" at 
http://www.paulgraham.com/rootsoflisp.html and "The Art of the 
Interpreter ..." at http://library.readscheme.org/page1.html

In OO similar things can be realized with meta-object protocols, or more 
  recently aspect-oriented programming (the dynamic variants) or 
generative programming. It's also possible to implement a meta-circular 
interpreter with Prolog. And there's probably even more, but these are 
good starting points...

Pascal
From: Donald Fisk
Subject: Re: is lisp unique?
Date: 
Message-ID: <3D791ECA.2DE8DDC5@enterprise.net>
vavavoomy2 wrote:
> 
> Hello I was just looking at Kawa, the efforts to compile scheme to
> Java.
> 
> One thing I am wondering about.  I heard that in Lisp, it is possible
> to feed code as data and have the interpreter execute it as code.
> 
> As far as I know this is not possible in interpreted languages like
> java.  How can scheme be compiled to java bytecode in that case?
> 
> Is there a name for this ability to execute data as code?  (Want to
> search for info on the net but don't know what it's referred to.)

Prolog also has this property, and it's as useful there as it is in
Lisp.   Without its presence in a language, it's difficult to do AI
(and other highly complex information processing) in that language.
Many languages, e.g. Perl and JavaScript allow you to execute
arbitrary pieces of text, but not in as flexible a way as it is in
Lisp and Prolog, so those languages are much less suitable for AI.

Other features that make Lisp stand out as ideal for AI are the
simplicity of its syntax, the existence of symbols, and the support
for (singly linked) lists.   The last of these, of course, is
trivial to implement in Java/C/etc. (so why is are Java's class
libraries lumbered with the much less useful /doubly/ linked lists?
They're not more general -- they're less general if you think hard
enough about it.   In fact, if your algorithm uses them it's a
pretty good indication you're not doing things the right way.

> Farah

Le Hibou
-- 
Dalinian: Lisp. Java. Which one sounds sexier?
RevAaron: Definitely Lisp. Lisp conjures up images of hippy coders,
drugs,
sex, and rock & roll. Late nights at Berkeley, coding in Lisp fueled by
LSD.
Java evokes a vision of a stereotypical nerd, with no life or social
skills.
From: Per Bothner
Subject: Re: is lisp unique?
Date: 
Message-ID: <3D7C3160.4000704@bothner.com>
vavavoomy2 wrote:
> Hello I was just looking at Kawa, the efforts to compile scheme to
> Java.
> 
> One thing I am wondering about.  I heard that in Lisp, it is possible
> to feed code as data and have the interpreter execute it as code.
> 
> As far as I know this is not possible in interpreted languages like
> java.  How can scheme be compiled to java bytecode in that case?

The Kawa internals papers is a bit out-of-data, but should explain
how Kawa does it: http://www.gnu.org/software/kawa/internals.html

The basic "magic" is that Java has a primitive that allows you to
create new classes at run-time, given a bytecode representation of
the class.  This is how a web browser runs Java applets.

Creating the bytecode representation is a fair bit of work, but in
principle any compiler-based Scheme implementation does similar
things.
-- 
	--Per Bothner
···@bothner.com   http://www.bothner.com/per/