[racket] About genericity...
On Oct 24, 2014, at 6:11 AM, Joan Arnaldich <jarnaldich at gmail.com> wrote:
> Hi there,
>
> I stumbled upon this thread when searching for generics. I really like
> Alexander's solution, but if I understand it correctly, the my-match-lambda-
> append function should read something like:
>
> (define my-match-lambda-append
> (case-lambda
> [() (case-lambda)]
> [(f1 . f2) (lambda args
> (with-handlers ([exn:fail:my-match-lambda:no-match:next-
> clause?
> (λ (e) (apply (apply my-match-lambda-append
> f2) args))])
> (parameterize ([within-my-match-lambda-append? #t])
> (apply f1 args))))]))
>
>
> Notice the dot clause and the recursive call. Otherwise it wouldn't work
> with more than 2 clauses...
I actually changed this later to do something sort of similar to work with more than 2 clauses (and handle keywords):
https://github.com/AlexKnauth/hash-lambda/blob/master/mutable-match-lambda/mutable-match-lambda-procedure.rkt#L46
(define mutable-match-lambda-clause-append
(case-lambda
[() (case-lambda)]
[(f) f]
[(f1 f2) (keyword-lambda (kws kw-args . args)
(with-handlers ([exn:fail:mutable-match-lambda:no-match:next-clause?
(λ (e) (keyword-apply f2 kws kw-args args))])
(parameterize ([within-mutable-match-lambda-clause-append? #t])
(keyword-apply f1 kws kw-args args))))]
[(f1 . rst) (mutable-match-lambda-clause-append f1 (apply mutable-match-lambda-clause-append rst))]
))
By the way I'm thinking of rewriting the whole thing further to use something a bit more like this idea (if I can):
http://www.greghendershott.com/2013/06/a-case-with-fall-through.html
>
> Just for completeness, I created a gist with the full code and updated tests:
> https://gist.github.com/jarnaldich/056a5856d3b1ce05c312#file-my-match-lambda-
> rkt
>
> Cheers,
>
> Joan
>
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20141024/a3a61373/attachment.html>