ashinn / chibi-scheme

Official chibi-scheme repository
Other
1.22k stars 141 forks source link

The command line is set too late for -e and -p #182

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

$ chibi-scheme -p '(command-line)' -- 0 1 2 3 4

What is the expected output? What do you see instead?

I expect:

(0 1 2 3 4)

I get:

#f

What version of the product are you using? On what operating system?

Head on Ubuntu Linux 12.4 LTS.

Please provide any additional information below.

Looking at main.c, it's obvious why this happens. In order to make the command 
line available to -e and -p (and I'd guess also modules loaded with -m and -x), 
I think you're going to have to parse the command line twice.

Original issue reported on code.google.com by a...@astro.unam.mx on 19 Jun 2013 at 5:19

GoogleCodeExporter commented 9 years ago
Either parse twice or delay actions.  But I don't want the
command-line processing to be more complicated than
needed.

Did you have a specific use-case for this?

Original comment by alexsh...@gmail.com on 19 Jun 2013 at 12:08

GoogleCodeExporter commented 9 years ago
Module foo.bar defines a main procedure, and I call it with:

chibi-scheme -m foo.bar -e '(main)' -- arg1 arg2 arg3 ...

Alternatively, module foo.bar implements an implicit main procedure in a begin 
clause, and I invoke it with

chibi-scheme -m foo.bar -- arg1 arg2 arg3 ...

I guess there are alternatives, but these seem natural to me, and I was very 
surprised that they didn't work.

Original comment by a...@astro.unam.mx on 19 Jun 2013 at 1:38

GoogleCodeExporter commented 9 years ago
This is similar to Python.  I was debating whether it was worthwhile, since
it encourages bloating modules with mains.  But it occurred to me that the
-r option used for SRFI-22 should already handle this, and it was more of
a bug that it didn't (there's no reason to require the script).

So you can write:

chibi-scheme -mfoo.bar -rmain -- arg1 arg2 arg3 ...

which is the same as

chibi-scheme -mfoo.bar -r -- arg1 arg2 arg3 ...

which is the same as

chibi-scheme -e'(define (main) <inline from foo.bar>)' -r -- arg1 arg2 arg3 ...

Note that if you do want to specify a name other than main,
there must be no space after -r.

How's that?

Original comment by alexsh...@gmail.com on 19 Jun 2013 at 2:23

GoogleCodeExporter commented 9 years ago
OK, I can use -r to work around this problem. Thanks.

However, if I understand correctly, (command-line) will return #f prior to 
calling the main procedure named by the -r option and will return a list of the 
specified arguments after calling the main procedure named by the -r option. I 
think the principle of least surprise requires that (command-line) give the 
same result no matter when it is called.

I used my original approach since defining a main in a module (or using 
implicit code in a begin) and using (command-line) to get the arguments seemed 
to be the safest way in R7RS-small Scheme to do this sort of thing. SRFI-22 is 
not part of R7RS-small Scheme.

By the way, the man page mentions -r but not -r<name> and "chibi-scheme --help" 
doesn't mention -r. I understand that the documentation for head is not always 
completely up-to-date.

Original comment by a...@astro.unam.mx on 19 Jun 2013 at 3:20

GoogleCodeExporter commented 9 years ago
The only safe R7RS approach is to write a program.  Once you're
talking about impl-specific options like -e nothing is portable.

I had updated chibi-scheme -h to mention -r.  Specifying a name
other than main was not officially supported.  I'll try to improve
docs before the release.

Original comment by alexsh...@gmail.com on 19 Jun 2013 at 9:40

GoogleCodeExporter commented 9 years ago
Yes, you're right that although my module code conforms to the draft R7RS, the 
way I invoke it does not. Thanks.

Alan

Original comment by a...@astro.unam.mx on 20 Jun 2013 at 6:25