I currently am working on https://github.com/roc-lang/roc/issues/7089 and have this working correctly. I just wanted to make sure this (non-sensical) program is doing what it should.
app [main!] {
pl: platform "../../basic-cli/platform/main.roc",
}
import pl.Stdout
import pl.Stdin
import pl.Stderr
main! = \_args ->
tick! {}
tick! = \{} ->
try Stdout.write! "Enter a number: "
when Stdin.line! {} is
Ok str ->
num =
Str.toU8 str ?? 255
|> addOne
try Stdout.line! "Did you write $(Num.toStr num) (Y/n)"
when Stdin.line! {} is
Ok "n" -> Ok {}
Ok _ -> tick! {}
Err _ -> Err Done
Err EndOfFile ->
try Stderr.line! "EOF"
Err Done
Err (StdinErr _) ->
try Stderr.line! "Couldn't read from stdin"
Err Done
addOne = \n ->
dbg { n }
if n == 255 then
255
else
n + 1
Here it will only actually get it right if you happen to type exactly 255 because the ??
has stronger precedence that |>
. Does everyone else expect that that would be the case?
And given that it is, what are all the places I need to look at to add tests around it?
https://github.com/roc-lang/roc/pull/7406 is the PR
that's the behavior I would expect!
as an aside for the future, this is the first short-circuiting operator implementation we have, so it would be awesome to follow up with changing over &&
and ||
to short-circuit as well, per #beginners > Short-circuit on boolean operations
That makes sense. So just desugar these like
idx > 32 && idx + 1 < 79
becomes
if idx > 32 then
idx + 1 < 79
else
Bool.false
and
idx > 32 || idx + 1 < 79
becomes
if idx > 32 then
Bool.true
else
idx + 1 < 79
?
yeah exactly!
Last updated: Jul 06 2025 at 12:14 UTC