#polymorphic procedure that works on things with a certain member

1 messages · Page 1 of 1 (latest)

mint wind
#
thing :: proc($a, $b) {
    a.foo = b.foo
}

I'm trying to implement something like alan webster's linked list macros

fervent tartan
#

Do you mean that you want it to not compile if a and b don't have foo fields?

#

I would generally suggest just having one specific type that you know about, instead of making it polymorphic.

mint wind
#

yeah i do

#

the gimmick i'm going for is i have different types that can be constructed into linked lists and one set of helpers to do all of that

#

like my entities are like that but so are things in my ui tree

fervent tartan
#

Not sure how much I recommend it, but you can do it with a where clause

mint wind
#

how can I check the field?

is there a different approach you like?

fervent tartan
#

You can do proc(a, b: $T) where intrinsics.type_has_field(T, "foo") {}, but I'm not sure where clauses give you good errors.

#

I would generally suggest that you make a proc for each type of thing

#

Perhaps a procgroup

mint wind
#

ahh i see

fervent tartan
#

That's what I do in my own project in the one place I do this

mint wind
#

does where check at compile time?

fervent tartan
#

Yes

mint wind
#

kk

#

i'll see how well where works and do the proc group if it isn't working

thanks a ton!

fervent tartan
#

The procgroup approach is probably better; trying to pretend to be Rust probably isn't gonna work out very well 🤣

mint wind
#

i'm trying to pretend to be c

fervent tartan
#

Trying to work out the exact incantation you need in order to actually get the correct where clause is more work than just writing out a proc for each one, morethanlike

#

If you've got literally 20 different structs all with different foo field types, then maybe - but in all seriousness, core:container/intrusive/list is a thing

mint wind
#

it does look pretty tricky