Writing exercises for SNOBOL4

I’m having some cognitive dissonance with writing the exercises because the student will write them one way but they will be executed another way with the test tool. The test tool reads the script, removes the trailing END, and then compiles it using CODE().

So the student writes a “raindrops” solution as

RAINDROPS INPUT.NUMBER = INPUT
        RESULT = EQ(REMDR(INPUT.NUMBER,3),0) RESULT "Pling"
        RESULT = EQ(REMDR(INPUT.NUMBER,5),0) RESULT "Plang"
        RESULT = EQ(REMDR(INPUT.NUMBER,7),0) RESULT "Plong"
        RESULT = IDENT(RESULT) INPUT.NUMBER
END

And that will work fine for local use. However, when test.sno reads it and compiles it, INPUT.YEAR is supplied and the INPUT statement itself would block the run. One might argue then that my “inhale” function should also remove the INPUT statement. Clues to the issue can be seen in the test.sno code:

test.17
*#17. the sound for 105 is PlingPlangPlong as it has factors 3, 5 and 7
 description = 'the sound for 105 is PlingPlangPlong as it has factors 3, 5 and 7'
 expected = 'PlingPlangPlong'
 property = 'convert'
 input.number = 105
 :<compiled>
 :(test.after)
test.17.end

At this point I’m thinking of instructing the student to comment out their INPUT before running tests. I’m not satisfied with that idea however.

Stripping it out seems incorrect because it’s not guaranteed to be in the same place. Is it possible to have more than one INPUT? That might cause issues if they are not all removed.

Knowing nothing of SNOBOL, is there a boilerplate we could add that checks if that input variable is already set by the test runner and if not sets it to whatever value we need? That makes the solution less magical and lets a student see what we’re doing. After a while, they get used to it so the cognitive load gets lower.

A few days later and I’m thinking I’ll put into each student script the declaration/s for input from the command line and include a comment to encourage commenting it/them out before testing with test.sno

E.g.

 INPUT.YEAR = INPUT
* comment out the above before testing with test.sno

INPUT.YEAR is the variable defined for leap

Unless, as you suggest,

 INPUT.YEAR = IDENT(INPUT.YEAR) INPUT
* Only reads from stdin if INPUT.YEAR hasn't already been set

which could be really quite interesting

Yeah, something like that.