RosettaCodeData/Task/A+B/Onyx/a+b.onyx
2023-07-01 13:44:08 -04:00

25 lines
650 B
Text

$Prompt {
`\nEnter two numbers between -1000 and +1000,\nseparated by a space: ' print flush
} def
$GetNumbers {
mark stdin readline pop # Reads input as a string. Pop gets rid of false.
cvx eval # Convert string to integers.
} def
$CheckRange { # (n1 n2 -- bool)
dup -1000 ge exch 1000 le and
} def
$CheckInput {
counttomark 2 ne
{`You have to enter exactly two numbers.\n' print flush quit} if
2 ndup CheckRange exch CheckRange and not
{`The numbers have to be between -1000 and +1000.\n' print flush quit} if
} def
$Answer {
add cvs `The sum is ' exch cat `.\n' cat print flush
} def
Prompt GetNumbers CheckInput Answer