Re: [racket-users] Mandatory arguments for command-line
You really just want to call out from the case-lambda branches to other functions that are then designed according to what you want to parse, and you can then share pieces that are common to both branches. > On Nov 14, 2015, at 11:10 AM, Christopher Walborn wrote: > > Ok. So you're using command-line in the body of the first case, and > the-mandatory-argument takes the first word. Thanks to #:argv others, > command-line can process the remaining ones. `./manage -h` would essentually > give `racket -h` while `./manage anything -h` would give you help from > command-line. I see how this opens a rabit hole of interesting possibilities. > Maybe, too, case-lambda could be used with #:args -- let command-line deal > with optional flags and keep the end user from running into accidental > `racket` flag interactions, and then deal with positional arguments with the > case-lambda (or maybe match?). -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] Mandatory arguments for command-line
Ok. So you're using command-line in the body of the first case, and the-mandatory-argument takes the first word. Thanks to #:argv others, command-line can process the remaining ones. `./manage -h` would essentually give `racket -h` while `./manage anything -h` would give you help from command-line. I see how this opens a rabit hole of interesting possibilities. Maybe, too, case-lambda could be used with #:args -- let command-line deal with optional flags and keep the end user from running into accidental `racket` flag interactions, and then deal with positional arguments with the case-lambda (or maybe match?). -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] Mandatory arguments for command-line
It is not an either-or situation. Here is an alternative run where I combined case-lambda with command-line: > $ ./manage hello -t world -d good > (the-mandatory-argument: hello #t) > (-t #f) > (-d good) > (files: ()) The script is this now: #! /bin/sh #| exec racket -tm "$0" ${1+"$@"} |# #lang racket (provide main) (define main (case-lambda [(the-mandatory-argument . others) (displayln `(the-mandatory-argument: ,the-mandatory-argument ,(string? the-mandatory-argument))) (command-line #:program "manage" #:argv others #:usage-help "\n Copy at a limited rate" #:once-each [("-t") time "the duration of in seconds between each copy; default: 5" (displayln `(-t ,(string->number time)))] [("-d") dest "the directory to which will be copied; default: ." (displayln `(-d ,dest))] #:args files (displayln `(files: ,files)))] [() (displayln '(help me make it through the night))])) > On Nov 13, 2015, at 11:10 PM, Christopher Walborn wrote: > > Oh, interesting. There's several new things in there for me to explore. Thank > you. (And nice Beatles reference.) > > If you don't mind explaining -- what are the trade-offs between this approach > and using the arg parsing features of racket/cmdline? > > Thanks, > Christopher > -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] Mandatory arguments for command-line
Oh, interesting. There's several new things in there for me to explore. Thank you. (And nice Beatles reference.) If you don't mind explaining -- what are the trade-offs between this approach and using the arg parsing features of racket/cmdline? Thanks, Christopher -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] Mandatory arguments for command-line
Glad to hear you got this far. Consider using something like this: #! /bin/sh #| exec racket -tm "$0" ${1+"$@"} |# #lang racket (provide main) (define main (case-lambda [(the-mandatory-argument . others) (displayln `(the-mandatory-argument: ,the-mandatory-argument ,(string? the-mandatory-argument))) (displayln `(others: ,others ,(length others))) #true] [() (displayln '(help, I need somebody, help))])) I prefer this for simple scripts. Here are some interactions: $ ./manage hello world, how are you doing (the-mandatory-argument: hello #t) (others: (world, how are you doing) 5) #t $ ./manage (help (unquote I) need somebody (unquote help)) — Matthias > On Nov 12, 2015, at 1:09 PM, Christopher Walborn wrote: > > Thanks, Greg, that's helpful. > > By the way, I love racket-mode. DrRacket is a great environment, but I > get frustrated editing text in anything but Emacs (or more recently > Emacs with Evil via Spacemacs). Racket-mode provides enough support that > I only switch into DrRacket when I've hit the wall with debugging. > > It probably shows, but I'm just beginning to work with Racket proper and > while the documentation is exhaustive, there's just so much to learn. I > did two passes on Gregor Kiczales' Systematic Programming Design MOOC > back when it was on Coursera -- once as a student, and once as a > community TA. I've passed through most of Realm of Racket and am now > just trying to use Racket for things that are actually useful to me, > things I would normally just do through rough and raunchy adhoc shell > scripting. I'm switching back and forth between the guide and the > reference and grepping the codebase to find examples of in-the-wild > usages. > > As a curiosity, I had my co-worker who doesn't code read over the > original Python script I'd written, and this Racket script and he > commented that he found the Racket version easier to follow. I agree. > I've found it easy to get simple things done in Python, and that mostly > without knowing what I'm doing. Doing the same things in Racket has > required a little more effort to research how to solve the problem, but > I'm happier with the end result and feel better about it, somehow. > > Thanks again, > Christopher > > -- > You received this message because you are subscribed to the Google Groups > "Racket Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to racket-users+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] Mandatory arguments for command-line
Thanks, Greg, that's helpful. By the way, I love racket-mode. DrRacket is a great environment, but I get frustrated editing text in anything but Emacs (or more recently Emacs with Evil via Spacemacs). Racket-mode provides enough support that I only switch into DrRacket when I've hit the wall with debugging. It probably shows, but I'm just beginning to work with Racket proper and while the documentation is exhaustive, there's just so much to learn. I did two passes on Gregor Kiczales' Systematic Programming Design MOOC back when it was on Coursera -- once as a student, and once as a community TA. I've passed through most of Realm of Racket and am now just trying to use Racket for things that are actually useful to me, things I would normally just do through rough and raunchy adhoc shell scripting. I'm switching back and forth between the guide and the reference and grepping the codebase to find examples of in-the-wild usages. As a curiosity, I had my co-worker who doesn't code read over the original Python script I'd written, and this Racket script and he commented that he found the Racket version easier to follow. I agree. I've found it easy to get simple things done in Python, and that mostly without knowing what I'm doing. Doing the same things in Racket has required a little more effort to research how to solve the problem, but I'm happier with the end result and feel better about it, somehow. Thanks again, Christopher -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] Mandatory arguments for command-line
I don't know how to make the `command-line` syntax do this (there's no flag-clause like `#:required-once`). So I think I'd just do a normal test outside it: (define destination (make-parameter #f)) ;default to #f meaning "unspecified" (command-line your existing code ) (define (main) (unless (destination) (raise-user-error "The -d option is required.")) your existing code ) p.s. Not too many versions ago Racket added a `main` submodule [1]. Using that would let other, "helper" functions be used and tested independently. However for what you have, now, the way you're doing it also seems fine. [1]: http://docs.racket-lang.org/guide/Module_Syntax.html#%28part._main-and-test%29 -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.