Can you write a quine in SC?

Hi all,

This may be a dumb question, but is it possible to write a quine in SC?
Pretty sure those of you who can answer know what a quine is, but for the rest of us, it’s “a computer program which takes no input and produces a copy of its own source code as its only output” (from Wikipedia).

I know it’s not a terribly useful use case, but interested to know.
Thanks

Perhaps slightly cheating(?) but:

value { "value" + thisFunction.asCompileString }

hjh

1 Like

Curious: why do you say that’s cheating?
It does print the whole thing, right?
Thanks!! Fascinating.

The examples folder included with SC contains a document titled quines.scd, described as

“// a conversation on quines, between Julian Rohrhuber, Jens Gulden and Tim Walters.”

Could be a good place to start! :slight_smile:

2 Likes

Wow, I never even thought that would be there. Thanks!

Here, I was able to track it down for everyone:

Platform.resourceDir +/+ "Examples/other/quines.scd"

…and there’s a few online, as well:

https://sccode.org/search?q=quines

1 Like
x="x=%;x=x.format(34.asAscii++x++34.asAscii);x.postln;";x=x.format(34.asAscii++x++34.asAscii);x.postln;
1 Like

Yup, that’s a cheating quine Quine_(computing)#Self-evaluation

Here’s the smallest “cheating” quine in sclang:

0

Interestingly, an empty file doesn’t work in sclang because it would output nil :slight_smile:

Interesting – to literally take on the can-question in the title, i thought all Turing-complete languages can have quines, but now the seed of doubt has been planned in my mind…

An SCTweet Quine (by @nathan ?) :

interpret(x="/******/play{RLPF.ar(COsc.ar(b=Buffer.loadCollection(s,x.ascii.normalize(-1,1)),Osc.kr(b,1,0,65,35)),Osc.kr(b,0.1,0,300,1e3))/5}")

This original one needed some adaptation because SC was warning about

Warning: size of wavetable not a power of two (COsc)
Warning: size of wavetable not a power of two (Osc)

Source: