Is it possible to get the origin of `strs` in `fn name(*strs: String)`?
Minimal repro, LSP shows
invalid call to 'append': method argument #0 cannot be converted from 'List[StringSlice[strs]]' to 'List[StringSlice[strs]]'
Seems like a bug, but maybe there's a proper way to do this?
9 Replies
Hey @toasty cool to see my code being used in ways I never imagined π€£ . No that won't work, you're trying to use the origin of the
VariadicList
as the origin of the strings themselves. This is a hard limitation of our current origin system, you can't have a heterogeneous list which is what this would need to be to be able to carry the origin of each of the strings inside the VariadicList
.
Now, what I like about Mojo is that you can point a π« to the compiler's head and say "trust me bro":
basically this is the hacky way of binding the origin to the list of strings itselfAhhh okay, now it makes sense with that explanation! I thought it would take a union of all the origins through some magic π
I have a PR open on nightly which should remove the need for
rebind[S](s[].as_string_slice()).splitlines()
well probably the VariadicList
is a union of the origins now that I think about itI appreciate the examples in coercing Mojo to do what I want haha
yeah not very adviced to the general public but I know you want to get other things done lol
I wanted to see how far I could go without allocating new strings, but avoiding the deep arcane stuff. I probably wonβt implement the origin casting, but good to know nonetheless!
Doing a lot of split lines -> iterate over code points -> apply ansi sequences and padding -> rejoin
actually it should also remove the need for the shady casting
ImmutableOrigin.cast_from[__origin_of(items)].result
yep, I know that's a very common use case
you might want to copy some code from this PR
I want to introduce a lazy iterator over splitlinesAll of your recent changes have brought it very far ππΎ working with strings has felt much better
Iβll take a look, thanks!
Thanks a lot π . My goal is to make it feel like Python in that sense. It's one of the things I love most about it