From: Peter Keller on
In comp.lang.lisp Elena <egarrulo(a)gmail.com> wrote:
> On 4 Ago, 17:09, Peter Keller <psil...(a)cs.wisc.edu> wrote:
>> Specifically:http://letoverlambda.com/index.cl/guest/chap5.html#sec_4
>>
>> Would show you how to write a macro such that it adds Scheme's tail call
>> optimized "named let" into Common Lisp. ?This goes beyond the concept
>> of syntactic sugar and enters the domain of pure code transformation.
>
> Indeed, code transformation is what sets CL's macros apart. However,
> TCO is much more than that. Read here:
>
> http://stackoverflow.com/questions/2181852/tail-call-elimination-in-clojure

After reading that, I assert that I don't know how to take base CL
and make it tail recursive since redefining things like defun and
whatnot lead to package lock errors. Even things like define-compiler-macro
can't redefine any of the CL macros or functions.

One probably could have success if they created forms like defun-tco,
labels-tco, flet-tco, etc which kept track of their code expansions
and rewrote them to be tco. But at that point you've implemented a
tco enforced lisp dialect on top of CL.

> However, TCO could also just not be possible in CL because of its
> design:
>
> http://www.cliki.net/Tail%20Recursion

It may be true, I don't know.

-pete
From: Pascal J. Bourguignon on
Peter Keller <psilord(a)cs.wisc.edu> writes:

> In comp.lang.lisp Elena <egarrulo(a)gmail.com> wrote:
>> On 4 Ago, 17:09, Peter Keller <psil...(a)cs.wisc.edu> wrote:
>>> Specifically:http://letoverlambda.com/index.cl/guest/chap5.html#sec_4
>>>
>>> Would show you how to write a macro such that it adds Scheme's tail call
>>> optimized "named let" into Common Lisp. ?This goes beyond the concept
>>> of syntactic sugar and enters the domain of pure code transformation.
>>
>> Indeed, code transformation is what sets CL's macros apart. However,
>> TCO is much more than that. Read here:
>>
>> http://stackoverflow.com/questions/2181852/tail-call-elimination-in-clojure
>
> After reading that, I assert that I don't know how to take base CL
> and make it tail recursive since redefining things like defun and
> whatnot lead to package lock errors. Even things like define-compiler-macro
> can't redefine any of the CL macros or functions.
>
> One probably could have success if they created forms like defun-tco,
> labels-tco, flet-tco, etc which kept track of their code expansions
> and rewrote them to be tco. But at that point you've implemented a
> tco enforced lisp dialect on top of CL.

It is almost trivial to provide a package (possibly even named
"COMMON-LISP") which is like the "COMMON-LISP" package, but that is
not the implementation's "COMMON-LISP" package.

See for example:
http://www.informatimago.com/develop/lisp/small-cl-pgms/ibcl/

The trick is in defining a defpackage form such as:

(defmacro defpackage (name &rest options)
`(cl:defpackage ,name
,@(mapcar
(lambda (option)
(if (listp option)
(case (first option)
((:use)
(substitute "IBCL" "COMMON-LISP"
(substitute "IBCL" "CL" option)))
((:shadowing-import-from :import-from)
(if (member (string (second option))
'("CL" "COMMON-LISP")
:test (function string=))
(list* (first option)
"IBCL"
(cddr option))
option))
(otherwise option))))
options)))

where you substitute the "COMMON-LISP" package for your own. (You
also need to define your own reader and loader, but these components
are available too).


--
__Pascal Bourguignon__ http://www.informatimago.com/
From: Aaron W. Hsu on
Fren Zeee <frenzeee(a)gmail.com> writes:

>My question to CLISP/ELISP/scheme people is

>If there is a wrapper do nothing type function in elisp/clisp/scheme
>which can have the same effect as commenting out.

>This is because I dont like to do comment-region/uncomment-region in
>emacs.

>These three lispy languages dont seem to have comment block construct
>like C ie /* and */

Actually, there are a lot of them in common use. Here are the one's I
use regularly, and you can check with your implementation to see if it
provides them:

#| |# block comments
#; Expression comments

I find the expression comments to be very useful. Basically, it let's
you comment out the next expression, such as this:

(if (test)
#;(bad
nothing
or another)
(good thing)
(other thing))

Now, some people don't like it because it plays with their Emacs
commenting modes. Since I don't use Emacs, this doesn't bother me. ;-)
On the other hand, the workaround if you don't want to hack your Scheme
highlighting is to do something like this instead:

(if (test)
#;
(bad
nothing
or another)
(good thing)
(other thing))

This will keep the highlighting mostly in check and still do the same
thing.

Aaron W. Hsu
From: Pascal Costanza on
On 05/08/2010 21:04, Elena wrote:
> On 4 Ago, 17:09, Peter Keller<psil...(a)cs.wisc.edu> wrote:
>> Specifically:http://letoverlambda.com/index.cl/guest/chap5.html#sec_4
>>
>> Would show you how to write a macro such that it adds Scheme's tail call
>> optimized "named let" into Common Lisp. This goes beyond the concept
>> of syntactic sugar and enters the domain of pure code transformation.
>
> Indeed, code transformation is what sets CL's macros apart. However,
> TCO is much more than that. Read here:
>
> http://stackoverflow.com/questions/2181852/tail-call-elimination-in-clojure
>
> However, TCO could also just not be possible in CL because of its
> design:
>
> http://www.cliki.net/Tail%20Recursion

Here is a way how to do TCO in Common Lisp:
http://groups.google.com/group/comp.lang.lisp/msg/8f9dcf58a00aca27

It can't be implemented as just a macro, because it requires the
cooperation of different parts of a program. You can only do that as a
"real" language extension.

Macros provide "only" syntactic sugar, in the sense that they perform
only local program transformations.


Pascal

--
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
From: Elena on
On Aug 6, 10:43 am, Pascal Costanza <p...(a)p-cos.net> wrote:
> Here is a way how to do TCO in Common Lisp:http://groups.google.com/group/comp.lang.lisp/msg/8f9dcf58a00aca27
>
> It can't be implemented as just a macro, because it requires the
> cooperation of different parts of a program. You can only do that as a
> "real" language extension.

Thanks for the link, Pascal.

IMHO, that would be a better way to make TCO available, that is: TCO
should be explicit, since you know beforehand whether you want your
function to be tail recursive or not. Then, whenever you fail to
implement a tail recursion among mutually recursive functions, the
compiler should complain. If I'm not mistaken, OCaml has (somewhat)
explicit TCO. Or detecting such errors would better be left to test
cases?