Re: shorter way to set states in -n?

2022-07-02 Thread Marc Chantreux
Ralph,

On Sat, Jul 02, 2022 at 08:27:19PM +0100, Ralph Mellor wrote:
> Does this do what you want:
>   BEGIN my (@o, @f) = 0 xx 3;
>   @o.push: "ok";
>   say @o;
> 

seq 2|raku -ne '
BEGIN my (@o, @f) = 0 xx 3;
@o.push: "ok";
say @o;
'

works fine! thank you very much.
-- 
Marc Chantreux
Direction du numérique de l'Université de Strasbourg
Pôle de Calcul et Services Avancés à la Recherche (CESAR)
http://annuaire.unistra.fr/p/20200


Re: shorter way to set states in -n?

2022-07-02 Thread Gianni Ceccarelli
On 2022-07-02 Marc Chantreux  wrote:
> AFAIK about raku -n, I need 2 lines to setup a
> state with a default value
> 
>   seq 2| raku -ne '
>   state (@o, @f);
>   BEGIN @o = 0 xx 3;
>   @o.push: "ok";
>   say @o;
>   '
> 
> but is there a shorter way ?

Something feels wrong to me… From the documentation, the equivalent
perl switch, and what I can see from the Rakudo source, `raku -ne
$something` should be the same as `raku -e "for lines -> $_ is copy {
$something }"`

but while this does what I expect:

seq 2|raku -e 'for lines() -> $_ is copy {
 state @x=; @x.push($_); say @x
  }'
[a b c 1]
[a b c 1 2]

this doesn't (as you noticed):

seq 2|raku -ne 'state @x=;@x.push($_);say @x'
[1]
[1 2]

Is this a bug, or are my (our?) expectations wrong?

-- 
Dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88



Re: shorter way to set states in -n?

2022-07-02 Thread Ralph Mellor
On Sat, Jul 2, 2022 at 5:26 PM Marc Chantreux  wrote:
>
> AFAIK about raku -n, I need 2 lines to setup a state with a default value

Does this do what you want:

BEGIN my (@o, @f) = 0 xx 3;
@o.push: "ok";
say @o;

?

love, raiph


shorter way to set states in -n?

2022-07-02 Thread Marc Chantreux


hello rakoons,

AFAIK about raku -n, I need 2 lines to setup a
state with a default value

seq 2| raku -ne '
state (@o, @f);
BEGIN @o = 0 xx 3;
@o.push: "ok";
say @o;
'

but is there a shorter way ?

regards,
marc