Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: My problems to understand the Perl documentation [updated]

by bojinlund (Prior)
on Sep 02, 2020 at 07:35 UTC ( #11121277=note: print w/replies, xml ) Need Help??


in reply to Re: My problems to understand the Perl documentation [updated]
in thread My problems to understand the Perl documentation

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 documentation

Here follows a number of rough drafts to changes.

Passing of arguments and return values

This 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.

  • One single flat list of scalars
  • 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 … ?.

  • Argument processed after each other
  • 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 split

Proposals 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.

Replies are listed 'Best First'.
Re^3: My problems to understand the Perl documentation [updated]
by choroba (Archbishop) on Sep 02, 2020 at 08:23 UTC
    I would reword "the call of the subroutine definition" - the definition isn't called, the definition is parsed and compiled to ops, and then this compiled thing is called. But as a non-native speaker of English, I don't dare to guess how to formulate that to make it easy to understand for newcomers.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
      I have the same problem!
Re^3: My problems to understand the Perl documentation [updated]
by Anonymous Monk on Sep 02, 2020 at 08:00 UTC
    Icky. Examples beat words

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11121277]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2022-01-19 15:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (55 votes). Check out past polls.

    Notices?