Hacker News new | past | comments | ask | show | jobs | submit login

Actually Perl 5 does have compile-time macros. First you can implement them with source filtering. See http://search.cpan.org/~smueller/Filter-Simple-0.84/lib/Filt... for an example to make that easier. That is how Switch was implemented by Damian Conway before it got pulled into the core. But you can also do them without source filtering using http://search.cpan.org/~flora/Devel-Declare-0.005011/lib/Dev.... For an example of how much that can change the language, look at http://search.cpan.org/dist/MooseX-Declare/lib/MooseX/Declar....

That said, my point about Perl seems to have been unclear. I'm not saying that Perl has a reputation for ugliness because people change the syntax on the fly. I'm saying that layering macros in Perl is problematic because they interact badly with the syntax.

This is why wise Perl programmers avoid source filters and modules that use source filters. Experience has shown that they are very fragile, and don't play well together when you start stacking them. (I'm guessing that fragility is one of the reasons why http://search.cpan.org/~elizabeth/ifdef-0.07/lib/ifdef.pm limited itself to stuff embedded in POD.) Unfortunately some things can't be done in Perl without core support or source filters. For example it wasn't until Switch.pm was pulled into the core that it could be done without source filters.




"For example it wasn't until Switch.pm was pulled into the core that it could be done without source filters."

Not true, actually - it could comfortably be done with Devel::Declare - we just haven't had time to yet.

(I wrote Devel::Declare and in fact have been trying for about a year to persuade somebody to write me the smartmatch logic for perl5 v8 with a promise that I'll do the given/when syntax if somebody does ...)

Source filters fail because they're line-by-line; Devel::Declare is still effectively a filter in some respects but it's one that co-operates with the tokenizer so it tends not to interact badly with anything. If you've seen places it does, failing tests would be very welcome.


I stand corrected.


That said, my point about Perl seems to have been unclear. I'm not saying that Perl has a reputation for ugliness because people change the syntax on the fly. I'm saying that layering macros in Perl is problematic because they interact badly with the syntax.

Ah, very good point, and well explained :) sorry for underestimating your first iteration.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: