M
Modular13mo ago
sa-code

Is there a way to create lists of Strings yet?

I'm working on an implementation of Apache Arrow and it looks like we can't make lists of memory only types. Screenshot shows the full code but a minimal example is here:
var string_list = DynamicVector[String]()
string_list.push_back("asdf")
var string_list = DynamicVector[String]()
string_list.push_back("asdf")
Is there another way to create a list of strings?
No description
17 Replies
TobiasPitters
TobiasPitters13mo ago
As a potential workaround, maybe one can interact with the MLIR String Type directly: https://mlir.llvm.org/docs/Dialects/Builtin/#stringattr
Builtin Dialect - MLIR
Multi-Level IR Compiler Framework
PriNova
PriNova13mo ago
Maybe you need to use StringLiteral or StringRef. I'm not really sure about both.
Goooshlrific
Goooshlrific13mo ago
see https://docs.modular.com/mojo/roadmap.html#no-lifetime-tracking-inside-collections - my read is that this isn't possible in a safe way until mojo supports polymorphism
Modular Docs - Mojo🔥 roadmap & sharp edges
A summary of our Mojo plans, including upcoming features and things we need to fix.
PriNova
PriNova13mo ago
And how about a concrete implementation without polymorphism, traits etc.? Let us forget DRY for a moment, why does so many people think that without traits or polymorphism it will not work? If implemented as concrete functions or higher-order functions as some kind of dispatching, it should work, shouldn't it?
sa-code
sa-code13mo ago
I'm not too familiar with MLIR - do you have an example of doing that in mojo?
rd4com
rd4com13mo ago
well you could do var x:object = object([]) x.append("hello") x.append("world") and to remove it needs a function that rebuild a new array without the one you want to delete,
PriNova
PriNova13mo ago
'object' is a dynamic type. Did you made benchmarks about the performance? I think because of the dynamic nature, it could be very costly in performance.
rd4com
rd4com13mo ago
it is a workaround yes there is some valgrind benchmark, i will run some time benchmark good idea i dont know if that link has his place in this public thread so, u can check it out and i remove the message are we even suppose to use that type @PriNova ? or do you think its only for internals function arguments ?
PriNova
PriNova13mo ago
Done, you earned your fisrt stargazer
rd4com
rd4com13mo ago
nice thank i dont know if it is only for the function param but its pretty versatile
PriNova
PriNova13mo ago
As function param as generic, Mojo uses 'AnyType'. Maybe this is an alias to 'object'
rd4com
rd4com13mo ago
it seems that it behave like arrays in ruby, js and python where the reference is not mutated its nice so if you keep the string inside the array, the array act like a pointer if u will
PriNova
PriNova13mo ago
For immutable stuff, you have to look into functional programming approaches, like linked lists, etc. But then you have Monads, Functors etc.
sa-code
sa-code13mo ago
This looks promising but there's no way to encode this to binary 😦
Want results from more Discord servers?
Add your server