In order to reduce copy and pasting it would be useful to be able to define functions. I agree that it would be a bad thing to make meson turing-complete, so why not allow user-defined functions, but with the restriction that a user-defined function may not call any other user-defined function.
Agree. Restrict recursion (and indirect recursion). Restrict storing function in variables. So language will stay turing-incomplete.
It would also help me a great deal.
The simplest way to do this is probably to have the following restrictions:
That way, recursion is impossible, parsing is simple, and it adds no expressive power to the language (you can do the same functionality by inlining all such functions).
Would such restricted functions/macros be categorically unwanted, or can I take a shot at implementing it?
User defined functions will not be accepted. End of discussion.
What you can do instead is to add functionality that provides what you were going to do with your functions and submit that as a pull request instead if it is generally useful. This way everyone can use it.
Thanks for the detailed explanation. Now it is obvious why user defined functions are not needed.
Now obviously we can't accept every niche thing in Meson master but we can add general tools that people can use to solve their own problems. The UX won't (and can't) be perfect but unfortunately everything is a tradeoff.
I accept the decision, user-defined functions won't happen, message received.
But I feel obligated to say you are contradicting yourself. You say we should add niche tools for everyone to use instead of general functionality that people can solve their own problems with, then the next message says the exact opposite.
If the decision is that no user-defined functions will be allowed, how do you propose that we reduce duplication of code in build files? The reason I originally posted this question is because I have 68 lines of meson code that I have to copy paste in a bunch of places. Adding user-defined functions or even just simple macros would help a lot here.
Can you maybe given an example of your usecase? For VLC for example I managed to get rid of a lot of repetition by using an array of dictionaries and iterating over them.
For VLC for example I managed to get rid of a lot of repetition by using an array of dictionaries and iterating over them.
I know this is currently the recommended way, but i always feel like that is a work around. Not something that really promotes the spirit of meson being easy and obvious to use.
@ePirat Sure! I'm happy to have more experienced mesoners take a look.
What this build file does is:
This exact same code ends up in a bunch of different places since I have a bunch of different folders which contain LCM files that need to be processed. It used to be more lines of meson code until I gave up and made a python script that does all of the steps for the python files at once.
The Meson file: https://gist.github.com/mkrogius/56fadc42cf0b551ba414accfa1dfb488
The python script I made to reduce the size of the meson file: https://gist.github.com/mkrogius/fb6c6c84bbb9c692c7a35f524d50cf66
Ideally I would just have to define all the necessary processing steps for my LCM files once, and then use that definition everywhere else in my project.
For clarity, by LCM I mean this project: https://lcm-proj.github.io/
For what it's worth, there is also PR #5209 which adds an include() function which might help in some cases with managing duplication/repeated chunks.
Not exactly - #5209 does not allow multiple inclusions of the same file, since it would be equal to function/macros, which are not allowed in meson by design. That PR main purpose is flat layout of split meson.build files (that is multiple split build files in one directory instead of one very long build file and/or multiple subdirectories for each split build file).
Most helpful comment
I know this is currently the recommended way, but i always feel like that is a work around. Not something that really promotes the spirit of meson being easy and obvious to use.