in reply to Re^8: why doesn't "my ($a,$b)" return a list?
in thread why doesn't "my ($a,$b)" return a list?

Well, you started claiming an analogy between builtin functions and named operators. :)

"builtin function" is another name for "named operator". No analogy was made between the two.

I understand your point even less.

Already the fact that you can assign a list, i.e. my(LIST)=LIST is beyond the normal patterns of lvalue sub

How would changing my affect that statement?

I don't understand this point either.

An operator working on lists of variables having a special behavior in scalar context is IMHO strange!

No operator or builtin or sub can return more than value in scalar context. It simply makes no sense. The only reason you're in scalar context is because what will receive the value cannot handle more than one value.

map, sort, grep, reverse, and more all work on lists and behave specially in scalar context. What about keys, values, split, splice, m//g, s///g, and more whose primarily purpose is to return a list? They all return something else in scalar context.

I don't see what you find strange.

Replies are listed 'Best First'.
Re^10: why doesn't "my ($a,$b)" return a list?
by LanX (Saint) on Aug 19, 2010 at 21:30 UTC
    in my world "eq" is a named operator and "grep" is a CORE function.

    maybe "my" is something else, for me it belongs in the same class as "sub", but I don't know about the correct terminology. Keyword? ¹)

    Taking into consideration that even "," is an operator I choosed the word operator.

    Cheers Rolf

    1) perlsyn uses the term "statement".

      Funny you should pick grep as your example of a function because there is no grep function anywhere. It's gets compiled into the grepstart and grepwhile opcodes. You'll find that none of the named operators are compiled into function calls. They are typically compiled into opcodes which the same name as the function or operator.

      $ perl -MO=Concise,-exec -e'time();' 1 <0> enter 2 <;> nextstate(main 1 -e:1) v:{ 3 <0> time[t1] v 4 <@> leave[1 ref] vKP/REFC -e syntax OK

      As a function call, it would look like:

      $ perl -MO=Concise,-exec -e'timex();' 1 <0> enter 2 <;> nextstate(main 1 -e:1) v:{ 3 <0> pushmark s 4 <$> gv(*timex) s/EARLYCV 5 <1> entersub[t1] vKS/TARG,1 6 <@> leave[1 ref] vKP/REFC -e syntax OK

      The point is that there's really no difference between grep, eq and the rest of perlfunc and perlop except for perceived differences. There's a set you perceive as functions, and that's exactly what I said earlier.

      maybe "my" is something else, for me it belongs in the same class as "sub",

      Well, I was saying that when my looks like a function, you shouldn't be surprised that my acts like a function. sub doesn't really look like a function.

      I don't know what this class is you are defining, nor how it relates to this conversation.

      Keyword?

      Yes, "my" is a keyword. It's quite a vague description, though.

      perlsyn uses the term "statement".

      While my $x would be a statement, my is not a statement itself.

        I thought by mentioning "builtin-functions" and "CORE" it's obvious that there is a possibility to overwrite &CORE::grep but none for &CORE::my, since they belong to completely different concepts.

        It doesn't matter if the implementation is done by special opcodes, the concept and purpose is important.

        Cheers Rolf