5 ms·
I don't get it! It is clearly written in the code, that the progam should behave this way. Is the proof, that perl is capable of this behaviour?! I don't get i
by reneberlin 5y ago
I don't get it! It is clearly written in the code, that the progam should behave this way.
Is the proof, that perl is capable of this behaviour?! I don't get it - what is the point?
I read all the comments and still don't get it. What am i missing?
- bachmeier 5y agoWas going to say the same thing. I thought it would be something wrong with the language. If you're going to write code that's different depending on the day of the week...meh.
- JohnHaugeland 5y agothey made a branch where one side is defective and the other isn't they only follow the non-defective side one day a week because perl doesn't forward analyze, it never sees the error on other days, and doesn't fail the presentation is false. this code is always wrong. it's just that the bug is only visible under certain conditions.
- wutbrodo 5y agoYou can write code in any language that fails at runtime depending on the day. What's notable about this is that its _syntactical correctness_ depends on the day, which is not possible to achieve in many languages. What's being noted is the degree of flexibility that Perl has with respect to its execution environment. Though if you include preprocessors, you expand the number of languages for which you can do something similar.
- iLoveOncall 5y agoWhat makes it "special" here is the fact that it will COMPILE only on a friday. It's not a runtime error but a compile time error. Because yes otherwise I would agree that it's doable easily in every single language.
- ghayes 5y agoBut isn’t this possible with any language that has a pre-compilation step? Perl is certainly conflating its passes (as explained by other comments above), but in rust you could add a check in build.rs or use macros in C to accomplish the same, right?
- bachmeier 5y agoHere's a D program that only fails to compile if the last digit of the current number of seconds is 4: enum timestamp = __TIMESTAMP__; void main() { pragma(msg, timestamp[$-6..$-5]); auto a = 4; static if(timestamp[$-6..$-5] == "4") { auto a = 7; } }
- high_pathetic 5y agoIsn't perl an interpreted language? Or I am missing a point? What will happen when the command is `perl -c friday.pm`?
- jwilk 5y agoYou get the same output with "perl -c". (Actually I've just updated README to use that.) Note that the error message is "friday.pm had compilation errors, so yes, there's a compilation phase. It's not compiled to the machine code, though.
- jwilk 5y agoIt's a humorous way to demonstrate that you can't parse Perl code statically.
- trissylegs 5y agoThe line f/1;#/+ is parsed differently depending on the day. On Friday it's [ "f", "/1;#/", "+" ] Other days it's parsed as [ "f", "/", "1", ";" ]. Perl is parsing /1;#/ is a regex based on whether f takes arguments. Otherwise it parses the slash as division and then the hash is a comment. Another example could be: foo() { some_func / 1;#/; die "It died" foo } Which depends on some_func to not halt. some_func could come from another file, set by whoever invokes the current file. Whatever, it's determed at runtime. This leads to a proof that perl is a actually impossible to parse. https://www.perlmonks.org/?node_id=663393 https://www.perlmonks.org/?node_id=663393 Which means you can't do a lot of static tooling on perl because you just can't analyses the source accurately. (Compared to say python, which parses source before running it)