command-line-arguments
command-line-arguments copied to clipboard
support for float type
would it be easy to support float types?
Yes. Look at the occurrences of integer in parse.lisp and add proper support for float (by which I hope you mean double-float, not single-float, although, whatever floats your boat).
Would you like to become the new maintainer?
I can make a PR for this feature. so far I haven't needed much more than what is provided, but if there are new requests in the future I may be able to take a look. Thanks
One issues with floats is that there is no natural analog of parse-integer to read a float in common lisp. The easiest solution would be to use read-from-string but then you could get people sneaking arbitrary lisp execution into the argument parsing (e.g., --number "(progn #.(run-misc) 0.1234)". For some applications this could be a serious security problem.
Maybe a read-number type (the name of which would document the inherent danger), or a float type which either uses a bespoke float reader (apparently whole packages exist for this) or tries to sanitize the float argument before passing it to read-from-string (feels like something that is easy to get wrong).
There is a library for parse-number, and you could use uiop:safe-read-from-string to avoid the #. issue.