Keep It Simple, Stupid | |
PerlMonks |
Re^2: My problems to understand the Perl documentation [updated]by bojinlund (Monsignor) |
on Sep 02, 2020 at 07:35 UTC ( [id://11121277]=note: print w/replies, xml ) | Need Help?? |
Sorry for taking so long time to create this post, but I needed some time to read and think.
Monks thank you for your answers, they have been helpful.
The goal you seem to have is to define Perl in Lisp'ish way, where everything can be derived from a small set of axioms. No, I just want to understand the documentation, and hopefully help others to do the same. This Re: My problems to understand the Perl documentation [updated] help me realize that I had missed Slices in scalar context return the last item of the slice. from perldata Split is an operator (op)
From perlfunc, which is a list of Perl builtin functions. Split is in this list.
The functions in this section can serve as terms in an expression. They fall into two major categories: list operators and named unary operators. From perlinterp : “An op is a fundamental operation that Perl can perform: all the built-in functions and operators are ops” From token.c in perl.git: case KEY_split: LOP(OP_SPLIT,XTERM);/ From pp.c in perl.git: This file contains general pp ("push/pop") functions that execute the opcodes that make up a perl program. A typical pp function expects to find its arguments on the stack, and usually pushes its results onto the stack, hence the 'pp' terminology.PP(pp_split) { … } implements split. The de-parse of sub { split} does not show any subroutine call. Ideas to changes to the documentationHere follows a number of rough drafts to changes.Passing of arguments and return valuesThis from perlsub is only one case: The Perl model for function call and return values is simple: all functions are passed as parameters one single flat list of scalars, and all functions likewise return to their caller one single flat list of scalars. Any arrays or hashes in these call and return lists will collapse, losing their identities--but you may always use pass-by-reference instead to avoid this. Both call and return lists may contain as many or as few scalar elements as you'd like. (Often a function without an explicit return statement is called a subroutine, but there's really no difference from Perl's perspective.) It only applies to Perl subs without Prototype or Signature. (I was mislead that it applied to any function.) Proposals to replace the quoted text above with: The arguments and return values are transferred using the argument stack. The subroutine arguments in the script source code is processed (evaluated), to store them on the argument stack. This is done before the call of the subroutine definition. Perl has two ways of processing the arguments before calling a function.
The arguments are passed as a single flat list of scalar values. Any arrays or hashes are collapsed and they are losing their identities. But you may always use pass-by-reference instead to avoid this. This method is used for subroutines without a prototype. It is also used for any subroutine called with an & and … ?. The arguments are separated by the commas in the source code. The arguments are processed one after each other. The processing is done in either scalar or list context. This method is used for subroutines with a prototype. The prototype defines which context is used. It is also used for built-in functions described in perlfunc. Proposals to add this before A return statement may : The return value is a flat list of scalar values, if the subroutine is called in list context and single one in scalar context. To avoid flattening of arrays or hashes you must use pass-by-reference. Documentation of splitProposals to add this in the beginning of split Split is a built-in function (implemented in the Perl interpreter and not as a Perl sub). The arguments are processed consecutively and in scalar context. The result of the processing of /PATTERN/ is a compiled regular expression. It is later used to match the separators. If LIMIT is one it is not used.
In Section
Meditations
|
|