4 ms·
I enjoyed footnote 5: ⁵ This feature does enable a neat quine: the Perl program “Illegal division by zero at /tmp/quine.pl line 1.”, when saved in the appropri
by interroboink 2y ago
I enjoyed footnote 5:
⁵ This feature does enable a neat quine: the Perl program “Illegal division by zero at /tmp/quine.pl line 1.”, when saved in the appropriate location, outputs “Illegal division by zero at /tmp/quine.pl line 1.” The reason for this behavior is left as an exercise for the reader.
- deleted 2y ago[deleted]
- LeifCarrotson 2y agoCan you help out a reader who does not know any Perl? I tried it in the REPL and found that "Illegal division" can't locate method "illegal" in package "division", so presumably that gets ignored, same with method "by" in package "zero", and that "at /tmp" is the simplest version of the string that produces the error message, which apparently is more severe than the missing package warnings and terminates the program? I'd guess the / is the operator for division, and the "tmp" is getting initialized as a variable and coerced into an integer? But "/tmp" doesn't do it, and "/tmp/" does something with regex, so I'm not sure why the parser would split it there.
- hoytech 2y agoEasiest way is to Deparse it: $ perl -MO=Deparse tp.pl 'division'->Illegal('zero'->by('at' / 'tmp' / 'quine' . 'line'->pl(1))); tp.pl syntax OK So I believe this is what causes it (note that "at" and "tmp" and such are "barewords"): $ perl -e 'at / tmp' Illegal division by zero at -e line 1.
- interroboink 2y agoThe footnote is originally referenced here: Figure 6 represents the string “gggijgziifiiffif”, which by pure coincidence happens to accurately represent the authors’ verbal reaction upon learning that “unquoted strings” were a feature intentionally included in the Perl language.⁵ So, the hint is that this has to do with the "unquoted strings" feature (aka "bare words"[1]). See the sibling comment about the actual parse — "at" and "tmp" are seen as strings. The strings get coerced into numbers due to being used with the numeric "/" operator (that's normal Perl behavor). Since the strings can't be parsed as numbers, they become "0". So, you get division by 0. [1] https://perlmaven.com/barewords-in-perl https://perlmaven.com/barewords-in-perl
- andai 2y agoNon Perl user here: why do people love Perl but hate JS? I imagine Perl had a lot more thought put into it (than JS's 10 days), but this kind of implicit conversion sounds like exactly the kind of thing that bites me in the ass constantly in JS land. (Actually, implicit unquoted strings sound so nightmarish it's comical, but let's do one question at a time...) I used to think the solution was static typing, but then I found none of the same infuriating bugs in Python, which has dynamic but strong typing, forcing you to be explicit about type conversions. Edit: I think I've hit the nesting limit, so please reply to parent comment and I will find it.
- TheDauthi 2y agoWhen using Perl you should `use strict; use warnings;` and you have something approaching a real language with a lot fewer warts, in which said quine is not a valid program. It isn't the default because Perl people have an obsession about not breaking backwards compatibility. I think the people that love perl love its expressiveness. It has a little bit of functional programming here, and a system for making an object-oriented language, and all of these handy tools and you choose which ones you need or find most readable. I've heard Ruby called a better Perl, and - as someone whose day job is largely those two things - that's completely fair.
- smueller1234 2y agoMany moons ago, I made a case for making strict mode the default in Perl. We settled on the current backwards compatibility compromise, which is that breaking changes are hidden behind a minimum version toggle: Eg. putting "use v5.14.0;" or similar on top of your file (or compilation unit/scope) will indeed turn on strict mode for you, along with adding a number of features as well. At the time, also auto-toggling warnings was considered unacceptable because technically, using the warnings pragma anywhere had some edge case action at a distance. This has been remedied in some later release after I wasn't involved in the language development anymore, and from some more recent version, warnings are also part of the standard import. I imagine you (TheDauthi) already know that, though.
- 2y ago
- kqr 2y agoIt might be when you run Perl with no qualifier you get a recent version of Perl which turns on strict warnings for you, and (rightly) warns about undefined words instead of quietly trying to evaluate them anyway. But yes, it converts the strings to integers and divides them, as shown in the sibling comment.
- TheDauthi 2y agoBy default, even on a recent perl it'll act like you're on a really old perl and run just fine. With warnings, it runs, but tells you about all of the mistakes you made. With strict, it doesn't run.
- fanf2 2y agoI wrote a blog post to explain it at https://dotat.at/@/2019-04-04-a-curious-perl-quine.html https://dotat.at/@/2019-04-04-a-curious-perl-quine.html And also a superficially-related but actually rather different Python quine: File "quine.py", line 1 File "quine.py", line 1 ^ IndentationError: unexpected indent
- teaearlgraycold 2y agoYou can do this with Python as well for indentation errors