[comp.lang.scheme] Kleene puzzle

feeley@chaos.cs.brandeis.edu (Marc Feeley) (04/03/91)

Here is a little puzzle for all Schemers: what is the shortest standard
Scheme program that writes itself on the current output port?  Note that
we are interested with what is PRINTED by the program and not the value of
the program itself (if this was the case the single character program 0
(or any other digit) would do the trick).  Here is one "self-printing"
program.  Is there a shorter one?

(let ((x '(write `(let ((x ',x)) ,x)))) (write `(let ((x ',x)) ,x)))

Marc -- feeley@cs.brandeis.edu

jaffer@zurich.ai.mit.edu (Aubrey Jaffer) (04/07/91)

Shorter in number of characters or number of cons cells?  This one
uses 2 fewer cons cells than your example.

((lambda(x)(write `((lambda(x) ,x) ',x))) '(write `((lambda(x) ,x) ',x)))

STCS8004%IRUCCVAX.UCC.IE@mitvma.mit.EDU (04/10/91)

A few news-letters back the following problem was posted:

  What is the shortest program that writes itself to the output port.
  The value of the program is not of concern, only the side-effect of
  the output.

I regret  that I  have lost  reference  to  the original  question and  the
solutions  proposed, but  if my  memory serves  me correctly  the solutions
involved  the use  of let  statements. I  believe the  following program is
shorter than  those previously proposed both  in terms of symbols  and cons
operations:

  ((lambda (x) (write `(,x ',x)))
   '(lambda (x) (write `(,x ',x))))

This is simply the 'write' version the shorter self-evaluating program

  ((lambda (x) `(,x ',x))
   '(lambda (x) `(,x ',x))).


G. Oulsnam                                    stcs8004@iruccvax.ucc.hea.ie