From: Brian
Subject: How wrong is it to make a quine in CL like this?
Date: 
Message-ID: <8a2576a0-9506-4274-9bb7-a74a01ead47e@13g2000hsb.googlegroups.com>
After wondering about it for a bit, I finally tried the following
code:

#1=(DEFUN QUINE () (SETF *PRINT-CIRCLE* T) '#1#)

It returned itself and it worked in SBCL and Clisp at least.  How
correct is this?

From: Dimiter "malkia" Stanev
Subject: Re: How wrong is it to make a quine in CL like this?
Date: 
Message-ID: <638sa9F258b1kU1@mid.individual.net>
Brian wrote:
> After wondering about it for a bit, I finally tried the following
> code:
> 
> #1=(DEFUN QUINE () (SETF *PRINT-CIRCLE* T) '#1#)
> 
> It returned itself and it worked in SBCL and Clisp at least.  How
> correct is this?

It works on ACL81 and LISPWORKS (though listpworks displays QUOTE, 
instead of ' - maybe another print setting?)

But it has a side effect, that it resets *print-circle* to T.

Fun times :)
From: Brian
Subject: Re: How wrong is it to make a quine in CL like this?
Date: 
Message-ID: <8c6a0915-88a9-4099-b8e9-7d453513e7f2@59g2000hsb.googlegroups.com>
Dimiter malkia Stanev wrote:
> It works on ACL81 and LISPWORKS (though listpworks displays QUOTE,
> instead of ' - maybe another print setting?)
>
> But it has a side effect, that it resets *print-circle* to T.
>
> Fun times :)
Who needs macros (just kidding) when you can do this:
#1=(DEFUN QUINE NIL (LET ((*PRINT-CIRCLE* T)) #2=(PRINT '#1#) #2# #2#
#2#) NIL)
From: Dimiter "malkia" Stanev
Subject: Re: How wrong is it to make a quine in CL like this?
Date: 
Message-ID: <638v2mF26h26kU1@mid.individual.net>
Brian wrote:
> Dimiter malkia Stanev wrote:
>> It works on ACL81 and LISPWORKS (though listpworks displays QUOTE,
>> instead of ' - maybe another print setting?)
>>
>> But it has a side effect, that it resets *print-circle* to T.
>>
>> Fun times :)
> Who needs macros (just kidding) when you can do this:
> #1=(DEFUN QUINE NIL (LET ((*PRINT-CIRCLE* T)) #2=(PRINT '#1#) #2# #2#
> #2#) NIL)

Ah, no longer with side effects!

Would that be the smallest program that prints itself as a side effect, 
without other side effects:

CL-USER 18 > #1=(DEFUN QUINE NIL (LET ((*PRINT-CIRCLE* T)) #2=(PRINT 
'#1#) nil))
QUINE

CL-USER 19 > (quine)

#1=(DEFUN QUINE NIL (LET ((*PRINT-CIRCLE* T)) (PRINT (QUOTE #1#)) NIL))
NIL

Well it prints NIL, but that's a functional effect of the REPL :)

Indeed fun times!

Thanks, Brian!
From: Brian
Subject: Re: How wrong is it to make a quine in CL like this?
Date: 
Message-ID: <b4137f1f-ee9a-47fe-bb14-6528cc6bfaf5@x41g2000hsb.googlegroups.com>
Dimiter malkia Stanev wrote:
> Would that be the smallest program that prints itself as a side effect,
> without other side effects:
>
> CL-USER 18 > #1=(DEFUN QUINE NIL (LET ((*PRINT-CIRCLE* T)) #2=(PRINT
> '#1#) nil))
You don't need the #2= there.

This also works from the REPL:
#1=(LET ((*PRINT-CIRCLE* T)) (PRINT '#1#) NIL)

> Thanks, Brian!
You're welcome.
From: Pascal Bourguignon
Subject: Re: How wrong is it to make a quine in CL like this?
Date: 
Message-ID: <87skz41g5t.fsf@thalassa.informatimago.com>
"Dimiter \"malkia\" Stanev" <······@gmail.com> writes:

> Brian wrote:
>> Dimiter malkia Stanev wrote:
>>> It works on ACL81 and LISPWORKS (though listpworks displays QUOTE,
>>> instead of ' - maybe another print setting?)
>>>
>>> But it has a side effect, that it resets *print-circle* to T.
>>>
>>> Fun times :)
>> Who needs macros (just kidding) when you can do this:
>> #1=(DEFUN QUINE NIL (LET ((*PRINT-CIRCLE* T)) #2=(PRINT '#1#) #2# #2#
>> #2#) NIL)
>
> Ah, no longer with side effects!
>
> Would that be the smallest program that prints itself as a side
> effect, without other side effects:

No, this is not the smallest common lisp quine.  There are a lot of
them, exactly one character (if you will ignore the zero-character
long program, which is also a quine).

C/USER[65]> 1
1

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

This universe shipped by weight, not volume.  Some expansion may have
occurred during shipment.
From: Juho Snellman
Subject: Re: How wrong is it to make a quine in CL like this?
Date: 
Message-ID: <87ablc9cqu.fsf@vasara.proghammer.com>
"Dimiter \"malkia\" Stanev" <······@gmail.com> writes:
> Would that be the smallest program that prints itself as a side
> effect, without other side effects:
> 
> CL-USER 18 > #1=(DEFUN QUINE NIL (LET ((*PRINT-CIRCLE* T)) #2=(PRINT
> '#1#) nil))
> QUINE

Trivially smaller:

  #1=(DEFUN QUINE () (WRITE '#1# :CIRCLE T) 1)

-- 
Juho Snellman
From: Kent M Pitman
Subject: Re: How wrong is it to make a quine in CL like this?
Date: 
Message-ID: <u1w6o5yoi.fsf@nhplace.com>
Brian <··············@gmail.com> writes:

> After wondering about it for a bit, I finally tried the following
> code:
> 
> #1=(DEFUN QUINE () (SETF *PRINT-CIRCLE* T) '#1#)
> 
> It returned itself and it worked in SBCL and Clisp at least.  How
> correct is this?

Well, I'm not sure what you mean by it "worked".

It's ok to write.  You can make a function that returns a circular
datum, and they are even "externalizable", so you can file compile
them, subject to the rules on identity (which you probably don't care
about here, since you're after visual sensation, but which are in
general a limitation for some applications).

The separate question of setting *print-circle* in the definition is
unclear.  You realize, I assume, that 

 (let ((*print-circle* nil)) (quine))

will cause you problems, right?  The special variable environment is
pretty emphemeral, and assuming that the value you return is about to
be printed is a pretty poor guess.  Consider too a file containing:

 (defvar *quine* (quine))
 (setq *print-circle* nil)
 (print *quine*)

which has the same issue.

Further, having entered that DEFUN you wrote interactively, if you
look at the value of the the + variable in the subsequent line to the
DEFUN, it will potentially be hard to read the result since you'll be
looking at it before *PRINT-CIRCLE* gets set, and so it might or might
not already be set to T for other reasons but won't be set due to the
execution of your function at all.

Btw, if you haven't seen it, you might find the following fun...

  http://www.maclisp.info/pitmanual/funnies.html#evaluating_new_ideas