M
Modular15mo 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
TobiasPitters15mo 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
PriNova15mo ago
Maybe you need to use StringLiteral or StringRef. I'm not really sure about both.
Goooshlrific
Goooshlrific15mo 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
PriNova15mo 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-codeOP15mo ago
I'm not too familiar with MLIR - do you have an example of doing that in mojo?
rd4com
rd4com15mo 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
PriNova15mo 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
rd4com15mo 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
PriNova15mo ago
Done, you earned your fisrt stargazer
rd4com
rd4com15mo ago
nice thank i dont know if it is only for the function param but its pretty versatile
PriNova
PriNova15mo ago
As function param as generic, Mojo uses 'AnyType'. Maybe this is an alias to 'object'
rd4com
rd4com15mo 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
PriNova15mo 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-codeOP15mo ago
This looks promising but there's no way to encode this to binary 😦
rd4com
rd4com15mo ago
what do you mean? serialize ?
ModularBot
ModularBot15mo ago
Congrats @rd4com, you just advanced to level 8!
Want results from more Discord servers?
Add your server