Define a primitive data type: Difference between revisions

Line 1,166:
 
=={{header|J}}==
J excels in composition rather than permitting verb overloading.
<pre>
le_z_=: 0 1-:"1 /:@(,&<"0) NB. compare arbitrary types
 
create_restrict_ =: monad define
'Value error. expected integer on [1,10]' assert 1 0 -: 1 11 le y
'Value error, non integral' assert (-: <.) y
value=: y
)
 
addAssign_restrict_=: monad def'create value + y'
 
 
4r3 conew 'restrict'
|Value error, non integral: assert
| 'Value error, non integral' assert(-:<.)y
'abc' conew 'restrict'
|length error: le
| 'Value error. expected integer on [1,10]'assert 1 0-:1 11 le y
'restrict'conew~s:' a' NB. symbol
|length error: le
| 'Value error. expected integer on [1,10]'assert 1 0-:1 11 le y
345 conew 'restrict'
|Value error. expected integer on [1,10]: assert
| 'Value error. expected integer on [1,10]' assert 1 0-:1 11 le y
0 conew 'restrict'
|Value error. expected integer on [1,10]: assert
| 'Value error. expected integer on [1,10]' assert 1 0-:1 11 le y
A =: 3 conew'restrict'
A =: 3 conew'restrict'
value__A
3
addAssign__A 2
5
value__A
5
addAssign__A 5
10
addAssign__A 3
|Value error. expected integer on [1,10]: assert
| 'Value error. expected integer on [1,10]' assert 1 0-:1 11 le y
</pre>
 
=={{header|Java}}==
Anonymous user