Anonymous user
Exponentiation with infix operators in (or operating on) the base: Difference between revisions
Exponentiation with infix operators in (or operating on) the base (view source)
Revision as of 19:38, 7 December 2020
, 3 years ago→{{header|Smalltalk}}: format
(→{{header|Smalltalk}}: added Sorry for the output to look different; but it does not really make sense here) |
m (→{{header|Smalltalk}}: format) |
||
Line 319:
=={{header|Smalltalk}}==
Smalltalk has no prefix operator for negation. To negate, you have to send the number a "negated" message, which has higher precedence than any binary message. Literal constants may have a sign (which is not an operation, but part of the constant).
<lang smalltalk>a := 2.
b := 3.
Transcript show:'-5**2 => '; showCR: -5**2.
Line 331 ⟶ 330:
" Transcript show:'5**-b => '; showCR: 5**-b. -- invalid: syntax error "</lang>
Using the "negated" message:
<lang smalltalk>Transcript show:'5 negated**2 => '; showCR: 5 negated**2. "negates 5"▼
▲Transcript show:'5 negated**2 => '; showCR: 5 negated**2. "negates 5"
Transcript show:'5 negated**3 => '; showCR: 5 negated**3.
Transcript show:'5**2 negated => '; showCR: 5**2 negated. "negates 2"
Line 345 ⟶ 343:
Transcript show:'(-5**b) negated => '; showCR: (-5**b) negated.
Transcript show:'-5 negated**2 => '; showCR: -5 negated**2. "negates the negative 5"
Transcript show:'-5 negated**3 => '; showCR: -5 negated**3.</lang>
{{out}}
<pre>
|