One place where this can go wrong is with contracts. Contracts are implemented using chaperones and impersonators (depending on the particular contract) http://docs.racket-lang.org/reference/chaperones.html?q=chaperone#%28tech._chaperone%29. Because of how chaperones and impersonators work, a procedure with a contract may be equal? to the original procedure, but is not eq? to it.
I would suggest using equal? in your implementation instead of eq? That way if someone receives one of your measures with a contract around it, the get-maximum procedure will still work. I’m not sure if there are other pitfalls to look out for. I’m sure others will chime in. On November 4, 2015 at 11:14:47 AM, Erich Rast (er...@snafu.de) 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 -- 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. -- 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.