Does anyone know if it's possible to create a DSL like this:
Copy code
myDsl {
1,
2,
3,
}
and end up with like a list of
1, 2, 3
somewhere in the DSL's code
🚫 2
j
Joost Klitsie
12/28/2021, 8:52 AM
No, it would be extremely weird as well. what does a comma mean? Why not make a function with a vararg? What you could do is:
Copy code
myDsl {
+1
+2
+3
}
The
+
(or unaryPlus) operator makes a lot more sense, it means we add something to something.
r
Ruckus
12/28/2021, 8:56 AM
No, and I don't see what that would get you over a simple function:
Copy code
myDsl(
1,
2,
3,
)
You couldn't do other calculations in the block, as the results of any calculations would need to be implicitly added. Thus you're effectively just passing a list of parameters, which is exactly what functions do.