On Thu, 2002-04-11 at 11:55, Aaron Sherman wrote:

> 1. The first default marks the beginning of optional parameters.
> 2. An optional parameter with no default will automatically default to
> undef.

Interestingly, I just said something that I did not mean to, but it
opens up an interesting avenue. As I understand it, right now we have:

        sub foo ($a;$b, $c) { ... }

Which indicates taht $b and $c are optional.

If we go with the above defaulting rules, we could dump the semi-colon
(to be re-used for something else?) in favor of:

        sub foo ($a, $b=undef, $c) { ... }

Slightly longer, but a unifying syntax between defaulting and optional
parameters!

Speaking of defaults, has anyone talked about C++'s instance variable
defaults? I don't like thier system, but the case of:

        const myobj foo(1,2,3); // C++

Is a tough one. As I understand it, in Perl that's:

        my $foo = myobj.new(1,2,3) but const;

Or is that

        my $foo is myobj(1,2,3) but const;

Either way, is the constructor allowed to manipulate the embryonic $foo?

For those who don't know, in C++ this is resolved by the following
syntax:

        class myobj {
                ...
                int a,b,c;
                myobj(int aa, int bb, int cc) :
                        a(aa), b(bb), c(cc) const {}
                ...
        };

Notice that the constructor itself does nothing to this "const instance"
that is being contstructed by the instance variable defaults.

It's a fine syntactical line, and I don't like how much the compiler has
to think about what C<a(aa)> really means. But, I have to admit I'm at a
loss for other ways to allow safe compilation of const instantiations.


Reply via email to