develooper Front page | perl.perl5.porters | Postings from August 2022

Re: Pre-RFC: A Metaprogramming (Reflection and Introspection) API

Thread Previous | Thread Next
From:
Branislav Zahradník
Date:
August 30, 2022 21:34
Subject:
Re: Pre-RFC: A Metaprogramming (Reflection and Introspection) API
Message ID:
CAB=rbOnVvvVQAjHgM+jGN78S7WKECy+8yZktmXgxLG+94NrqNw@mail.gmail.com
>
> Don't forget though that defaults come from expressions, not mere
> values.
>
>   sub f($x, $y = lc($x), $z = substr($y, 0, 5)) { ... }
>
> Here, it would be easy to say that:
>
>   * min arity is 1
>   * max arity is 3
>   * parameter names are qw( $x $y $z )
>
> but there isn't a simple representation for the defaults.
>
>
you can provide it as a list of parameter descriptions, in this case
[
  {
    name => 'x',
    sigil => '$',
    positional => true,
    required => true,
  },
  {
    name => 'y',
    sigil => '$',
    positional => true,
    required => false,
    default => true,
  },
  {
    name => 'z',
    sigil => '$',
    positional => true,
    required => false,
    default => true,
  }
]

in case of slurpy argument:
  sigil => '@'
or
  sigil => '%'

Best regards,
Brano

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About