felipecrv commented on code in PR #42106:
URL: https://github.com/apache/arrow/pull/42106#discussion_r1638354632
##########
cpp/src/arrow/compute/expression.cc:
##########
@@ -72,11 +72,12 @@ Expression field_ref(FieldRef ref) {
}
Expression call(std::string function, std::vector<Expression> arguments,
- std::shared_ptr<compute::FunctionOptions> options) {
+ std::shared_ptr<compute::FunctionOptions> options, bool
is_special_form) {
Review Comment:
This is exactly the kind of added complexity around calls that I'm trying to
convince you is not a good idea. This boolean is effectively saying the
arguments are passed in call-by-name fashion and not call-by-value [1].
We should keep the Arrow rewrite system a strict-evaluated system with just
1 or 2 special forms. That means calls are always called by value. We keep the
`if_else` and `case_when` functions as they are and introduce a
`ConditionalSpecialForm` in the context of `compute::Expression`.
C++ is a strictly evaluated rewrite system. You can't declare a function and
say "all the parameters are call-by-name" like you're trying to do with this
boolean parameter. So you can implement `if_else` just like Arrow does here and
has to use special syntax to get a conditional that takes two expression in a
call by name fashion.
```cpp
template<typename T>
T if_else(bool cond, T then_case, T else_case) {
if (cond) { return then_case; } else { return else_case; }
}
// Non-strict evaluation with special form syntax. The branches of the
// if are non-strictly evaluated in a way that can't be achieved with
// the `if_else` Call.
if (den > 0) {
return num / den;
} else {
return 0;
}
```
A general conditional special form can serve for if-else, `and`, and `or`.
Probably the single special form we need.
https://en.wikipedia.org/wiki/Evaluation_strategy#Non-strict_binding_strategies
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]