-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open Questions: Readers with custom writers #13
Comments
This seems to be describing a general problem with argument handling in perl, not anything tied to Cor. While it would definitely be nice to improve the sub signature features to make this more reasonable, I wouldn't try to make it part of the Cor proposal. If you did want Cor to do something to solve this, something analogous to coercions seems like the way to do it. Another way this could be written, which is admittedly a bit weird:
This is very similar to the proposed "solution" except using perl's normal sub signature features, and not relying on a horrifying special case. |
I've never liked the method foo ($new_x = return $x, $new_y = return $y) {
...
} mst pointed out the cleanest solution and one that is generally applicable: has $foo :isa(Str); # no reader or writer
method foo(@args) {
return $foo unless @args;
...
} For now, I believe this issue is resolved. |
I've basically been going through examples of stuff that's hard in Cor, and seeing how Zydeco handles them. Has helped me catch a few bugs. Anyway, for the binary tree example on the Wiki... use v5.16;
use Data::Dumper;
package Local::App {
use Zydeco declare => ['BinaryTree'];
class BinaryTree {
method $add_child ( $value ) {
$value->parent($self);
}
has value ( is => rw, type => Value );
has left, right ( is => rw, type => BinaryTree, trigger => $add_child );
has parent ( is => rw, type => BinaryTree, weak_ref => true );
coerce from Value via promote {
$class->new( value => $_ );
}
}
}
my $btree = Local::App->new_binarytree( value => 10 );
my $left = $btree->left(3);
my $right = $btree->right(17);
$left->left(1);
$left->right(17);
print Dumper($btree); |
Please leave feedback regarding question 2 on this ticket.
The text was updated successfully, but these errors were encountered: