DrRacket and command line arguments

36 views
Skip to first unread message

David Storrs

unread,
Apr 18, 2020, 2:03:16 PM4/18/20
to Racket Users

Is there a way to specify command line arguments when running inside DrRacket?

For example:

#lang racket
(define foo (make-parameter 7))
(command-line
 #:program "foo"
 #:once-each
 [("--thing") thing "The thing" (foo thing)]
 )
(displayln (foo))


If running in DrRacket, how can I make this spit out 9 instead of 7?


Michael MacLeod

unread,
Apr 18, 2020, 2:30:46 PM4/18/20
to David Storrs, Racket Users
You can parameterize `current-command-line-arguments` like so:

```
#lang racket

(require racket/cmdline)

(define foo (make-parameter 7))

(parameterize ([current-command-line-arguments #("--thing" "9")])

  (command-line
   #:program "foo"
   #:once-each
   [("--thing") thing "The thing" (foo thing)])
  (displayln (foo)))
```

See the docs for more information.


--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/CAE8gKocbjLNy%3D9S-g4HSc6WmOJf2TAsd7LOzbEYGQsm%3DYLGLAg%40mail.gmail.com.

David Storrs

unread,
Apr 18, 2020, 2:32:23 PM4/18/20
to Michael MacLeod, Racket Users
Okay, so "edit the file" is the answer.  That works for me.  Thanks!

Jens Axel Søgaard

unread,
Apr 18, 2020, 2:43:14 PM4/18/20
to David Storrs, Racket Users
Hi David,

You can set the command line arguments that DrRacket uses in the dialog that appears 
from the menu "Language" and menu item "Choose Language...". You may need
to click the "Advanced" button too:

image.png




--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/CAE8gKocbjLNy%3D9S-g4HSc6WmOJf2TAsd7LOzbEYGQsm%3DYLGLAg%40mail.gmail.com.


--
--
Jens Axel Søgaard

Laurent

unread,
Apr 18, 2020, 2:50:00 PM4/18/20
to Jens Axel Søgaard, David Storrs, Racket Users
You can also use the `#:argv` argument of `command-line`.

David Storrs

unread,
Apr 18, 2020, 4:01:41 PM4/18/20
to Jens Axel Søgaard, Racket Users
Good to know.  Thank you.
Reply all
Reply to author
Forward
0 new messages