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...
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:
X "ZL "_$T(+0)_" ZP"
Q
Another solution:
I wrote these several years ago - please do not code like this!
Quine 1:
Quine 2:
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.
Social networks
InterSystems resources
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue