Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse command line args as numbers in Racket

Tags:

scheme

racket

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.

like image 971
Guy Avatar asked Nov 14 '25 23:11

Guy


1 Answers

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

(define c (string->number(vector-ref args 0)))
like image 56
uselpa Avatar answered Nov 19 '25 10:11

uselpa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!