<div dir="ltr"><div>Problem 1 -- you have to use define/generic if you want to use the generic version of something in the context of a set of specific method implementations. That's by design.<br><br></div>Problem 2 -- what error message or unexpected behavior are you getting? That should work, it sounds like a bug in define/generic if it's not working.<br>
</div><div class="gmail_extra"><br clear="all"><div>Carl Eastlund</div>
<br><br><div class="gmail_quote">On Fri, Aug 16, 2013 at 4:36 PM, J. Ian Johnson <span dir="ltr"><<a href="mailto:ianj@ccs.neu.edu" target="_blank">ianj@ccs.neu.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I'm starting to use generics, and me being myself, I wrote some macros to make writing method definitions easier.<br>
But, I'm seeing that #:methods seems to rebind method identifiers in a way that hygiene interferes with.<br>
<br>
I would expect to be allowed to do the following two things (problems annotated):<br>
<br>
(struct exp (label fvs-box)) ;; parent struct for all expressions<br>
(define-generics binds-variables<br>
[free-box binds-variables]<br>
[free binds-variables #:bound [bound]]<br>
#:fallbacks [(define (free e #:bound [bound ∅]) ∅)<br>
(define free-box exp-fvs-box)]<br>
#:fast-defaults ([(compose unbox free-box)<br>
(define (free e #:bound bound) (unbox (free-box e)))])) ;; problem 1: free-box not in scope<br>
<br>
(define-syntax-rule (def-free e gfree bound struct [(pats ...) rhss ...])<br>
(begin<br>
(define/generic gfree free) ;; problem 2: since #:methods rebinds free, this is not in the scope one would expect with its definition in the define-generics form.<br>
(define (free e #:bound [bound ∅])<br>
(match e [(struct _ fvs-box pats ...)<br>
(set-box! fvs-box<br>
(let () rhss ...))]))))<br>
<br>
(struct var exp (name) #:transparent<br>
#:methods gen:binds-variables<br>
[(def-free e gfree bound var [(x) (if (x . ∈ . bound) ∅ (set x))])])<br>
<br>
I have workarounds thanks to stamourv, but they're unpleasant:<br>
Problem 1: define free in fast-defaults as an eta-expansion of a definition outside the define-generics form that does what you want.<br>
Problem 2: add free as a parameter to def-free, and pass free in at all uses of def-free.<br>
<br>
The first problem seems like more of a programming error than the use of the wrong tool.<br>
The second problem seems like generic method identifiers should be syntax-parameters, if they indeed need to be rebound in the rhs of the #:methods argument.<br>
<br>
Are these expectations unreasonable/against the design decisions for generics?<br>
Thanks,<br>
-Ian<br>
<br>
_________________________<br>
Racket Developers list:<br>
<a href="http://lists.racket-lang.org/dev" target="_blank">http://lists.racket-lang.org/dev</a><br>
</blockquote></div><br></div>