Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: [Perl 6] Generalized shortcutting C<||>?

by Roy Johnson (Monsignor)
on Sep 17, 2007 at 18:32 UTC ( [id://639460]=note: print w/replies, xml ) Need Help??


in reply to [Perl 6] Generalized shortcutting C<||>?

Much belatedly, I came up with this function that I think you will find appealing.
sub cond (&$$) { (my $check, local $_, my $default) = @_; $check->() ? $_ : $default; }
Call it thus:
print cond { fileno($_} } $fh, 'undef';
It's the sort of trivial function that might be at home in List::MoreUtils.

Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^2: [Perl 6] Generalized shortcutting C<||>?
by blazar (Canon) on Sep 18, 2007 at 13:52 UTC
    Much belatedly, I came up with this function that I think you will find appealing.

    But of course! Except that as you can easily understand, I wanted something more "builtin" and more disguised as an operator, with the condition in the middle. I understand perfectly well that the general consensus does not seem to agree with my own desire so I will refrain from insisting. Most probably(*) in Perl 6 the corresponding function could be coded as a macro with the same syntax as the one I devised, so perhaps it will be interesting to test it "on the field" one day.

    (*) I'm not sure because Synopsis 6 specifies the syntax to define infix, prefix, postfix, circumfix and postcircumfix custom operators. But there does not seem to be any means to specify more generic ones, e.g. ternary ones. This may well be the subject of another thread.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://639460]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2024-04-25 11:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found