in reply to Re: A subroutine is a reference to a list of statements
in thread A subroutine is a reference to a list of statements

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.

Replies are listed 'Best First'.
Re: Re: Re: A subroutine is a reference to a list of statements
by japhy (Canon) on Sep 09, 2001 at 22:49 UTC
    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:??;

Re: Re: Re: A subroutine is a reference to a list of statements
by premchai21 (Curate) on Sep 09, 2001 at 23:12 UTC
    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.
Re: Re: Re: A subroutine is a reference to a list of statements
by ariels (Curate) on Sep 10, 2001 at 12:26 UTC
    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.