Is this broken or is it me? Parameterized function alias...
The error is:
Basically, I need to use pattern of make_buffer_sad because I am using FFI to write a wrapper around lgpio...
8 Replies
Congrats @xentropy, you just advanced to level 2!
I guess there are limitations with Python and reading SPI bus for some high speed ADCs, so I thought this is a great use case for Mojo.
I got around it by using DTypePointer but still wondering if this should have worked.
This works:
There were a couple problems.
1. It looks like like you can't parameterize a parametric function pointer type in an
alias
. Not sure why though.
2. Your struct needed to be parameterized at the struct level so it knows that the different parts are parameterized in the same way.
also you forgot to cast from Int32 to UInt8Thanks!
I was trying to avoid parameterizing the struct itself. I am reading a different number of bytes every time, but the number of bytes is known at compile time. I don't want to create a new struct everytime I read the bytes. It seems like you should able to parameterize just the function, no?
You can parametrize just a function but having a method and a field on a struct both parameterized in the same way requires you to parameterize the struct. It's not clear to me why you need the struct without knowing more about the use case but you might be better off with just a function
just trying to do something object oriented, but you're right. there's a file handle that persists between function calls, so I thought I'd store the handle in the same struct as the group of functions that will use it. if I were willing to throw that away I could just use functions at the module level and I think the issue would be solved.
I don't know. This kind of feels like an issue with function pointers.
You can't parameterize a runtime value. Parameterization means the compiler actually makes a specialized version of the thing and so it needs to happen at compile time.
gotcha. so what I'm trying to do is fundamentally incorrect.