gnembon / fabric-carpet

Fabric Carpet
MIT License
1.73k stars 275 forks source link

Calling system functions from `call()`? #1043

Open altrisi opened 3 years ago

altrisi commented 3 years ago

I know the docs say call can only for user defined functions, but I'm wondering how complex would be to allow it to call system functions.

My use case right now is that I have a dynamic suggester based on a previous parameter that is gotten from a map, pseudocode: <param1> <param2> -> param2_suggester = global_suggesters:param1

Now the problem I'm facing is that I must use strings for that, but I have situations where I want to get booleans (and in the future maybe numbers, etc). The idea I have now is to have that map hold pairs (or triples) with the second element being a function to call to convert param2 into the correct type. Given call doesn't allow calling system functions, I can't make it just 'bool', 'number' or 'str', I'd have to use _(val) -> bool(val), which isn't a lot more complicated, but would be nicer to be able to just call it from call, if it's not something that would involve big refactoring or things like that (for my use case it's not that big of a deal at least).

gnembon commented 3 years ago

by system functions you mean scarpet built-ins, right? not see a big reason not to allow that. One thing is that as you mentioned you could always wrap it with my_bool(a) -> bool(a), but that's feels nasty. In short - yeah, why not. calling conditionally some code sequential or parallel could become easier using call(if(..,'call','task'), _() -> todo()))