digitalmars.D.learn - Python eval() equivalent in Dlang working in Runtime?
- Baby Beaker (1/1) May 01 2020 There is a Python eval() equivalent in Dlang working in Runtime?
- tsbockman (8/9) May 01 2020 No, and there almost certainly never will be due to fundamental
- H. S. Teoh (16/24) May 01 2020 [...]
- tsbockman (5/21) May 01 2020 Good to know, but that's quite different from the eval() of
- H. S. Teoh (8/16) May 01 2020 True. I will say, though, that dmd is fast enough that unless you're
- jmh530 (4/5) May 01 2020 You might find arsd's script.d interesting [1], but it's more
There is a Python eval() equivalent in Dlang working in Runtime?
May 01 2020
On Friday, 1 May 2020 at 15:42:54 UTC, Baby Beaker wrote:There is a Python eval() equivalent in Dlang working in Runtime?No, and there almost certainly never will be due to fundamental differences between the languages. Depending on your goal, the closest alternatives are using the string mixin language feature, writing a parser (std.conv or certain DUB packages can help), or embedding a scripting engine such as AngelScript or Squirrel into your program. What are you really trying to do?
May 01 2020
On Fri, May 01, 2020 at 05:44:27PM +0000, tsbockman via Digitalmars-d-learn wrote:On Friday, 1 May 2020 at 15:42:54 UTC, Baby Beaker wrote:[...] Actually, if you're willing to ship a working copy of dmd with your program, you *could* compile D code on-the-fly and dynamically load it as a dll/shared library. (I have done this before in one of my projects, which generates D code based on user input then invokes dmd to compile it into a shared lib, then loads the shared lib and runs the compiled code.) It will be restricted to function calls and static variables, though; it will not be possible to access local variables in the scope where the eval() is called (unless you explicitly pass them through the dll/.so interface, i.e., as function parameters), and it will not be possible to eval() snippets smaller than a function. T -- The most powerful one-line C program: #include "/dev/tty" -- IOCCCThere is a Python eval() equivalent in Dlang working in Runtime?No, and there almost certainly never will be due to fundamental differences between the languages. Depending on your goal, the closest alternatives are using the string mixin language feature, writing a parser (std.conv or certain DUB packages can help), or embedding a scripting engine such as AngelScript or Squirrel into your program.
May 01 2020
On Friday, 1 May 2020 at 18:07:54 UTC, H. S. Teoh wrote:On Fri, May 01, 2020 at 05:44:27PM +0000, tsbockman via Digitalmars-d-learn wrote:Good to know, but that's quite different from the eval() of interpreted languages with respect to both semantics and performance, so it's really another item for the "D alternatives to eval()" list.On Friday, 1 May 2020 at 15:42:54 UTC, Baby Beaker wrote:[...] Actually, if you're willing to ship a working copy of dmd with your program, you *could* compile D code on-the-fly and dynamically load it as a dll/shared library.There is a Python eval() equivalent in Dlang working in Runtime?No, and there almost certainly never will be due to fundamental differences between the languages. Depending on your goal, the closest alternatives are using the string mixin language feature, writing a parser (std.conv or certain DUB packages can help), or embedding a scripting engine such as AngelScript or Squirrel into your program.
May 01 2020
On Fri, May 01, 2020 at 06:37:41PM +0000, tsbockman via Digitalmars-d-learn wrote:On Friday, 1 May 2020 at 18:07:54 UTC, H. S. Teoh wrote:[...]True. I will say, though, that dmd is fast enough that unless you're compiling large code snippets or doing it inside an inner loop, you might not notice the slight pause! T -- Turning your clock 15 minutes ahead won't cure lateness---you're just making time go faster!Actually, if you're willing to ship a working copy of dmd with your program, you *could* compile D code on-the-fly and dynamically load it as a dll/shared library.Good to know, but that's quite different from the eval() of interpreted languages with respect to both semantics and performance, so it's really another item for the "D alternatives to eval()" list.
May 01 2020
On Friday, 1 May 2020 at 15:42:54 UTC, Baby Beaker wrote:There is a Python eval() equivalent in Dlang working in Runtime?You might find arsd's script.d interesting [1], but it's more like a blend between D and javascript. [1]https://github.com/adamdruppe/arsd/blob/d0aec8e606a90c005b9cac6fcfb2047fb61b38fa/script.d
May 01 2020