On Wednesday, November 4, 2015 at 8:14:42 AM UTC-8, erich wrote:
> Hi,
> 
> I have a number of functions for computing raw distance measures and
> functions to compute their maxima for a given number of items, so to
> normalize them to [0,1] I provide this:
> 
> (define (normalize/distance measure maximum)
>   (lambda (p q)
>     (/ (measure p q) (maximum (full-domain-size p q)))))
> 
> However, the maximum procedure seems unnecessary, because every measure
> has its own maximum. So I was wondering whether I could leave it out
> and instead use something like this:
> 
> (define (get-maximum measure)
>   (cond
>     ((eq? measure footrule) footrule-maximum)
>     ((eq? measure bogart) bogart-maximum)
>     .
>     .
>     .
>     (else (error 'get-maximum "unknown measure ~s" measure))))
> 
> both internally and for export. But if I also export it, because
> sometimes people might want to use the respective procedure directly,
> is this really safe? Will this always work, or can this somehow
> interfere with macros, modules, etc.? 
> 
> Best,
> 
> Erich

Alternatively, you can represent measures with structs containing a function 
instead of just functions, and then attach the maximizer function to each 
measure. If you want them to still use the function application syntax, you can 
implement prop:procedure in the measure struct so they're still usable as 
functions.

(struct measure (measuring-proc maximum-proc)
  #:prop prop:procedure (struct-field-index measuring-proc))

(define footrule (measure footrule-proc footrule-maximum))

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