Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

comment on

( #3333=superdoc: 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 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.

In reply to Re^2: My problems to understand the Perl documentation [updated] by bojinlund
in thread My problems to understand the Perl documentation by bojinlund

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2022-05-26 02:12 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (92 votes). Check out past polls.