Turning Strings into code

BlitzMax Forums/BlitzMax Programming/Turning Strings into code

Capirola(Posted 2012) [#1]
Hi!

Is there any way to include Strings into executable code?

An example:

I'd like to make a function which does something with an Object (or a list etc etc) of which I'd like to specify the name in the function-parameters:

Functions MyFunction(Objectname$,ParamaterX,ParameterY)

Objectname$:MyType = New MyType

etc.


I hope this kind of explains what I'm asking for.

What I'd like to is this kind of thing for is a function for handling Objects which I could simply recycle for all kinds of different Types and Objects without having to modify its code.

I'm not too sure if this question even makes that much sense but I'd appreciate any kind of answer anyway. :-)


Jesse(Posted 2012) [#2]
It really doesn't make much sense. Do you want to recycle objects or code?

Are you trying to create some type of scripting so you don't have to recompile a program to obtain different output than I suggest you check out LUA it works with many computer languages including BlitzMax. Or do you mean Macros which Blitzmax doesn't support?

Other than that, you lost me.

Last edited 2012


ziggy(Posted 2012) [#3]
I'm not sure if youre refering to reflection (take a look about it on the blitzmax docs). If that's not what you're looking for, maybe scripting with LUA can be the answer... ?


Capirola(Posted 2012) [#4]
Thanks for the hints. I'll look into Lua-scripting then. :-)


Mahan(Posted 2012) [#5]
On a side note Lisp (and variants like Clojure) do exactly that. There you can for instance write functions or macros that actually generate runable code.

In Lisp this is quite elegant and not an abnormal frowned upon hack (as for instance eval() in .js or Python)


Yasha(Posted 2012) [#6]
Lisp has a standard representation for code data structures, and macros, fexprs or whatever can manipulate the code as though it were any other list, vector or Lisp data structure... Lisp doesn't have any special relationship with strings though (a string containing a Lisp program needs to be "read" before it exists as an s-expression, which is the equivalent of loading it into a compiler for other languages).

Tcl, on the other hand, really does use strings as its internal representation for everything, up to and including functions.


zoqfotpik(Posted 2014) [#7]
Yasha, have you implemented a LISP in Blitzmax?

I've been working on a forth dialect that uses recursive string expansion in the parser and it struck me today that it's actually closer to LISP. I realized that to do forth I need to write a bytecode assembly language and compile to that bytecode...


Yasha(Posted 2014) [#8]
Other than the Scheme you already found in the archives, no. I started a "proper" one a while back but gave up... the thing is, Lisp is simple in theory, but to make a good compiler it ends up being at least as complicated as any other language. I'm happier just using something the experts have tuned for years.

Would probably be fun to do sometime though.