Exponentiation with infix operators in (or operating on) the base: Difference between revisions

Added R.
(Put all power functions in Haskell)
(Added R.)
Line 401:
x = 5 p = 3 -x^p is -125, -(x)^p is -125, (-x)^p is -125, -(x^p) is -125
</pre>
=={{header|R}}==
 
<lang R>expressions <- alist(-x ^ p, -(x) ^ p, (-x) ^ p, -(x ^ p))
x <- c(-5, -5, 5, 5)
p <- c(2, 3, 2, 3)
output <- data.frame(x,
p,
setNames(lapply(expressions, eval), sapply(expressions, deparse)),
check.names = FALSE)
print(output, row.names = FALSE)</lang>
{{out}}
<pre> x p -x^p -(x)^p (-x)^p -(x^p)
-5 2 -25 -25 25 -25
-5 3 125 125 125 125
5 2 -25 -25 25 -25
5 3 -125 -125 -125 -125</pre>
=={{header|Raku}}==
In Raku by default, infix exponentiation binds tighter than unary negation. It is trivial however to define your own infix operators with whatever precedence level meets the needs of your program.
331

edits