Arc Forumnew | comments | leaders | submitlogin
Command line arguments
2 points by hasenj 5122 days ago | 3 comments
Is Arc suitable for use as a scripting language?

When attempting to run:

  $ arc app.arc -arg1 -arg2
It seems that 'arc' attempts to run each argument as an arc file.

  $ cat g.arc
  (prn ($.current-command-line-arguments))
  
  $ arc g.arc -arg1
  #(g.arc -arg1)
  call-with-input-file: cannot open input file: "/home/hasenj/code/playground/-arg1" (No such file or directory; errno=2)
The 'arc' command here is a symlink to arc.sh from Anarki. I suppose I could hack that to only accept one .arc file, but I was wondering if there's already an accepted mechanism for doing this kind of thing.

Does Arc actually have any functions/macros for parsing command arguments? Or do I just to drop into Racket with '$ ?



2 points by fallintothis 5121 days ago | link

I'm not aware of any option parsers written in Arc. There are plenty of good libraries to mimic (e.g., http://docs.python.org/library/argparse.html), but in the meantime, you could monkey-patch with Racket (http://docs.racket-lang.org/reference/Command-Line_Parsing.h...) or with getopt (http://man.cx/getopt) in arc.sh (not that that's portable).

-----

2 points by hasenj 5120 days ago | link

Is there a reason as.scm assumes all arguments are script files?

    ; command-line arguments are script filenames to execute
    (for-each (lambda (f) (aload f)) args)))

If no, I'd like to scratch that,

    ; only the first argument is a script filename 
    (aload (car args))))

-----

2 points by fallintothis 5120 days ago | link

Well, blame (https://github.com/nex3/arc/blame/5ac5d567bce08004c0dce6fc4c...) tells us that the commit (https://github.com/nex3/arc/commit/5ac5d567bce08004c0dce6fc4...) wasn't really belabored. My guess is that there's no particular rationale. It does make more sense to me to pass in argv parameters rather than just aloading everything.

-----