3 ms·
Well, ok -- I guess (after a bit more googling) I see what you mean: http://www.catalyzed.org/2009/05/dawn-of-a-new-age-in-perl-how-develdeclare-extends-perls-
by e12e 14y ago
Well, ok -- I guess (after a bit more googling) I see what you mean:
http://www.catalyzed.org/2009/05/dawn-of-a-new-age-in-perl-how-develdeclare-extends-perls-syntax.html http://www.catalyzed.org/2009/05/dawn-of-a-new-age-in-perl-h...
Now, while power obviously is power -- I don't see many immediate uses for that, that can't be done better within in python via magic methods etc.
But in case others are interested, here's a couple of links I also came across:
http://stackoverflow.com/questions/214881/can-you-add-new-statements-to-pythons-syntax http://stackoverflow.com/questions/214881/can-you-add-new-st...
http://eli.thegreenplace.net/2010/06/30/python-internals-adding-a-new-statement-to-python/ http://eli.thegreenplace.net/2010/06/30/python-internals-add...
(Most definitely in the "don't do that"-category from a python point of view :)
If this (writing a new language) is really what you want, you would probably be better off playing with pypy and its restricted python, though:
https://bitbucket.org/brownan/pypy-tutorial/src/8cfb3cd72515/tutorial.rst https://bitbucket.org/brownan/pypy-tutorial/src/8cfb3cd72515...
(Tutorial for writing your own interpreter with rpython)
https://bitbucket.org/cfbolz/pyrolog/src/aa127d31df0c/prolog/doc.txt https://bitbucket.org/cfbolz/pyrolog/src/aa127d31df0c/prolog...
Working implementation of Prolog, built with pypy/rpython
- ironcamel 14y agoThe python example you linked to http://eli.thegreenplace.net/2010/06/30/python-internals-adding-a-new-statement-to-python/ http://eli.thegreenplace.net/2010/06/30/python-internals-add..., which shows an example of adding an 'until' keyword, requires you to recompile the python interpreter. From your article: "After making all the changes and running make, we can run the newly compiled Python and try our new until statement". Of course you can extend any language by recompiling it and creating a new interpreter. That is exactly my point! Perl lets you achieve the same thing simply by using a module from CPAN. I don't think you have been paying attention to what I have been saying. You keep mentioning that python has strong meta-programming. I never said anything about meta-programming. Perl, python, ruby, everybody can do meta-programming. I said that Perl lets you easily modify the core language grammar via 3rd party modules. This is an extremely powerful feature, if you took a second to think about it.
- e12e 14y agoYes, I should have been clearer in my previous comment: What I meant to say was that I see what the previous poster meant, and I was wrong. However, if someone wants to do something similar in Python, here are how you would (have) to do it. I didn't mean to say that it was the same - or as straightforward. This is also why I linked to the r(estricted)python examples with pypy -- because they give you more of the power to define a whole language -- but that also isn't the same as being able to do it within the language itself. As for meta-programming, I have always meant that in the sense of lisp macros, not simply chaining some cleverly named functions. I'm still not convinced it's a feature I would want in Perl -- but then again, I don't particularly like Perl, and I don't use it -- so clearly what I think of it doesn't matter: I'm not the target audience for Perl features. Thankfully we don't all prefer the same tools :-)
- ironcamel 14y agoYou had asked for some examples of Perl modules that extend the core language. As was stated by @knighthacker, MooseX::Declare and Test::Class::Sugar are excellent examples: https://metacpan.org/module/MooseX::Declare https://metacpan.org/module/MooseX::Declare https://metacpan.org/module/Test::Class::Sugar https://metacpan.org/module/Test::Class::Sugar Just look at the SYNOPSIS section for example code. If you know some Perl, you will notice that the code would normally not be valid syntax. Yet simply by using a module, you can define classes (MooseX::Declare) or describe tests (Test::Class::Sugar) in a brand new way.