8 hours ago - last edited 8 hours ago
I'd like to propose an idea for the GDL language: a preprocessor much like the C preprocessor, which would allow defining macros that get expanded at the time the GDL object is saved and compiled.
GDL has its limitations, and as much as I would love to be able to define functions and custom datatypes, one can still accomplish quite a lot - it just takes a lot of code to do relatively simple things. For example you can definately design a general purpose subroutine to calculate a cross product, but to use it, you will probably will end up having to define an input dictionary, an output dictionary, assign values to the input dictionary one by one, make the 'gosub' call, and assign the result to something, one value at a time. Calling a macro object doesn't free you from having to deal with packaging and unpackaging data into various dictionaries and arrays, with rigidly defined variable names. So what if you could simply type a macro like this?:
! define a macro behind a # symbol for example - it could be anything
# define cross3(c, u, v, w) \
dict {result} : \
{c}.x = {u}.y * {v}.z - {u}.z * {v}.y : \
{c}.y = {u}.z * {v}.x - {u}.x * {v}.z : \
{c}.z = {u}.x * {v}.y - {u}.y * {v}.x
! call the macro [v1 and v2 are dicts with .x, .y, and .z keys]
cross3(result, v1, v2)
! which would be expanded as:
dict result : result.x = v1.y * v2.z - v1.z * v2.y : result.y = v1.z * v2.x - v1.x * v2.z : result.z = v1.x * v2.y - v1.y * v2.xI have already built something like this in Ruby using the ERB templating system from the standard library. I have array literals and straightforward vector math, with the inconvenience only of having to copy - paste into Archicad. What's nice about it is that Graphisoft would not have to alter the base GDL language - this could be a competely separate subsystem that only takes action when the code is compiled, and ideally it would be something you can turn on and off to get a live preview of the expanded results. I admit that it's a bit niche, but if you're developing library objects that do anything advanced, or just find yourself writing certain things often enough, having these kinds of macros would make the code far easier to read and maintain.
Going further, what if GDL had an 'include' statemet? Then you could actually have a central store of commonly used macros, rigorously tested and used by many different objects without ever needing to remember the exact names of all the parameters you need to pass to normal GDL macros.
Operating system used: Mac Apple Silicon 15.7.2