shirok / Gauche

Scheme Scripting Engine
https://practical-scheme.net/gauche
Other
815 stars 81 forks source link

r7rs one-liners is awkward #719

Closed pclouds closed 4 years ago

pclouds commented 4 years ago

Caveat: I don't read r7rs from top down, I'm probably just doing something dumb. But hopefully there's some room for improvement.

I wanted to do something very simple, to get (features) out of gosh (for chibi snow).

This does not work (no output, not even an error)

gosh -r7 -e '(import (scheme base) (scheme write)) (write (features))' </dev/null

This does

gosh -r7 -e '(begin (import (scheme base) (scheme write)) (write (features)))'  </dev/null

However, that one does not work in Sagittarius while the first one does :( And I was hoping for something more or less portable, but I guess I'm running into some corner here.

A few more experiments, multiple '-e' does not work either:

gosh -r7 -e '(import (scheme base) (scheme write))' '(write (features))'  </dev/null

I'm guessing they are evaluated in two separate environments. There may be merits in that, so let's try import libraries from command line option

$ gosh -r7 -u '(scheme base)' -u '(scheme write)' '(write (features))'  </dev/null
gosh: "ERROR": cannot find "(scheme base)"

-u scheme.base does work. But it feels more Gauche-y and less r7rs-y.

I was thinking of falling back to gauche mode, but I don't know where (features) was from and had to import scheme.base anyway

gosh -u scheme.base -E 'write (features)' < /dev/null

Granted r7rs with all the explicit imports are not great for one-liners. And this is not a real report, just something I stumble upon. I'll probably close this soon.

shirok commented 4 years ago

It's explainable as follows.

I think the most intuitive solution is to allow multiple S-exprs contained in one -e option.

pclouds commented 4 years ago

Yeah I kinda expected multiple expressions in '-e' initially. That would be good improvement without breaking anything. The -u (and -m too) could probably accept r7rs libraries too (i.e. separated by spaces; with or without ()), at least when -r7 is specified.

pclouds commented 4 years ago

Never mind the -u comment. I just realized that chibi, r7rs-only scheme, also accepts module.name not 'module name' from command line. Easier to type is the reason, i guess.