cond-expand missing from the default R7RS environment

Create issue
Issue #264 resolved
Lassi Kortela created an issue

Hi and thank you for a very nice Scheme implementation!

Would it be possible to add cond-expand to the sagittarius -r 7 default environment? Currently the following happens:

$ echo '(cond-expand (sagittarius 1))' >test.scm
$ sagittarius test.scm
$ sagittarius -r 7 test.scm
Unhandled exception
  Condition components:
  1. &undefined
  2. &who sagittarius
  3. &message unbound variable sagittarius in library user
  4. &stack-trace

stack trace:
  [1] #f
    src: (sagittarius 1)
    "test.scm":1
  [2] eval
  [3] main-loop
  [4] dynamic-wind
  [5] scriptvi

cond-expand can be imported from (scheme base) but having it without (scheme base) would be useful for compatibility with non-native-R7RS Scheme implementations like Chicken which require (import (r7rs)) before (import (scheme base)).

Comments (8)

  1. Takashi Kato repo owner

    Thank you for the report!

    I've checked Chibi Scheme and it does resolve cond-expand without importing (scheme base). I’ll accept the proposal 😉

  2. Lassi Kortela reporter

    Thank you. Gauche and Kawa also expose cond-expand by default so you will be in good company :)

    gosh -r 7 -e '(cond-expand (gauche (write 1)))' -e '(exit)'

    kawa --r7rs -e '(cond-expand (kawa 1))'

  3. Takashi Kato repo owner

    Seems Gauche doesn't resolve cond-expand on R7RS mode

    $ scheme-env run gauche@0.9.7 -- -r7 ~/foo.scm
    *** ERROR: invalid syntax: (else #f)
        While compiling "/**/foo.scm" at line 1: (cond-expand (gauche (import (scheme base)) (display "ok") (newline)) (else #f))
        While loading "/**/foo.scm" at line 4
    Stack Trace:
    _______________________________________
    
    ;; foo.scm
    (cond-expand (gauche
                  (import (scheme base))
                  (display "ok") (newline))
                 (else #f))
    

    You may also want to create an issue on Gauche’s repository, then (might already been done though) 😉

  4. Lassi Kortela reporter

    Tested the fix but it doesn’t seem to take quoting into account:

    $ echo "(cond-expand (sagittarius 123))" >hello.scm
    $ sagittarius hello.scm
    $ sagittarius -r 7 hello.scm
    Unhandled exception
      Condition components:
      1. &undefined
      2. &who sagittarius
      3. &message unbound variable sagittarius in library user
      4. &stack-trace
    
    stack trace:
      [1] #f
        src: (sagittarius 123)
        "hello.scm":1
      [2] eval
      [3] main-loop
      [4] dynamic-wind
      [5] script
    

    You’re right about Gauche, it seems to be stricter in R7RS script mode than R7RS REPL mode.

    You need to also import (scheme write) to get display. But it still doesn’t work:

    (cond-expand (gauche (import (scheme base) (scheme write)) (display "ok") (newline)))

    Gives the error:

    $ gosh -r7 foo.scm
    ok
    *** ERROR: unbound variable: gauche
        While loading "./foo.scm" at line 1
    
  5. Lassi Kortela reporter

    Chibi doesn’t work so easily either when running a file:

    (cond-expand
      (chibi (import (scheme base) (scheme write))
             (display "ok")
             (newline)))
    

    Error:

    $ chibi-scheme foo.scm
    ERROR on line 3 of file foo.scm: undefined variable: display
    
  6. Lassi Kortela reporter

    Thanks! I rebuilt is according to your instructions and it works 🙂

    $ cat >hello.scm
    (cond-expand (sagittarius (import (scheme write) (scheme base))
                              (display "ok") (newline)))
    $ sagittarius -r 7 hello.scm
    ok
    
  7. Log in to comment