Discussion
· Aug 16, 2021

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.

Wikipedia.

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?

Discussion (15)3
Log in or sign up to continue

an overcomplicated solution:

Go() [] PUBLIC
{
    s cont = 0,pos = 1,lines = 0
    do {
        set line = $Text(Go+pos)
        set cont = cont + (($LENGTH(line,"{")-1)-($LENGTH(line,"}")-1))
        set lines = lines + 1
        set pos = pos + 1
    } while (cont > 0)
    s x=1
    if (x=1) a=}
    f i=0:1:lines $Text(Go+i),!
    s x=1
    if (x=1) a=}
    if (a=x) {
        b=a
    }
}

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),!
 }