From: joswig on
On 14 Mrz., 14:10, m_mom...(a)yahoo.com (Mario S. Mommer) wrote:
> "jos...(a)corporate-world.lisp.de" <jos...(a)lisp.de> writes:
> > On 14 Mrz., 13:35, Slobodan Blazeski <slobodan.blaze...(a)gmail.com>
> > wrote:
> >> On Mar 14, 12:47 pm, Rainer Joswig <jos...(a)lisp.de> wrote:
> >> > In article
> >> > <978067d6-b3ec-4a37-afde-3cd87280c...(a)q15g2000yqj.googlegroups.com>,
> >> >  "jos...(a)corporate-world.lisp.de" <jos...(a)lisp.de> wrote:
> >> > CL-USER 279 > (in-package "SCHEME")
> >> > #<The SCHEME package, 750/1024 internal, 0/16 external>
>
> >> > SCHEME 280 > (define (foo x) (x 1 2))
> >> > FOO defined.
>
> >> > SCHEME 281 > (foo list)
> >> > (1 2)
>
> >> Wow I didn't know that. Does it have call/cc?
>
> > The version above does not provide the full call/cc. But then I hope
> > it won't be used in user level scripts anyway...  ;-)
>
> Norvig's PAIP has a scheme implementation which, IIRC, supports full
> call/cc. The scheme source is compiled to byte code that runs on a VM.

Right, that one is/was used in CL applications.
From: refun on
In article <m3zl2bstee.fsf(a)winooski.ccs.neu.edu>, eli(a)barzilay.org says...
> As a purely anecdotal example, I have
> not seen any practical example of a CL program that defines a new
> language for some purpose, whereas this is quite common in PLT, to the
> point of defining a new language that is used in a few files and
> nowhere else.

DSL's and embedded languages everywhere when I look at Common Lisp.
Most introductory and more advanced CL book touch the subject in one way or the
other.

Various CL books show examples of embedding other languages in Lisp.
PAIP shows a Lispy Prolog interpreter and compiler , A Scheme interpreter and
compiler, and a number of other Domain Specific Languages. It usually keeps the
languages Lispy and avoids defining real syntaxes which gives one the
possibility of using real macros.

On Lisp is a book about macros and DSLs. It also contains a Prolog interpreter,
and shows how to do continuations via CPS and a simple code walker.

Practical Common Lisp shows a DSL for parsing binary files (define a structure
and have some macros generate reading/writing code for you) and a HTML
generation library (interpreter and compiler, and by the way, another
introductory CL book, ANSI CL has a similar chapter on the same subject).

Let Over Lambda has an embedded Forth compiler.

Of course the examples in the books are just educational examples and usually
not industrial strength, standard-compliant implementations. If you want that,
you should just google for the library you want, and you might just get what
you want. At least one commercial Lisp features a fully-featured embedded
Prolog implementations, but I never had the chance to look at it myself.

Lisp itself seems to me to be heavily about extending the language and defining
your own DSLs, some of which are standardized: LOOP is an interation language
of its own, CLOS and the MOP are one of the most advanced DSLs for OO and
defining/extending one's own OO system, FORMAT is its own string formatting
language, destructuring lambda lists are a language of its own as well. People
also defined other portable DSLs, one example would be ITERATE which tries to
make a more lispy LOOP. CL-YACC is another example of a portable library which
defines a Lispy YACC-like DSL. There's a few META parsing DSLs as well, some
come with their own syntax (reader macros), while others are lispy.
All portable Common Lisp code. Some Lisp implementations come with x86
assemblers, and movitz has a portable x86 assembler. There is an Python in CL
implementation called cl-python, it has a large standard library - it compiles
python to CL, and has a python lexer/parser. CL-PPCRE defines a DSL for using
perl-compatible regexps, and offers a lispy language as well. One could go on
and on about this, but I suggest you go look up the available libraries if you
want more examples.

The package system is powerful enough that you can shadow symbols, so you want
to change how some standard CL function works, you can cleanly replace it. If
you wanted, you could just not use the CL package and start from scratch (you
could still import specific symbols or qualify specific symbols you need,
packages are just read-time constructs). If you want a truly custom syntax,
make your own reader with your own lexer and parser. If you want to extend
Lisp's syntax (used by READ), use a reader macro. Since CL standardizes
compilation functions and related compiler hooks (such as macros) this makes it
very suitable for defining one's own DSLs. I'm sure you can do the same in
Scheme, but not in a very portable manner(at least not in R5RS, I haven't had
the time to study R6RS in detail).
From: refun on
In article <hniqau$78b$1(a)news.eternal-september.org>, refun(a)nospam.gmx.com
says...

And I completly forgot to mention that call/cc is supported in the PAIP's
Scheme's and there's some call/cc in Lisp libraries like CL-CONT (via CPS) or
SB-HEADDUMP(non-portable SBCL version via stack copying). Of course, call/cc is
not reconcilable* with some of CL's special forms, so one needs to be aware of
the limitations.

* - http://www.nhplace.com/kent/PFAQ/unwind-protect-vs-continuations-
original.html
From: refun on
In article <hniqau$78b$1(a)news.eternal-september.org>, refun(a)nospam.gmx.com
says...

Another thing that I forgot to mention is that there are CL implementations
which can have inline C code such as ECL, since they compile the lisp code to
C. At the same time, you have libraries like Parenscript which translate CL
code to JavaScript.

Other languages can be mixed with Lisp in one of the following ways:
1) Language->Lisp
Compile language to Lisp, or interpret language in Lisp (like the Prolog,
Forth, Scheme ... implementations. Oh there was also a C to Lisp compiler on
the Lisp Machine, I think you could find its source code by searching around
the internet as that particular compiler was open-sourced). If one has a good
native CL implementation, a Language->Lisp compiler can be seen as a cheap way
to get native compilation for an embedded language.

2) Lisp<->Lisp
Language is an extended Lisp. This is the most common kind of DSL as keeping
your language Lispy gives you all sorts of benefits of being able to mix Lisp
code freely. Most programmers want this kind of "DSL".

3) Lisp->Language
Compile Lisp to language. Useful when you need to generate code for other
platforms, such as CL->Javascript or C. Of course, language could also be some
specific platform's assembler, in which case it's just a natively compiled CL.
From: Nicolas Neuss on
Eli Barzilay <eli(a)barzilay.org> writes:

> Nicolas Neuss <lastname(a)kit.edu> writes:
>
>> Eli Barzilay <eli(a)barzilay.org> writes:
>>
>>> (FWIW, I tried to have a quick and naive translation of the CL code
>>> to PLT, and on a 64 bit machine with that input file it takes about
>>> 19 seconds. But I'm not posting any code since I know nothing
>>> about it or what it should produces... (What I got was some random
>>> text which looked like the output on a different post but also had
>>> a bunch of junk characters.))
>>
>> That junk output was probably OK (the text was too short for finding
>> the correct unique solution by this decryption technique). I also
>> checked only that my optimized version produced the same output as
>> Helmut's original CL version (and I was quite confident that Helmut
>> did check the output against the original Forth program).
>>
>> 19 seconds sounds quite reasonable. I would be really interested in
>> how that code and the procedure to compile and call it looks like.
>
> I've put the code at http://tmp.barzilay.org/x (but again, this was
> just a quick translation). You don't need to compile, just save that
> somewhere and run `mzscheme the-file'.

OK, doing that I see that it produces the correct result. But I observe
a time of 113 seconds and not 19 seconds (SBCL/optimized: 15 seconds).

Nicolas