Hi Philip,

On Sat, 4 Aug 2018 00:08:46 -0500, Philip McGrath
<phi...@philipmcgrath.com> wrote:

>I'm still not sure that I understand what the original questioner is trying
>to do. It might help to see an example in code to be clear that we're all
>talking about the same thing.

I'm not really certain either, but Sanjeev wrote: 

  "make a keyword useable as the parameter-expr in a parameterize
   expression."

There is there no problem with passing parameter as keyword arguments
or making parameters from keyword arguments.  So I figured he must
somehow be asking about the keyword symbol itself.  

Perhaps he wants to define a set of functions that will take the same
keyword, but he wants the keyword *name* to be settable rather than a
code literal.

There's no way to do that in Racket - at least not any simple way.
Define won't let you use a variable (or parameter) in a formal
position.



>A few points for the list, though:
>
>On Fri, Aug 3, 2018 at 10:53 PM, George Neuner <gneun...@comcast.net> wrote:
>
>>       (define mykey (make-parameter (string->keyword "#:unless")))
>>
>
>Using (string->keyword "#:unless") will produce the same keyword value as
>(quote #:#:unless), which is *not* the same as the value of (quote
>#:unless).
>
>
>> 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.  …
>>       (define (f x y . keys ) ... )
>>       (f 1 2)
>>       (f 1 2 'unless #t )
>>
>
>This is absolutely possible, but I would strongly advise against it.
>
>You can call a function with dynamically calculated keyword arguments using
>keyword-apply
><http://docs.racket-lang.org/reference/procedures.html?q=keyword-apply#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._keyword-apply%29%29>,

But the called function has to accept the keyword(s) passed.  The
issue would seem to be defining functions without using keyword
literals.


>and you can create a function that accepts arbitrary or
>dynamically-calculated keyword arguments (which is rarely desirable) using
>make-keyword-procedure
><http://docs.racket-lang.org/reference/procedures.html?q=keyword-apply#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._make-keyword-procedure%29%29>.

Ok, I didn't know about make-keyword-procedure.

But this creates a procedure that accepts anything.  This seems worse
than the solution using the plist: the keyword accepting variant of
the function can't have named positional arguments.

Obviously, you can supply the "plain proc" variant and chain to it
from the keyword list variant - but it seems that the only use for
make-keyword-procedure is to create keyword aware wrappers for other
functions.  IOW: do it twice.


>These support essentially the same interface as an ad-hoc "keyword" system
>using symbols, but take advantage of Racket's (current and future)
>optimizations and features for keyword functions. Perhaps most importantly,
>clients that *don't *need to dynamically calculate keywords can use the
>normal calling conventions without having to worry about all this.
>
>-Philip

YMMV,
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