develooper Front page | perl.perl6.users | Postings from July 2022

Re: shorter way to set states in -n?

Thread Previous | Thread Next
From:
Gianni Ceccarelli
Date:
July 2, 2022 20:10
Subject:
Re: shorter way to set states in -n?
Message ID:
20220702211005.3b927923@thenautilus.net
On 2022-07-02 Marc Chantreux <mc@unistra.fr> 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=<a b c>; @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=<a b c>;@x.push($_);say @x'
    [1]
    [1 2]

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

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


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