Re: [racket] About genericity...

2014-10-27 Thread Joan Arnaldich
Alexander D. Knauth writes: > 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 ... > By the way I'm thinking o

Re: [racket] About genericity...

2014-10-24 Thread Alexander D. Knauth
On Oct 24, 2014, at 6:11 AM, Joan Arnaldich 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-ap

Re: [racket] About genericity...

2014-10-24 Thread Joan Arnaldich
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 ar

Re: [racket] About genericity...

2014-04-07 Thread Alejandro Zamora Fonseca
Yes, it's the second guess, it is my only knowlege about genericity in Lisp. I wanted to know how to do in Racket ... :) thanks for all answers, Alejandro 2014-04-06 00:21, Daniel Prager escribió: Hi Roman I think, Alejandro wanted to add clauses in different places (generic in one module, ad

Re: [racket] About genericity...

2014-04-05 Thread Daniel Prager
Hi Roman > I think, Alejandro wanted to add clauses in different places (generic in one module, added method in another, for example). Quite possibly, or perhaps not! ;-) Alejandro gave an example of one declaration mechanism that he'd seen in CL. Hard to tell whether that's optimal for his cont

Re: [racket] About genericity...

2014-04-04 Thread Patrick Useldinger
On 05/04/2014 00:08, Patrick Useldinger wrote: I copied Common Lisp's model, but it's a good idea to add Racket-style contracts. It should be a matter of simply adding a matcher for this. I've pushed a quick fix. Your code becomes: (def-multi P contract-match-parms) (add-multi P (listof number

Re: [racket] About genericity...

2014-04-04 Thread Patrick Useldinger
On 04/04/2014 23:48, Alexander D. Knauth wrote: (def-multi +) (add-multi + '() (lambda () 0)) (add-multi + (listof number?) (lambda args (apply + args))) (add-multi + (listof vector?) (lambda args (apply v+ args))) (check-equal? (+ 1 2 3) 6) (check-equal? (+ (vector 1 2 3) (vec

Re: [racket] About genericity...

2014-04-04 Thread Alexander D. Knauth
Oh never mind I realized it’s expecting a list of predicates, not a predicate that takes a list. But it would probably be a good thing to make it to accept a predicate too, so that you can do (listof number?). On Apr 4, 2014, at 5:44 PM, Alexander D. Knauth wrote: > I wanted to try it out,

Re: [racket] About genericity...

2014-04-04 Thread Alexander D. Knauth
I wanted to try it out, but it’s giving me an error about car expecting a pair: . . car: contract violation expected: pair? given: # #lang racket (require (submod def-multi/def-multi multim)) (require plot/utils) (require (only-in racket [+ rkt:+])) (require rackunit) (def-multi +) (add-mu

Re: [racket] About genericity...

2014-04-04 Thread Patrick Useldinger
On 02/04/2014 20:48, Patrick Useldinger wrote: I can share it if you're interested, it's roughly 40 lines of code. Here's the link: https://github.com/uselpa/def-multi Racket Users list: http://lists.racket-lang.org/users

Re: [racket] About genericity...

2014-04-03 Thread Alexander D. Knauth
Is this sort of like what you mean?: (define dup (my-match-lambda*)) (my-match-lambda-add-clause! dup [(list (? string? s)) (string-append s s)]) (my-match-lambda-add-clause! dup [(list (? integer? n)) (list n n)]) (check-equal? (dup "Hello") "HelloHello") (check-equal? (dup 10) '(10 10)) Here’

Re: [racket] About genericity...

2014-04-03 Thread Roman Klochkov
Or even simpler  (define (dup a)   (cond     [(string? a) (string-append a a)]     [(integer? a) (list a a)]) :-) I think, Alejandro wanted to add clauses in different places (generic in one module, added method in another, for example). Thu, 3 Apr 2014 20:11:36 +1100 от Daniel Prager : >Her

Re: [racket] About genericity...

2014-04-03 Thread Daniel Prager
Here's an out-of-the-box option, using Racket's pattern matching with the (? predicate) form: (define/match (dup a) [((? string?)) (string-append a a)] [((? integer?)) (list a a)]

Re: [racket] About genericity...

2014-04-02 Thread Roman Klochkov
There is gls package  https://github.com/Kalimehtar/gls/tree/master It is even more generic (you may use any predicate as a `type') Your case is  #lang racket (require gls) (defgeneric dup) (add-method dup   (method ((a string?))      (string-append a a))) (add-method dup    (method ((a exact

Re: [racket] About genericity...

2014-04-02 Thread Asumu Takikawa
On 2014-04-02 20:53:58 +0200, Alejandro Zamora Fonseca wrote: > ¿How can I create generic-functions in Racket? > > Something like > this samples in CL: > > (defmethod dup ((a string)) > (concatenate 'string a a)) > > (defmethod dup ((a integer)) > (list a a)) See the docs for the `racke

Re: [racket] About genericity...

2014-04-02 Thread Patrick Useldinger
On 02/04/2014 20:53, Alejandro Zamora Fonseca wrote: (defmethod dup ((a string)) (concatenate 'string a a)) (defmethod dup ((a integer)) (list a a)) 1) From the standard Racket "swindle/tiny-clos" library, you can use the CLOS-like functions that you may already know from Common