xentropy
xentropy
MModular
Created by xentropy on 8/27/2024 in #questions
mojo-lsp-server crashing
Is it crashing for anybody else? I'm using it with neovim and I can reliably make it crash after a couple of minutes of using it.
35 replies
MModular
Created by xentropy on 8/9/2024 in #questions
Is this broken or is it me? Parameterized function alias...
alias ExampleFn = fn [L: Int] (Int32) -> SIMD[DType.uint8, L];

fn example_fn_1 [L: Int] (default: Int32) -> SIMD[DType.uint8, L]:
return SIMD[DType.uint8, L](default);


struct ExampleStruct:
var example_fn: ExampleFn;

fn __init__(inout self):
self.example_fn = example_fn_1;

""" This works fine """
fn make_buffer_ok [L: Int] (inout self, default: Int32) -> SIMD[DType.uint8, L]:
return example_fn_1[L](default);

""" This does not work """
fn make_buffer_sad [L: Int] (inout self, default: Int32) -> SIMD[DType.uint8, L]:
return self.example_fn[L](default);
alias ExampleFn = fn [L: Int] (Int32) -> SIMD[DType.uint8, L];

fn example_fn_1 [L: Int] (default: Int32) -> SIMD[DType.uint8, L]:
return SIMD[DType.uint8, L](default);


struct ExampleStruct:
var example_fn: ExampleFn;

fn __init__(inout self):
self.example_fn = example_fn_1;

""" This works fine """
fn make_buffer_ok [L: Int] (inout self, default: Int32) -> SIMD[DType.uint8, L]:
return example_fn_1[L](default);

""" This does not work """
fn make_buffer_sad [L: Int] (inout self, default: Int32) -> SIMD[DType.uint8, L]:
return self.example_fn[L](default);
The error is:
/home/pi/Development/mojo-lgpio/test.mojo:20:31: error: 'fn[Int](SIMD[int32, 1]) -> SIMD[uint8, $0]' is not subscriptable, it does not implement the `__getitem__`/`__setitem__` or `__refitem__` methods
return self.example_fn[L](default);
/home/pi/Development/mojo-lgpio/test.mojo:20:31: error: 'fn[Int](SIMD[int32, 1]) -> SIMD[uint8, $0]' is not subscriptable, it does not implement the `__getitem__`/`__setitem__` or `__refitem__` methods
return self.example_fn[L](default);
Basically, I need to use pattern of make_buffer_sad because I am using FFI to write a wrapper around lgpio...
15 replies
MModular
Created by xentropy on 8/3/2024 in #questions
Interfaces or Abstract Classes
I am learning the language, coming from .NET and Python. I am trying to implement a feature that is only aware of the of signature of another feature, and isn't concerned with its implementation details. Naturally, I reached for the traits system, but hit a brick wall because I found out you can't specify the return type of a function to be a trait, and I don't think you can specify a variable's type to be a trait either. I got partly around this writing a function that takes in the trait... I'm probably not making a ton of sense. Suppose I have feature A, that I want to be swappable at runtime with feature B based on a runtime configuration. Traditionally I would do this with interfaces, and traits seem like the closest thing. Is there a way to do this in Mojo?
7 replies