Don't truncate checkInputs error string
[supercollider.git] / examples / other / quines.scd
blob5c6e9fee1d5d138a6cf3d03c3f75c47eb32591b3
1 // a conversation on quines, between Julian Rohrhuber, Jens Gulden and Tim Walters.
4 // is this quine a cheat?
6 { thisFunction.asCompileString ++ ".value" }.value
9 // ... and Jens Goulden wrote the first proper one:
12 { |a="", b=""| if (a!="", { a ++ "\"" ++ a.escapeChar($\\).escapeChar($\") ++ "\", \"" ++ b.escapeChar($\\).escapeChar($\") ++ "\"" ++ b }, { thisFunction.value("{ |a=\"\", b=\"\"| if (a!=\"\", { a ++ \"\\\"\" ++ a.escapeChar($\\\\).escapeChar($\\\") ++ \"\\\", \\\"\" ++ b.escapeChar($\\\\).escapeChar($\\\") ++ \"\\\"\" ++ b }, { thisFunction.value(", ") } ) }.value") } ) }.value
16 //" // the quotes mess up the syntax highlighting..
20 // so, with the addition of a "quote" method, something like this works:
22 (_ + '.(*' +  quote(_)  + '! 2)').(*"(_ + '.(*' +  quote(_)  + '! 2)')" ! 2)
25 // but maybe we can make an acoustic quine by sending the code as timecode over audio.
28 // quine with surplus
29 // acoustic quine
34 {|x|
35         var dt = 0.00019;
36         {
37         var num, u, t;
38                 x = x ++ '.(' ++  quote(x)  ++ ')';
39                 x.do {|x| num = num.add(x.ascii * dt) };
40                 u = TDuty.ar(Dseq(num), 0, Dseq(num / dt), doneAction:2);
41                 t = Timer.ar(u);
42                 SendTrig.ar(u, 0, t);
43                 u * 0.5
44         }.play;
45         
46         OSCresponder(s.addr, '/tr', { |t,r,msg| (msg[3] / dt + 0.5).asInteger.asAscii.post }).add;''
47         
48 }.("{|x|
49         var dt = 0.00019;
50         {
51         var num, u, t;
52                 x = x ++ '.(' ++  quote(x)  ++ ')';
53                 x.do {|x| num = num.add(x.ascii * dt) };
54                 u = TDuty.ar(Dseq(num), doneAction:2);
55                 t = Timer.ar(u);
56                 SendTrig.ar(u, 0, t);
57                 u * 0.5
58         }.play;
59         
60         OSCresponder(s.addr, '/tr', { |t,r,msg| (msg[3] / dt + 0.5).asInteger.asAscii.post }).add;''
61         
62 }")
67 // here is a short form, folded into a string, suggested by Tim Walters
70 var a = "{|x|
71         var dt = 0.00019;
72         {
73         var num, u, t;
74                 x = 'var a = ' ++ quote(x) ++ '; a.interpret.(a)';
75                 x.do {|x| num = num.add(x.ascii * dt) };
76                 u = TDuty.ar(Dseq(num), doneAction:2);
77                 t = Timer.ar(u);
78                 SendTrig.ar(u, 0, t);
79                 u * 0.5
80         }.play;
81         
82         OSCresponder(s.addr, '/tr', { |t,r,msg| (msg[3] / dt + 0.5).asInteger.asAscii.post }).add;''
83         
84 }"; a.interpret.(a)
92 // Jens Gulden answered and suggested to make the times explicit instead
93 // folding the top of the quine over the roll
97 {|num|
98     var dt = 0.00019;
99     {
100         var m, u, t;
101         num.do({|n, i|
102             if ( i != 0 , { m = m.add(0.00836).add(0.00608) });
103             n.asString.do({|x| m = m.add(x.ascii * dt)});            
104         });
105         num = num.add(0.00874).add(0.0076).add(0.01729).add(0.00608).addAll(m).add(0.01767).add(0.00779).add(0.01121);
106         u = TDuty.ar(Dseq(num), doneAction:2);
107         t = Timer.ar(u);
108         SendTrig.ar(u, 0, t);
109         u * 0.5
110     }.play;
112     OSCresponder(s.addr, '/tr', { |t,r,msg| (msg[3] / dt + 0.5).asInteger.asAscii.post }).add;''
114 }.([ 0.02337, 0.02356, 0.0209, 0.02223, 0.02071, 0.02356, 0.0019, 0.00608, 0.00608, 0.00608, 0.00608, 0.02242, 0.01843, 0.02166, 0.00608, 0.019, 0.02204, 0.00608, 0.01159, 0.00608, 0.00912, 0.00874, 0.00912, 0.00912, 0.00912, 0.00931, 0.01083, 0.01121, 0.0019, 0.00608, 0.00608, 0.00608, 0.00608, 0.02337, 0.0019, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.02242, 0.01843, 0.02166, 0.00608, 0.02071, 0.00836, 0.00608, 0.02223, 0.00836, 0.00608, 0.02204, 0.01121, 0.0019, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.0209, 0.02223, 0.02071, 0.00874, 0.019, 0.02109, 0.0076, 0.02337, 0.02356, 0.0209, 0.00836, 0.00608, 0.01995, 0.02356, 0.0019, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.01995, 0.01938, 0.00608, 0.0076, 0.00608, 0.01995, 0.00608, 0.00627, 0.01159, 0.00608, 0.00912, 0.00608, 0.00836, 0.00608, 0.02337, 0.00608, 0.02071, 0.00608, 0.01159, 0.00608, 0.02071, 0.00874, 0.01843, 0.019, 0.019, 0.0076, 0.00912, 0.00874, 0.00912, 0.00912, 0.01064, 0.00969, 0.01026, 0.00779, 0.00874, 0.01843, 0.019, 0.019, 0.0076, 0.00912, 0.00874, 0.00912, 0.00912, 0.01026, 0.00912, 0.01064, 0.00779, 0.00608, 0.02375, 0.00779, 0.01121, 0.0019, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.0209, 0.00874, 0.01843, 0.02185, 0.01577, 0.02204, 0.02166, 0.01995, 0.0209, 0.01957, 0.00874, 0.019, 0.02109, 0.0076, 0.02337, 0.02356, 0.0228, 0.02356, 0.00608, 0.02071, 0.00608, 0.01159, 0.00608, 0.02071, 0.00874, 0.01843, 0.019, 0.019, 0.0076, 0.0228, 0.00874, 0.01843, 0.02185, 0.01881, 0.01995, 0.01995, 0.00608, 0.00798, 0.00608, 0.019, 0.02204, 0.00779, 0.02375, 0.00779, 0.01121, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.0019, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.02375, 0.00779, 0.01121, 0.0019, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.0209, 0.02223, 0.02071, 0.00608, 0.01159, 0.00608, 0.0209, 0.02223, 0.02071, 0.00874, 0.01843, 0.019, 0.019, 0.0076, 0.00912, 0.00874, 0.00912, 0.00912, 0.01064, 0.01045, 0.00988, 0.00779, 0.00874, 0.01843, 0.019, 0.019, 0.0076, 0.00912, 0.00874, 0.00912, 0.00912, 0.01045, 0.01026, 0.00779, 0.00874, 0.01843, 0.019, 0.019, 0.0076, 0.00912, 0.00874, 0.00912, 0.00931, 0.01045, 0.0095, 0.01083, 0.00779, 0.00874, 0.01843, 0.019, 0.019, 0.0076, 0.00912, 0.00874, 0.00912, 0.00912, 0.01026, 0.00912, 0.01064, 0.00779, 0.00874, 0.01843, 0.019, 0.019, 0.01235, 0.02052, 0.02052, 0.0076, 0.02071, 0.00779, 0.00874, 0.01843, 0.019, 0.019, 0.0076, 0.00912, 0.00874, 0.00912, 0.00912, 0.01045, 0.01045, 0.01083, 0.00779, 0.00874, 0.01843, 0.019, 0.019, 0.0076, 0.00912, 0.00874, 0.00912, 0.00931, 0.01045, 0.01026, 0.01045, 0.00779, 0.00874, 0.01843, 0.019, 0.019, 0.0076, 0.00912, 0.00874, 0.00912, 0.00931, 0.00931, 0.0095, 0.00931, 0.00779, 0.01121, 0.0019, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.02223, 0.00608, 0.01159, 0.00608, 0.01596, 0.01292, 0.02223, 0.02204, 0.02299, 0.00874, 0.01843, 0.02166, 0.0076, 0.01292, 0.02185, 0.01919, 0.02147, 0.0076, 0.0209, 0.02223, 0.02071, 0.00779, 0.00836, 0.00608, 0.019, 0.02109, 0.0209, 0.01919, 0.01235, 0.01881, 0.02204, 0.01995, 0.02109, 0.0209, 0.01102, 0.0095, 0.00779, 0.01121, 0.0019, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.02204, 0.00608, 0.01159, 0.00608, 0.01596, 0.01995, 0.02071, 0.01919, 0.02166, 0.00874, 0.01843, 0.02166, 0.0076, 0.02223, 0.00779, 0.01121, 0.0019, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.01577, 0.01919, 0.0209, 0.019, 0.01596, 0.02166, 0.01995, 0.01957, 0.00874, 0.01843, 0.02166, 0.0076, 0.02223, 0.00836, 0.00608, 0.00912, 0.00836, 0.00608, 0.02204, 0.00779, 0.01121, 0.0019, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.00608, 0.02223, 0.00608, 0.00798, 0.00608, 0.00912, 0.00874, 0.01007, 0.0019, 0.00608, 0.00608, 0.00608, 0.00608, 0.02375, 0.00874, 0.02128, 0.02052, 0.01843, 0.02299, 0.01121, 0.0019, 0.0019, 0.00608, 0.00608, 0.00608, 0.00608, 0.01501, 0.01577, 0.01273, 0.02166, 0.01919, 0.02185, 0.02128, 0.02109, 0.0209, 0.019, 0.01919, 0.02166, 0.0076, 0.02185, 0.00874, 0.01843, 0.019, 0.019, 0.02166, 0.00836, 0.00608, 0.00741, 0.00893, 0.02204, 0.02166, 0.00741, 0.00836, 0.00608, 0.02337, 0.00608, 0.02356, 0.02204, 0.00836, 0.02166, 0.00836, 0.02071, 0.02185, 0.01957, 0.02356, 0.00608, 0.0076, 0.02071, 0.02185, 0.01957, 0.01729, 0.00969, 0.01767, 0.00608, 0.00893, 0.00608, 0.019, 0.02204, 0.00608, 0.00817, 0.00608, 0.00912, 0.00874, 0.01007, 0.00779, 0.00874, 0.01843, 0.02185, 0.01387, 0.0209, 0.02204, 0.01919, 0.01957, 0.01919, 0.02166, 0.00874, 0.01843, 0.02185, 0.01235, 0.02185, 0.01881, 0.01995, 0.01995, 0.00874, 0.02128, 0.02109, 0.02185, 0.02204, 0.00608, 0.02375, 0.00779, 0.00874, 0.01843, 0.019, 0.019, 0.01121, 0.00741, 0.00741, 0.0019, 0.0019, 0.02375]);
120 // so, we can, after all, wrap it all up into the extension of time..
122 // this one is currently out of order ...
124 // indepted to time
126 var a = [ 0.01353, 0.01364, 0.0132, 0.01364, 0.0011, 0.00099, 0.01353, 0.0011, 0.00099, 0.01298, 0.01067, 0.01254, 0.00352, 0.0121, 0.01287, 0.01199, 0.00484, 0.00352, 0.01287, 0.00484, 0.00352, 0.01276, 0.00484, 0.00352, 0.01089, 0.00352, 0.00671, 0.00352, 0.00737, 0.01144, 0.01067, 0.01254, 0.00506, 0.0121, 0.01188, 0.00649, 0.0011, 0.00099, 0.00099, 0.0132, 0.00352, 0.00671, 0.00352, 0.00429, 0.00517, 0.00517, 0.00352, 0.01155, 0.0121, 0.011, 0.01111, 0.01232, 0.01276, 0.01111, 0.011, 0.00352, 0.01276, 0.01221, 0.00352, 0.01276, 0.01155, 0.01199, 0.01111, 0.00429, 0.00352, 0.00473, 0.00473, 0.00352, 0.01089, 0.00352, 0.00473, 0.00473, 0.00352, 0.00429, 0.0044, 0.00429, 0.00352, 0.00473, 0.00473, 0.00352, 0.01089, 0.00352, 0.00473, 0.00473, 0.00352, 0.00429, 0.01298, 0.01067, 0.01254, 0.00352, 0.01067, 0.00352, 0.00671, 0.00352, 0.00429, 0.00352, 0.00473, 0.00473, 0.00352, 0.0132, 0.00506, 0.01067, 0.01265, 0.00737, 0.01221, 0.01199, 0.01232, 0.01155, 0.01188, 0.01111, 0.00913, 0.01276, 0.01254, 0.01155, 0.0121, 0.01133, 0.00352, 0.00473, 0.00473, 0.00352, 0.00429, 0.00649, 0.00429, 0.00352, 0.00473, 0.00473, 0.00352, 0.01089, 0.00352, 0.00473, 0.00473, 0.0011, 0.00099, 0.00099, 0.00099, 0.00429, 0.01067, 0.00506, 0.01089, 0.01221, 0.01188, 0.01188, 0.01111, 0.01089, 0.01276, 0.00352, 0.01353, 0.01364, 0.01089, 0.01364, 0.00352, 0.0044, 0.01089, 0.00352, 0.00517, 0.00352, 0.00528, 0.00506, 0.00528, 0.00528, 0.00528, 0.00539, 0.00539, 0.00451, 0.00506, 0.01254, 0.01221, 0.01287, 0.0121, 0.011, 0.00506, 0.01067, 0.01265, 0.00803, 0.0121, 0.01276, 0.01111, 0.01133, 0.01111, 0.01254, 0.00506, 0.01067, 0.01265, 0.00715, 0.01265, 0.01089, 0.01155, 0.01155, 0.01375, 0.00506, 0.01166, 0.01221, 0.01155, 0.0121, 0.00506, 0.01155, 0.0121, 0.01276, 0.01111, 0.01254, 0.01232, 0.01254, 0.01111, 0.01276, 0.00506, 0.0044, 0.01067, 0.00451, 0.00429, 0.00352, 0.00473, 0.00473, 0.00352, 0.01089, 0.00352, 0.00473, 0.00473, 0.00352, 0.00429, 0.00451, 0.00429, 0.00649, 0.0011, 0.00099, 0.00099, 0.0132, 0.00506, 0.011, 0.01221, 0.00352, 0.01353, 0.01364, 0.0132, 0.01364, 0.00352, 0.0121, 0.01287, 0.01199, 0.00352, 0.00671, 0.00352, 0.0121, 0.01287, 0.01199, 0.00506, 0.01067, 0.011, 0.011, 0.0044, 0.0132, 0.00506, 0.01067, 0.01265, 0.01089, 0.01155, 0.01155, 0.00352, 0.00462, 0.00352, 0.00528, 0.00506, 0.00528, 0.00528, 0.00528, 0.00539, 0.00539, 0.00451, 0.00352, 0.01375, 0.00649, 0.0011, 0.00099, 0.00099, 0.01287, 0.00352, 0.00671, 0.00352, 0.00924, 0.00748, 0.01287, 0.01276, 0.01331, 0.00506, 0.01067, 0.01254, 0.0044, 0.00748, 0.01265, 0.01111, 0.01243, 0.0044, 0.0121, 0.01287, 0.01199, 0.00451, 0.00484, 0.00352, 0.011, 0.01221, 0.0121, 0.01111, 0.00715, 0.01089, 0.01276, 0.01155, 0.01221, 0.0121, 0.00638, 0.0055, 0.00451, 0.00649, 0.0011, 0.00099, 0.00099, 0.01276, 0.00352, 0.00671, 0.00352, 0.00924, 0.01155, 0.01199, 0.01111, 0.01254, 0.00506, 0.01067, 0.01254, 0.0044, 0.01287, 0.00451, 0.00649, 0.0011, 0.00099, 0.00099, 0.00913, 0.01111, 0.0121, 0.011, 0.00924, 0.01254, 0.01155, 0.01133, 0.00506, 0.01067, 0.01254, 0.0044, 0.01287, 0.00484, 0.00352, 0.00528, 0.00484, 0.00352, 0.01276, 0.00451, 0.00649, 0.0011, 0.00099, 0.00099, 0.01287, 0.00352, 0.00462, 0.00352, 0.00528, 0.00506, 0.00583, 0.0011, 0.00099, 0.01375, 0.00506, 0.01232, 0.01188, 0.01067, 0.01331, 0.00649, 0.0011, 0.00099, 0.0011, 0.00099, 0.00869, 0.00913, 0.00737, 0.01254, 0.01111, 0.01265, 0.01232, 0.01221, 0.0121, 0.011, 0.01111, 0.01254, 0.0044, 0.01265, 0.00506, 0.01067, 0.011, 0.011, 0.01254, 0.00484, 0.00352, 0.00429, 0.00517, 0.01276, 0.01254, 0.00429, 0.00484, 0.00352, 0.01353, 0.00352, 0.01364, 0.01276, 0.00484, 0.01254, 0.00484, 0.01199, 0.01265, 0.01133, 0.01364, 0.00352, 0.0044, 0.01199, 0.01265, 0.01133, 0.01001, 0.00561, 0.01023, 0.00352, 0.00517, 0.00352, 0.00528, 0.00506, 0.00528, 0.00528, 0.00528, 0.00539, 0.00539, 0.00451, 0.00506, 0.01067, 0.01265, 0.00803, 0.0121, 0.01276, 0.01111, 0.01133, 0.01111, 0.01254, 0.00506, 0.01067, 0.01265, 0.00715, 0.01265, 0.01089, 0.01155, 0.01155, 0.00506, 0.01232, 0.01221, 0.01265, 0.01276, 0.00352, 0.01375, 0.00451, 0.00506, 0.01067, 0.011, 0.011, 0.00649, 0.00429, 0.00429, 0.0011, 0.00099, 0.0011, 0.01375 ];
127 a.collect {|c| (c / 0.00011).round.asInteger.asAscii }.join.interpret.(a)
132 // and a concluding question, posed by James McCartney, 09/14/2006:
133 // If I GPL a quine program, is the output GPL? 
134 // (nb. a quine is a program whose output is the same program).