Results 1 to 10 of 10

Thread: Quines in Simba

  1. #1
    Join Date
    Jan 2007
    Location
    East Coast, USA
    Posts
    138
    Mentioned
    0 Post(s)
    Quoted
    38 Post(s)

    Default Quines in Simba


    Quines:
    What are they?

    Quines, in short, are curious pieces of code that can write themselves back character for character.
    For further reading check out: Wikipedia and this collection The Quine Page

    Why should you care?

    Because.

    What does it look like?

    Brace yourself. This is the compactest one I could find, at the time of writing, that works in Simba:

    Simba Code:
    const a='const a=';b='begin writeln(a,#39,a,#39#59#98#61#39,b,#39#59#10,b) end.';
    begin writeln(a,#39,a,#39#59#98#61#39,b,#39#59#10,b) end.
    Credit: Geoffrey A Swift (blimey@toke.com)
    Note: I changed write() to writeln()

    What is that?

    It's a Quine! Let me break it down piece by piece so we can better understand how it works.
    Even I at the time of writing this don't know what's exactly going on. Soon enough all shall be made clear.

    Right from the start two constants are declared,
    a:
    Simba Code:
    const a='const a=';
    and b:
    Simba Code:
    b='begin writeln(a,#39,a,#39#59#98#61#39,b,#39#59#10,b) end.';

    "a" is the "initial" part of the script and "b" is the "body+end" of the script.

    The "body+end" of the script is then actually executed on the next line with:
    Simba Code:
    begin writeln(a,#39,a,#39#59#98#61#39,b,#39#59#10,b) end.
    This outputs the constants a and b in the appropriate locations and
    any additional characters needed in between to recreate the script.
    And let's not forget the important "end." to "finalize" the code.

    For quick reference:
    39 is '
    59 is ;
    98 is b
    61 is =
    10 is new line feed

    Now what?

    Well, I guess that's it. But nothing is stopping you from attempting to make it even shorter.
    Or perhaps write your own! There are an infinite number of ways to make a Quine! Shortness isn't a requirement.
    Some people make their Quines ridiculously complex just for the heck of it, sometimes even over several programming languages.
    If you have one to share, post it below!

    Last edited by fastler; 11-30-2014 at 06:41 PM.

  2. #2
    Join Date
    Jan 2007
    Location
    East Coast, USA
    Posts
    138
    Mentioned
    0 Post(s)
    Quoted
    38 Post(s)

    Default

    I put the compact Quine onto one line, shortening the total character count by 6 (newline noninclusive):
    Simba Code:
    const a='const a=';b='begin writeln(a,#39,a,#39#59#98#61#39,b,#39#59,b) end.';begin writeln(a,#39,a,#39#59#98#61#39,b,#39#59,b) end.

    I also put it in a form using only one constant instead of two, but it's longer by 3 characters:
    Simba Code:
    const a='begin writeln(#99#111#110#115#116#32#97#61#39,a,#39#59,a) end.';begin writeln(#99#111#110#115#116#32#97#61#39,a,#39#59,a) end.
    Last edited by fastler; 11-30-2014 at 06:40 PM.

  3. #3
    Join Date
    Dec 2011
    Location
    East Coast, USA
    Posts
    4,231
    Mentioned
    112 Post(s)
    Quoted
    1869 Post(s)

    Default

    So wait, this is code that writes code?

    o_O
    GitLab projects | Simba 1.4 | Find me on IRC or Discord | ScapeRune scripts | Come play bot ScapeRune!

    <BenLand100> we're just in the transitional phase where society reclassifies guns as Badâ„¢ before everyone gets laser pistols

  4. #4
    Join Date
    Sep 2012
    Location
    Netherlands
    Posts
    2,752
    Mentioned
    193 Post(s)
    Quoted
    1468 Post(s)

    Default

    @Ashaman88; script-writer-script leak?!?!

  5. #5
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by KeepBotting View Post
    So wait, this is code that writes code?

    o_O
    Nope. It's code that prints itself. A program that prints its own source code..
    I am Ggzz..
    Hackintosher

  6. #6
    Join Date
    Dec 2011
    Posts
    2,147
    Mentioned
    221 Post(s)
    Quoted
    1068 Post(s)

    Default

    Quote Originally Posted by Brandon View Post
    Nope. It's code that prints itself. A program that prints its own source code..
    Forgive me if I'm being ignorant, but what is the purpose of this? Or is it just for sh*ts and giggles?

  7. #7
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    trol-lol-lol-lol-lol

    lol-lol-lol-LA

    Simba Code:
    function getScriptCode():string;
    var
      h:integer;
    begin
      h := openfile(scriptPath + scriptFile, true);
      readFileString(h, result, fileSize(h));
      closefile(h);
    end;

    Theoretically we could make the script run itself infinite number of times with the correct cmd arguments to run a simba script:

    Simba Code:
    function getScriptCode():string;
    var
      h:integer;
    begin
      h := openfile(scriptPath + scriptFile, true);
      readFileString(h, result, fileSize(h));
      closefile(h);
    end;

    function duplicateScript():string;
    var
      fName, fContents:string;
      fNum:integer;
    begin
      fName := toStr(random(high(int64)));
      fContents := getScriptCode();
      fNum := createFile(scriptPath + fName + '.simba');
      closeFile(fNum);
      fNum := reWriteFile(scriptPath + fName + '.simba', true);
      writeFileString(fNum, fContents);
      closeFile(fNum);
      result := scriptPath + fName + '.simba';
    end;

    begin
      openWebPage('start ' + duplicateScript + ' -run');
    end.

  8. #8
    Join Date
    Jan 2007
    Location
    East Coast, USA
    Posts
    138
    Mentioned
    0 Post(s)
    Quoted
    38 Post(s)

    Default

    Quote Originally Posted by Clarity View Post
    Forgive me if I'm being ignorant, but what is the purpose of this? Or is it just for sh*ts and giggles?
    I should probably add more than "Because" to the "Why should you care"...
    As far as I understand it's just for sh*ggles, but it's also a display of the language being Turing complete.


    Quote Originally Posted by Robert View Post
    trol-lol-lol-lol-lol

    lol-lol-lol-LA

    Simba Code:
    function getScriptCode():string;
    var
      h:integer;
    begin
      h := openfile(scriptPath + scriptFile, true);
      readFileString(h, result, fileSize(h));
      closefile(h);
    end;
    Ideally you aren't allowed to just read the code from somewhere, especially the source file.
    But if you can chop it down to an impressive shortness then it's something. ^_^
    If you were to go full troll then an empty program would be the shortest.
    By not outputting anything it has thereby outputted itself.
    I hope that doesn't spiral off into a philosophical debate on the definition of nothing.
    Last edited by fastler; 11-30-2014 at 07:04 PM.

  9. #9
    Join Date
    Nov 2014
    Posts
    104
    Mentioned
    12 Post(s)
    Quoted
    59 Post(s)

    Default

    That isn't full troll, it's just incorrect. Pretty sure a quine can't be empty. Quines are only good to learn more about the language and it can be fun trying to find the shortest one.

  10. #10
    Join Date
    Jan 2007
    Location
    East Coast, USA
    Posts
    138
    Mentioned
    0 Post(s)
    Quoted
    38 Post(s)

    Default

    Quote Originally Posted by akarigar View Post
    That isn't full troll, it's just incorrect. Pretty sure a quine can't be empty. Quines are only good to learn more about the language and it can be fun trying to find the shortest one.
    Right, it is incorrect, but that still wouldn't stop some people from jokingly postulating it as a solution.
    Very much not unlike:
    _42873205_find_x_math_203.gif

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •