I just signed up & submitted the following solution to the very first problem (LIfe, the universe & everything):

(do
  ((i (read) (read)))
  ((= i 42) '())
  (begin
    (display i)
    (newline)))

This works fine if I run it in Chicken Scheme on my own machine, but it is rejected as incorrect by spoj. If I look at the details of the submission, it seems to think that it doesn't stop when 42 is entered. I tried changing the code to:

(do
  ((i (read) (read)))
  ((= i 42) (quit))
  (begin
    (display i)
    (newline)))

in case the interpreter wasn't exiting (and the REPL was continuing to evaluate input as displayable atoms or something?) but this doesn't seem to help.

I had hoped to use spoj to improve my Scheme programming, but this isn't the best start!

Does anybody have any ideas as to what I might be doing wrong?

  • created

    Aug '17
  • last reply

    Aug '17
  • 1

    reply

  • 984

    views

  • 1

    user

8 days later

The following works:

(begin
  (do
    ((i (read) (read)))
    ((= i 42) '())
    (begin
      (display i)
      (newline)))
  (quit))

Indicating that the interpreter continues to run after the number 42 is encountered. I wonder if this is sensible default behaviour? I think it would be best to run the submitted code as a "script". With Chicken scheme this would be achieved by running

csi -s input.scm

This way, the interpreter would quit as expected.