You should use loop for multiple iterations of addition. GOTO statement and labels can be used to design a loop of your requirement. please give me some ideas.
Asked
Active
Viewed 201 times
-3
-
I'm voting to close this question as off-topic because it's a zero-effort requirements dump. – EJoshuaS - Stand with Ukraine Aug 31 '17 at 05:06
2 Answers
2
I think it's not really Snobol if it doesn't contain a pattern match...
This solution generates the even numbers 000 .. 100
by matching a pattern against the string "01012345678902468"
and adding the generated numbers through the function add()
. Looping is done through the FAIL
keyword at the end of the pattern, which forces the pattern scanning to continue looking for alternatives until the expression (*EQ(h t o,100) ABORT)
causes the scanning to abort.
&FULLSCAN = 1
DEFINE('add(x)') :(add.End);add sum = sum + x :(RETURN);add.End
"01012345678902468" (LEN(1) $ h *LEN(1 - h)) ARB (LEN(1) $ t
. *LEN(9 - t)) ARB LEN(1) $ o *add(h t o)
. (*EQ(h t o,100) ABORT) FAIL
OUTPUT = sum
END
Works both in Snobol and Spitbol (&FULLSCAN = 1
is needed for Snobol, it's a no-op in Spitbol)

zberd
- 21
- 1
- 4
-
And in all honesty, I really enjoyed writing this solution, but it's also really convoluted. So the solution Eben posted is better if "written in Snobol" is all you need. – zberd Apr 21 '17 at 07:17
1
*This works on the Spitbol version of Snobol.
loop m = le(n, 98) (n = n + 2) + m :s(loop); output = m ;end

Eben
- 11
- 1