Hello. I cannot understand why this program die with stack overflow:
#1=(write '#1# :circle t)
I tried it only on clisp 2.34. Where bug lives: in clisp or in my head?
I think that before call to write '#1# is evaluated to circular object
#1=(write '#1# :circle t), and function write must not to evaluate it
again. But why overflow?
PS I'm sorry for my english.
In article <·······················@g14g2000cwa.googlegroups.com>,
rgo <···@mail.interzet.ru> wrote:
> Hello. I cannot understand why this program die with stack overflow:
> #1=(write '#1# :circle t)
> I tried it only on clisp 2.34. Where bug lives: in clisp or in my head?
> I think that before call to write '#1# is evaluated to circular object
> #1=(write '#1# :circle t), and function write must not to evaluate it
> again. But why overflow?
Try:
(progn #1=(write '#1# :circle t) nil)
Keep in mind that the return value of WRITE is the object that was
written, which is a circular list, and *PRINT-CIRCLE* is only bound to
T inside the WRITE call. So when the REPL prints the return value,
it will go on infinitely.
(Unless of course you manually (setf *print-circle* t) beforehand.)
-bcd
--
*** Brian Downing <bdowning at lavos dot net>
rgo wrote:
> Hello. I cannot understand why this program die with stack overflow:
> #1=(write '#1# :circle t)
The :CIRCLE T keyword paramter only affects the action of the WRITE
function call. But that WRITE call also returns a value, namely the
object which was written. And your Lisp listener will try to print that
object. Since *PRINT-CIRCLE* is set to false, the listener will try to
expand the infinite object.
Your program isn't a true quine since it cheats by retrieving a copy of
its own source code, rather than computing it from scratch. The hard
work is done by the language implementation.
By the way, if the language provided a standard function called QUINE
which prints the string "(QUINE)", would the program (QUINE) be
considered a quine?
:)
"rgo" <···@mail.interzet.ru> writes:
> Hello. I cannot understand why this program die with stack overflow:
> #1=(write '#1# :circle t)
> I tried it only on clisp 2.34. Where bug lives: in clisp or in my head?
> I think that before call to write '#1# is evaluated to circular object
> #1=(write '#1# :circle t), and function write must not to evaluate it
> again.
[1]> (setf *print-circle* t)
T
[2]> #1=(write '#1# :circle t)
#1=(WRITE '#1# :CIRCLE T)
#1=(WRITE '#1# :CIRCLE T)
[3]>
No problem with your program.
> But why overflow?
The overflow doesn't occur in your program, but in the REPL. write
returns the value it wrote, namely #1#. The Printer in the rePl tries
to print it and if *print-circle* is nil, it overflows the stack.
--
__Pascal Bourguignon__ http://www.informatimago.com/
Until real software engineering is developed, the next best practice
is to develop with a dynamic system that has extreme late binding in
all aspects. The first system to really do this in an important way
is Lisp. -- Alan Kay