Front page | perl.perl6.language |
Postings from August 2001
if3 as canonical macro
Thread Previous
|
Thread Next
From:
David L. Nicol
Date:
August 1, 2001 12:36
Subject:
if3 as canonical macro
Message ID:
3B685826.4268389C@kasey.umkc.edu
> > sub if3 ($&&&) {
> > return &{$_[1]} unless $_[0];
> > return &{$_[2]} if $_[0] < 0;
> > return &{$_[3]};
> > }
> >
> > gives the functionality.
How about allowing a scheme-style macro specifier:
macro if3 ($&&&) {
return &{$_[1]} unless $_[0];
return &{$_[2]} if $_[0] < 0;
return &{$_[3]};
}
So, it gets inline-expanded instead of called. Then
it might be (with a -1, 0, +1 selection order)
macro if3 ($&&&) { $_[0] ? ( $_[0] < 0 ? &$[1] : &$[3] ) : &$[2] }
I think it would be a really good example of a macro, for the documentaion
of macros, or inlined subroutines (in the C++ inline sense, not the
Inline.pm
sense), or whatever they might get called.
Or maybe the internals might replace all one-expression subs in place
instead of calling them, which could be abused by wrapping the whole
subroutined body in a do or an eval.
--
David Nicol 816.235.1187
"Straight from the docs" doesn't mean "you can cut-and-paste" - it
just means you find the principle explained clearly - without
having to construct it from smaller blocks. -- Abigail
Thread Previous
|
Thread Next