Quicktip # 7 VEX Syntax
Added 2018-10-23 08:31:57 +0000 UTCThis is a pretty short and simple tip. But it will save you some time if you did not know this one.
VEX has some features in it's Syntax that allow you to work fairly quickly and press stuff into very few lines of code.
When I write more complex logic I do not use this but if it's a quick test or a short task it is quite handy.
And I am talking about something what you could call a nested function call.
So here is a simple VEX example. I get the returning vector of minpos() and save it into the vector variable pos. It is the closest position on the 2nd input geometry - the grid.
That position can be used to use addpoint to create a new point at that very position. Two lines.

The key note here is that minpos() returns a vector and addpoint NEEDS a vector. And that's when you can use nested function calls to save time and space.
You can write the same functionality this way
int pt = addpoint(0,minpos(1,@P));
The result of minpos is directly used for addpoint. And this can be used all the time the returning datatype of the nested function is equal to the expected parameter.
But be aware that some returning parameters are not defined like the function point()

As you can see the returning parameter is <type> which means it has the type of whatever the attribute is we named with attribute_name. If we want to get "P" that's a vector but the syntax only sees <type> during the call. In other words - you get an error.

In those cases you need something we call casting. A cast is basicly telling the result of point() that it is indeed a vector. Like so.

This basicly allows us to create some ridiculous long commands. They do work and you can try to challenge yourself to get your codes into as few lines of code as possible...

BUT this will lead to yourself travel back in time to kick yourself in the balls because you can't read whatever the duck this is supposed to do if you come back to it later.
But it is still pretty handy to combine 2 functions and it will increase your speed when creating these kinds of workflows.
It will also help you to memorize what the different functions expect and return if you start to incorporate this in your projects.
I hope this was useful to some of you!
Cheers
Dave