Define a primitive data type: Difference between revisions
→{{header|ooRexx}}: corrected to take care of a*2
Walterpachl (talk | contribs) m (→{{header|ooRexx}}: correct output) |
Walterpachl (talk | contribs) (→{{header|ooRexx}}: corrected to take care of a*2) |
||
Line 931:
* 21.06.2014 Walter Pachl
* implements a data type tinyint that can have an integer value 1..10
* 22.06.2014 WP corrected by Rony Flatscher to handle arithmetic
*---------------------------------------------------------------------*/
a=.tinyint~new(1) ; Say 'a='||a~value
Say '2*a='||(2*a)
Say 'a*2='||((0+a)*2)
say "---> rony was here: :)"
say "The above statement was in effect: '(0+a)*2', NOT 'a*2*, hence it worked!"
say "These statements work now:"
say "(a)*2:" (a)*2
say "<--- rony was here, The end. :)"
b=.tinyint~new(11); Say 'b='||b~value
b=.tinyint~new('B'); Say 'b='||b~value
Line 967 ⟶ 969:
::method value
Expose v
Return v
-- rgf, 20140622, intercept unknown messages, forward arithmetic messages to string value
::method unknown
expose v
use arg methName, methArgs
if wordpos(methName, "+ - * / % //")>0 then -- an arithmetic message in hand?
forward message (methName) to (v) array (methArgs[1])
</lang>
'''output'''
<pre>a=1
2*a=2
---> rony was here: :)
The above statement was in effect: '(0+a)*2', NOT 'a*2*, hence it worked!
These statements work now:
(a)*2: 2
a*2: 2
<--- rony was here, The end. :)
Argument 1 must be between 1 and 10
*-* Compiled method NEW with scope "Object"
Error 88 running D:\
Error 88.907: Argument 1 must be in the range 1 to 10; found "11"
</pre>
=={{header|Oz}}==
|