Safe Runtime DSL Evaluation (Codable DSL?)

I don't even know how to go about this, but I just thought the idea of being able to execute result builder DSL syntax dynamically would be awesome.

For example, if you are using SwiftHTML DSL, and you would like to add some dynamism to it, maybe you can make the DSL Codable and import/export DSL files on runtime. Or, in Narratore you maybe could import stories you've written in other tools. Or even create our own small live coding environment that fits the project's needs.

I think we can technically do it already, with some effort, but first-class language support would be really nice. Maybe a bit too much to put it in the compiler?

+ Edit: I changed the title to convey my idea more clearly. My point was, it would be great if there were a type-safe way to dynamically evaluate result builder DSLs during runtime. Much safer than just Python/JS style "eval()" things, still offers a lot of dynamism.

What would be the purpose of such dsl?
What problem would it be solving?

The question from ktoso is a good one, but I have a similar random thought: Dynamic import?

let foo = "Foundation"
import foo //currently doesn't work.

Could this be useful? Seems like a bit more protocol could result in an easy sort of plugin thing...

What initially came to my mind was to provide a way to write DSL in runtime. Kinda like what Eval Package does, but with your own DSL syntax. With that, users could input simple scripts that does specific things, without the risk of arbitrary code execution. For example, you could make a live coding environment like Sonic Pi or a comprehensive spreadsheet application like Numbers or Excel.

But also, it could be used to import/export functionalities on the fly in runtime. Admittedly, the second idea was an afterthought.

To my knowledge, dynamic linking in runtime is possible but kinda difficult to achieve. If you need to do that kind of thing, maybe look into this article?

Reading it back, Maybe I didn't state my idea clear enough in the original post.

Python is an interpreter ! eval() is possible easily ... but Swift is a compiler
more difficult to have it in the runtime ! ( it's a big beast ! )

Yeah. It would definitely be harder to implement, but I don't think it's impossible.