in reply to A subroutine is a reference to a list of statements

Note: in <code> tags, you don't need to do any &-escaping.

If the &foo syntax goes the way of the dodo (for calling functions) in Perl 6, then I do think a viable method of assigning code to a function would be something like:

&add = sub { ... };
I'm not sure I agree with the syntax you've proposed. A list is a very specific thing in Perl, and I wouldn't call a subroutine a list of statements. A block is a connected series of statements, and a subroutine is a block with benefits.

_____________________________________________________
Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Replies are listed 'Best First'.
Re: Re: A subroutine is a reference to a list of statements
by princepawn (Parson) on Sep 09, 2001 at 22:45 UTC
    But what if you wanted to manipulate a subroutine like a list? And push and pop statements from it? And splice things, etc and so forth.

    The sub word is un-necessary. Just think, do we have to do:

    $x = scalar 5;
    No, the onl time we needscalar is when we are forcing something else into scalar context.
      If you want to treat a subroutine as a list, that's fundamentally different from how most languages treat them. You'd have to create an array of statements and modify that array, and evaluate the entire array.

      _____________________________________________________
      Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
      s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

      I think that a better way to do this might be the way that (AFAIK) has been proposed for Perl 6: runtime syntax tree modification. So...
      &hello = sub { print "Hello, " }; &hello.syntree[0][1] .= "world!\n"; hello(); # prints "Hello, world!"
      ... or some such thing.
      Unfortunately, Perl's syntactic texture is more than just a list of words. To make meaningful code changes, you need to work on the parse tree.

      You could take a look at HP's RPL ("Reverse Polish Lisp"), which does things this way (it mimics Forth, where subs are (almost) nothing more than lists of words. Available on any of their programmable calculators, at least since the HP-41 (I think), and including the HP-48 and HP-49 series.