in reply to The Future of Perl 5
actually reads more like:sub fibonacci (PositiveInt $n) { return 1 if $n <= 1; return fibonacci($n-1) + fibonacci($n-2); }
What I'd rather see is the ability to quickly validate, completely under my control, and completely duck-typed. For example:sub fibonacci ($n ... # Wait, wait... hold on a second! What is this $n thing you claim # to be sending me?! Is this a thing? Is it the kind of thing that # I approve of? What about my friends? Will my friends respect # this thing? Let's ask them... Hold on, now, do I trust my # friends? Maybe not. Better take some precautions... # Time for some state management in the form of eval. That's light # weight, right? # Also, now is a good time to pre-format some error messages just # in case. Okay, I think this $n thing is up to snuff, but just in # case, I'm going to do some state management. Hold on a bit... ) { return 1 if $n <= 1; return fibonacci($n-1) + fibonacci($n-2); }
Where this expands to something more or less like:sub fibonacci($n {$n >= 0 && int($n) == $n}) { return 1 if $n <= 1; return fibonacci($n-1) + fibonacci($n-2); }
I have no problem with typing as a shorthand that people can use if they want, wheresub fibonacci($n) { die '$n failed check "$n >= 0 && int($n) == $n"' unless $n >= 0 && + int($n) == $n; ... }
is equivalent tosub fibonacci(PostiveInt $n) {
But in that case, I've opted in to a potentially very expensive type construction from my potentially very simple value.sub fibonacci($n {$n = PostiveInt->new($n)}) {
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: The Future of Perl 5
by tobyink (Canon) on Aug 20, 2018 at 10:13 UTC | |
|
Re^2: The Future of Perl 5
by Anonymous Monk on Aug 19, 2018 at 15:44 UTC | |
|
Re^2: The Future of Perl 5
by raiph (Deacon) on Aug 19, 2018 at 23:10 UTC |