yanyingwang1
2020-8-20 09:55:20

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
2020-8-20 09:58:25

@xrenas has joined the channel


popa.bogdanp
2020-8-20 10:01:46

@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))


xrenas
2020-8-20 10:02:02

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) ?


laurent.orseau
2020-8-20 10:06:13

There is no such value


laurent.orseau
2020-8-20 10:08:37

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)


yanyingwang1
2020-8-20 10:08:49

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.



yanyingwang1
2020-8-20 10:10:10

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


popa.bogdanp
2020-8-20 10:11:00

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


yanyingwang1
2020-8-20 10:13:24

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.


popa.bogdanp
2020-8-20 10:16:29

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.


yanyingwang1
2020-8-20 10:22:13

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


spdegabrielle
2020-8-20 13:02:18

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?


badkins
2020-8-20 15:04:51

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?


samc
2020-8-20 21:02:36

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


samc
2020-8-20 21:03:05

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


sorawee
2020-8-20 21:58:33

mflatt
2020-8-20 23:08:14

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.


samc
2020-8-20 23:10:03

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


sorawee
2020-8-21 01:32:30

Merged.