Re:Conventions for Command Line Options
by chriswarbo on Saturday August 01, 2020 @04:51PM
(#24023811)
Interesting that you bring up Lisp and dynamic scope, since I've previously combined env vars with Racket's "parameters" (AKA dynamic bindings): https://lobste.rs/s/gnniei/setenv_fiasco_2015#c_owz2pp
[ Parent
| on HN ]
Re:Conventions for Command Line Options
by TeMPOraL on Saturday August 01, 2020 @05:17PM
(#24023975)
Yeah, I just can't stop thinking about envs / dynamic binding when someone brings up the other.
Speaking of using both direct and dynamic arguments, a common pattern in (Common) Lisp is using dynamically-bound variables (so-called "special" variables) to provide default values. Since default values in (Common) Lisp can be given as any expression, which gets evaluated at function-call time, I can write this:
(defun function (&key (some-keyword-arg *some-special*))
...)
And then, if I call this function with no arguments, i.e (some-function), the some-keyword-arg will pull its value from current dynamic value of some-special. In process land, this would be equivalent to having command line parser use values in environment variables as defaults for arguments that were not provided.