
hi everyone. I’m playing around with Racket’s generic interfaces and structs. And from the Racket doc page of struct and what I’ve tried, all the keyword include #: methods can only be used one time except #:property. My question is what if I defined two generic inteterfaces and want to use them within one struct?

@xrenas has joined the channel

@yanyingwang1 #:methods can be supplied multiple times. This should work just fine:
#lang racket
(require racket/generic)
(define-generics a (a-a a))
(define-generics b (b-b b))
(struct c ()
#:methods gen:a
[(define (a-a _)
'a)]
#:methods gen:b
[(define (b-b _)
'b)])
(a-a (c))
(b-b (c))

Does anyone know what value for the first argument of cons
should I pass to not change a list provided in the second argument in Scheme, e.g. (cons ??? '(a b c))
-> '(a b c)
?

There is no such value

You can build your own cons to do this though: (define no-value (gensym))
(define (maybe-cons x l)
(if (eq? x no-value)
l
(cons x l)))
(maybe-cons no-value '(a b c)) ; -> '(a b c)

Oh maybe I mistyped some code, I’ve tried that on my work this afternoon and it doesn’t work on my computer. I’m on my way home and will try that again when I got home.


and can’t we send a pic on the slack? It seems I didn’t find a icon to do this.

On desktop at least there’s an option to attach a file. Not sure about Slack for mobile.

Oh thanks. Actually I just wanna say, from the previous link I just sent, there is a paragraph says this: The #:inspector, #:auto-value, and #:guard options specify an inspector, value for automatic fields, and guard procedure, respectively. See make-struct-type for more information on these attributes of a structure type. The #:property option, which is the only one that can be supplied multiple times, attaches a property value to the structure type; see Structure Type Properties for more information on properties. The #:transparent option is a shorthand for #:inspector #f.

Ah, yeah, that seems wrong. You should open an issue about it on the Racket repo. Most likely someone forgot to change that sentence when generics were added.

If it is like this, we really should fix the doc. :nerd_face:

Does this rely on the Debian package? https://tracker.debian.org/pkg/racket That seems to need a icon moved
https://launchpad.net/~plt/+archive/ubuntu/racket
I don’t currently have a machine I could try this on. Do you think you could give it a go?

Just out of curiosity, can you provide more context regarding why you want to do this? In other words, why not just use '(a b c)
vs. (cons ??? '(a b c))
even if there existed a ???
that worked?

anyone know how to interpret a "+" in a printed module-path-index? e.g. #<module-path-index:"core-types.rkt" + 'tmp[136608]>

As reported by identifier-binding
. Trying to track down why two ids aren’t free-identifier=?
:confused:


It means the module path “core-types.rkt” relative to a module with the symbolic name tmp
. Why the module is named tmp
is unclear without more context, but it may be the name of a module at compile time, or maybe it’s a module named tmp
was declare outside of a file.

ah yeah I have a file named tmp
which is where I expect it’s from

Merged.