Re: [racket-users] [racket users] struct #:methods question

2020-04-20 Thread Jon Zeppieri
There's no trick to it: #lang racket/base (require racket/generic) (define-generics foo (foo-do foo x)) (struct thing (x) #:methods gen:foo [(define (foo-do f x) (thing x))]) On Mon, Apr 20, 2020 at 6:32 PM Kevin Forchione wrote: > > Hi guys, > How do you return an instance of the

[racket-users] [racket users] struct #:methods question

2020-04-20 Thread Kevin Forchione
Hi guys, How do you return an instance of the structure type from the struct’s #:methods? This is would seem to be a common situation, but it has me stumped. Kevin -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group

Re: [racket-users] New to racket, help with coursework question

2020-04-20 Thread David Storrs
Great job! For the record: Yes, it is entirely possible to have an 'if' clause choose the arguments to a function. This is legal: (define first-element (vector-ref some-vector (if (equal? type 'zero-indexed) 0 1))) As is this, which is more relevant to your exercise: (define leap-year-months (v

Re: [racket-users] Re: ask a pict its colour?

2020-04-20 Thread Spencer Florence
You could use pict/convert to make a wrapper that remembers the color: ``` #lang racket (require pict pict/convert) (struct pict+color (pict color) #:property prop:pict-convertible (lambda (x) (pict+color-pict x))) (define (my-colorize p c) (pict+color (colorize p c) c)) (define (get