Jump to content

Define a primitive data type: Difference between revisions

→‎{{header|ooRexx}}: corrected to take care of a*2
m (→‎{{header|ooRexx}}: correct output)
(→‎{{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)
/* Note that these ways of using it are invalid: ******************************
say "---> rony was here: :)"
Say (a)*2 --> Error 97 running D:\tinyint.rex line 5: Object method not found
say "The above statement was in effect: '(0+a)*2', NOT 'a*2*, hence it worked!"
-- Error 97.1: Object "a TINYINT" does not understand message "*"
say "These statements work now:"
Say a*2
say "(a)*2:" (a)*2
******************************************************************************/
Saysay '(0+"a)*2='||((0+: " 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</lang>
 
-- 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
(0+a)*2=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
 
2728 *-* Raise Syntax 88.907 array(1,1,10,i)
*-* Compiled method NEW with scope "Object"
1314 *-* b=.tinyint~new(11);
Error 88 running D:\tinyinttinyint2.rex line 2728: Invalid argument
Error 88.907: Argument 1 must be in the range 1 to 10; found "11" </pre>
</pre>
 
=={{header|Oz}}==
2,299

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.