Settings

Theme

A Quine in Fortran 90

medium.com

23 points by orph4nus 10 years ago · 13 comments

Reader

emson 10 years ago

Great, every language needs a Quine. Here's one we created in Elixir: http://elixirgolf.com/articles/elixir-quine-self-replicating...

randlet 10 years ago

Enjoyed the article. It made me pine for the days when I had time to dedicate a day to just play with code.

verandaguy 10 years ago

I may be missing something, but isn't a quine trivial when you use a language that allows for file I/O (which I believe Fortran does have)? Or is the point of the "challenge" to avoid using file I/O?

  • orph4nusOP 10 years ago

    I could be wrong, as I only learned about the concept of a quine recently. But the way I understand it, it is good enough to simply output it. I suppose you could write to a file as well, but where would you write to? The wikipedia page for a quine has a lot of examples and all of them seem to simply output to stdout, just as I did. I don't think the challenge talks at any point about I/O, so I do think you can use it if you would want to.

    • verandaguy 10 years ago

      I didn't mean that you could output to a file -- I meant that, knowing the name of the file the program is saved to (which is possible using facilities available in many modern languages, not sure about Fortran), you can ingest that file and print out its contents (to STDOUT for example).

      It feels like cheating, but it's also probably the easiest way to get a true quine which'll always work even if you modify parts of the code (while retaining the part of the program which ingests and prints out the file's contents).

      • pmav 10 years ago
      • gliese1337 10 years ago

        Many years ago, I attempted to cheat this way when writing a JScript quine- but it didn't work because the Windows Scripting Host keeps the source file open while interpreting it, which meant the script couldn't open its own source file because the file was already open in another program!

        A proper quine, though, doesn't require input.

        • orph4nusOP 10 years ago

          A multiquine does require you to give input in order to determine what language to output. Although it will output the current file if no input is giving. More info @ https://en.wikipedia.org/wiki/Quine_(computing)#Multiquines

          • gliese1337 10 years ago

            The definition of a multiquine specifically disallows passing in source code as input, though. The input to a multiquine is strictly for selecting which sub-quine to run, or which output set to calculate, and is not used in any way to influence the calculation of the selected output.

      • randlet 10 years ago

            #!/usr/bin/env python2.7
            print open(__file__, 'r').read()
            
        
        Seems like cheating!
ISISIS 10 years ago

print "(2a, 2('2459093414108622880,2821560280312525352,3180149544576887847,1684956475', a))",2459093414108622880,2821560280312525352,3180149544576887847,1684956475;end

mkj 10 years ago

I suppose string handling isn't Fortran's strong point!

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection