DC Challenge: Write a quine in ObjectScript!
A quine is a computer program which takes no input and produces a copy of its own source code as its only output.
How about a fun challenge?
The task is to write a quine in InterSystems ObjectScript. It can be a class, or a method, or a routine, or just a line to be executed in a terminal. You decide!
Here's some resources you might consider useful:
Hard mode: do not use source code access functions.
Here's my (extremely uninspired, I know) attempt:
Class User.Quine
{
/// do ##class(User.Quine).Test()
ClassMethod Test()
{
set sc = ##class(%Compiler.UDL.TextServices).GetTextAsString($namespace, $classname(), .str)
write str
}
}
It produces this output:
How many different ways of producing a quine are there in ObjectScript?
Store as quine.int
Run it by DO ^quine
;; have any content
clone X "ZL quine ZS quine1 P"
;; may have more content
to avoid hardcode the actual routine name, you may do:
X "ZL "_$T(+0)_" ZP"
Just print... no store, no nothing
myQuine ;A quine test
Just print it, no store, no nothing...
myQuine ; A test for a quine x "zl @$zn p"
That's all. And you can name the routine as you like...
Ok, but how does it work?
Docs.
That's the MultiValue command. This is the doc for the ObjectScript one:
https://docs.intersystems.com/irislatest/csp/docbook/Doc.View.cls?KEY=RC...
Got it
an overcomplicated solution:
USER>d ^quine set q = $C(34) kill a //stolen from Wikipedia Java example set a($I(a)) = " set q = $C(34) kill a //stolen from Wikipedia Java example" set a($I(a)) = " set a($I(a)) = " set a($I(a)) = " write a(1),! " set a($I(a)) = " for i=1:1:a { " set a($I(a)) = " write a(2),q,a(i),q,! " set a($I(a)) = " }" set a($I(a)) = " for i=3:1:a {" set a($I(a)) = " write a(i),!" set a($I(a)) = " }" write a(1),! for i=1:1:a { write a(2),q,a(i),q,! } for i=3:1:a { write a(i),! }
X "ZL "_$T(+0)_" ZP"
Q
Another solution:
I wrote these several years ago - please do not code like this!
Quine 1:
s s=" s s= w $E(s,1,5),$C(34),s,$C(34),$E(s,6,*)" w $E(s,1,5),$C(34),s,$C(34),$E(s,6,*)
Quine 2:
s p="w $c(115,32,112,61,34)_p_$c(34,32,120,32,112)" x p
I am busy with mine. It is fiendish. Can a quine, having produced a copy of its own source code, delete itself and recreate itself using the output it generated?
Sure, why not.