-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: Allow state
-declared variables to be instantiated/initialized to non-zero signed integers
#458
Comments
Definitely seems like a bug to me. For an input file with several lines, this works:
You get a countdown, 10 9 8 7 6. But using state doesn't behave as expected:
|
Hi @jubilatious1! Happy holidays. :) This is a dupe of a previously reported bug. So:
|
Hi @raiph and Happy Holidays to you as well. I did a search for Regardless, I note with interest @raydiak shows This problem-solving issue demonstrates the usefulness of I'll review the Issues you reference. Thx. |
REFERENCE:
https://docs.raku.org/syntax/state
Presently,
state
-declared variables can be instantiated within blocks and-ne
/-pe
one-liners. They provide a way of initializing a variable within a block only once, for easier readability, etc. Here's a typical usage:Count number of lines with length condition
REQUEST:
What would be really nice would being able to initialize the
state
-declared value to a signed integer. Let's say you want to count the days remaining until the end of the month. You instantiate astate
-declared and initialize it to the total number of days in the month (e.g.state $December = 31
, and then$December--
until New Year's Eve:Of course, the above doesn't work and all lines get read to the bitter end, regardless of the
$Dec
counter. This is because presently the$Dec
state variable is initialized to0
zero. To get the code to work I need to writelast if $Dec == -31;
. This means the the output looks odd (and also the code, if you've initialized the variable tostate $Dec = 31
):I hope this Feature Request is adequately described. Thank you for your consideration.
The text was updated successfully, but these errors were encountered: