Exponentiation order: Difference between revisions

Added R. It got a bit silly.
m (→‎{{header|Phix}}: added syntax colouring the hard way, phix/basics)
(Added R. It got a bit silly.)
Line 724:
 
Stack empty.</pre>
 
=={{header|R}}==
The 'Operator Syntax and Precedence' documentation tells us that <lang>^</lang> is "exponentiation (right to left)". The 'Arithmetic Operators' documentation also tells us that the parser translates <lang>**</lang> to <lang>^</lang>, but its depreciation status is complicated.
 
It turns out that the parser is so blind to "**" that we cannot even quote it. The following are identical:
<lang r>print(quote(5**3))
print(quote(5^3))</lang>
As for actually solving the task, the requirement that each output be on a new line causes us a surprising amount of difficulty. We cannot pass a new line character to <lang>print</lang>, but <lang>cat</lang>, which does accept them, does not accept quoted inputs. To avoid repeating ourselves, we end up having to do some frankly ridiculous metaprogramming.
<lang r>inputs<-alist(5^3^2, (5^3)^2, 5^(3^2), 5**3**2, (5**3)**2, 5**(3**2))
printer<-function(i) print(paste(inputs[i], "returns: ", eval(inputs[[i]])))
invisible(sapply(seq_along(inputs), printer))</lang>
{{out}}
<pre>5^3
5^3
[1] "5^3^2 returns: 1953125"
[1] "(5^3)^2 returns: 15625"
[1] "5^(3^2) returns: 1953125"
[1] "5^3^2 returns: 1953125"
[1] "(5^3)^2 returns: 15625"
[1] "5^(3^2) returns: 1953125"</pre>
 
=={{header|Racket}}==
331

edits