On 8/3/2018 11:52 AM, Sanjeev Sharma wrote:
make a keyword useable as the parameter-expr in a parameterize expression. for example, If I need a similar #:unless cause for  a bunch of for expressions It's not a current issue, but would be good  to have in the toolbox for next time.

If I'm understanding correctly, then no.  You can make the keyword symbol a parameter:

      (define mykey (make-parameter (string->keyword "#:unless")))

but you can't use it AS a keyword in a define, and you can't you use it in a keyword position in a function call.
e.g.,

      (define (f (mykey) [k #f] )  ... )
      > ERR: (mykey) not an identifier

      (define (g #:unless [k #f] )  ... )
      (g (mykey) 42)
      > ERR: arity mismatch


You probably can do something using macros, but I am not sure how. I'm not aware of a way in Racket to make a keyword name variable, or to modify a function's keyword list at runtime [some languages can do this].

One thing you might do is define the functions to take a plist "rest" argument, use ordinary symbols for keywords, and parse the arguments from the list.  It's annoying to do for a lot of functions, but if you have many functions using the same keyword list, you can break out the key parsing into a separate function.

e.g.,

      (define (f x y . keys ) ... )
      (f 1 2)
      (f 1 2 'unless #t )


George

--
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to