3
votes

I am writing a simple script using Racket and I want to pass in three values from the command line. Two floats and an integer.

My initial thought was to try this:

(define args (current-command-line-arguments))
(define c (string->number(car args)))

but that did not work as expected. I received this error:

car: contract violation
  expected: pair?
  given: '#("3" "2")

I'm new to Racket, but I think the the # means procedure rather than list. I just need a list of the arguments.

I found some documentation on parsing command line args from Racket, but it seems to be designed to parse for switches/options rather than just values.

Can anyone offer any advice? thanks.

1
The command-line macro that you linked to does let you specify the number of arguments with #:args (saves you some code to check that). You're correct that you still have to check/parse the individual arguments yourself though.Asumu Takikawa

1 Answers

5
votes

The result of current-command-line-arguments is a vector. Use vector-ref instead of car.

(define c (string->number(vector-ref args 0)))