by LeifCarrotson · 2y ago · 0 comments
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.
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.
Huh, that's an odd failure of Perl's normal ethic of doing things that appear to make sense in context. A number should be 0 by default in additive contexts and 1 by default in multiplicative contexts.
(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.
The two languages certainly both have their terrible warts. I think in the implicit conversion gotchas, JS is actually markedly worse. Perl has polymorphic values, but somewhat typed (for its basic types) operators (eg "eq" for strings, "==" for integers). JS has both implicit value type conversions and overloaded operators. That leads to an unholy level of indeterministic mess.
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.
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.
Possible effects: People that must use Javascript, but don't want to (only choice, only framework). People that use Javascript because it's hyped or hot, not because of personal interest. Larger volume of talk, so more opportunities for griping. Much larger perception of griping (blogs, HN links, news. You almost have to work to find the Perl griping locations). The talk tends to more work issues (stuck on project, annoyed at issue), and not discussing a language you write with because you enjoy the features.
$ 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.But yes, it converts the strings to integers and divides them, as shown in the sibling comment.
With warnings, it runs, but tells you about all of the mistakes you made. With strict, it doesn't run.