In continuation to
I tried to hack a proof of concept for a concise OO syntaxThe basic ideas are that:
{ use Class BLA => ISA-LIST; use Data::Dump qw/pp/; my Int ($x,$y) :has :rw = (10,11); sub set_x { my ($var) = @_; #warn "set_x $$x -> $var \n"; $$x = $var; } sub print_x { print "x = $$x \n"; } sub print_self_x { print "x = $self->{x} (via \$self)\n"; } sub dump { warn '$self:',\$self; warn pp '$self: ', $self; warn pp '$$x: ', $$x; warn pp '$$y: ', $$y; } }
The implementation is done via a macro expansion from use Class which injects some boilerplate into the head of the class, which handles the creation.
Injecting is basically done via a source filter or alternatively via Keyword::Simple. NB: just injecting some code doing introspection. No parsing, regexing or modification of the code you see.
I'm supposing this concise syntax could be used as a front end for all current OO models in Perl and might help offering a stable backwards compatible syntax if it's hardcoded into the engine.
A rough proof of concept follows here:
NB: This example is pretty barebone, and not meant to be an alternative to other OO Frameworks, but rather a frontend. It doesn't create accessors and the constructor is only simplistic.
Comments?
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
FootballPerl is like chess, only without the dice
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: RFC: Concise OOP Syntax
by daxim (Curate) on Aug 05, 2019 at 09:08 UTC | |
by LanX (Saint) on Aug 05, 2019 at 09:43 UTC | |
by daxim (Curate) on Aug 05, 2019 at 10:46 UTC | |
by LanX (Saint) on Aug 05, 2019 at 12:12 UTC | |
by daxim (Curate) on Aug 05, 2019 at 18:27 UTC | |
| |
by Laurent_R (Canon) on Aug 05, 2019 at 21:45 UTC | |
by 1nickt (Canon) on Aug 05, 2019 at 12:31 UTC | |
| |
by LanX (Saint) on Aug 05, 2019 at 14:10 UTC | |
by 1nickt (Canon) on Aug 05, 2019 at 14:31 UTC | |
| |
|
Re: RFC: Concise OOP Syntax
by daxim (Curate) on Oct 21, 2019 at 12:30 UTC |