As I was reading through Exegesis 4, which was very nicely done, btw, one thing did strike me as a bit odd. Maybe it's just my Ruby/Python background, but why was push() still a built-in function? It seems like this should be a method of the array, as long as arrays are going to be objects.

Maybe taking the form of:

@foo.push($bar);

or:

push @foo: $bar;

If I understand that form of method call correctly.

Replies are listed 'Best First'.
Re: An Exegesis 4 thought
by pdcawley (Hermit) on Apr 07, 2002 at 15:28 UTC
    Probably because pop and shift still need to be builtins because of their defaulting behaviour (and they don't necessarily default to the current topic either), and a language with builtin pop and shift would look very weird.

    I don't doubt that there will be standard push and unshift methods on the builtin ARRAY class though.

      Will @_ then act as the default array in Perl 6? I wasn't sure about this, given how references have thus far been described.

      Could the default behavior possibly be dealt with like the following? (assuming I'm remembering correctly that @_ is still going to be the default argument array for subrutines whse arguments haven't been otherwise specified)

      sub foo { my $bar = .shift // "some default"; my $baz = .pop // "some other default"; }

        I wonder why @_ in subs would still be needed. IIRC, you can write:

        sub foo ($bar //= "some default", $bar //= "blah") { ... }

        U28geW91IGNhbiBhbGwgcm90MTMgY
        W5kIHBhY2soKS4gQnV0IGRvIHlvdS
        ByZWNvZ25pc2UgQmFzZTY0IHdoZW4
        geW91IHNlZSBpdD8gIC0tIEp1ZXJk