3 ms·
Scala-style if expressions would be significatly more readable IMO (particularly if you also had the feature of allowing a block to be used as an expression).
by lmm 3y ago
Scala-style if expressions would be significatly more readable IMO (particularly if you also had the feature of allowing a block to be used as an expression).
function deriv(exp, variable) {
return if(is_number(exp))
0
else if(is_variable(exp))
if(is_same_variable(exp, variable))
1
else
0
else if(is_sum(exp))
make_sum(
deriv(addend(exp), variable),
deriv(augend(exp), variable)
)
else if(is_product(exp))
make_sum(
make_product(multiplier(exp), deriv(multiplicand(exp), variable)),
make_product(deriv(multiplier(exp), variable), multiplicand(exp))
)
else error(exp, "unknown expression type -- deriv");
}