Define a primitive data type: Difference between revisions

Content added Content deleted
Line 1,166: Line 1,166:


=={{header|J}}==
=={{header|J}}==
J excels in composition rather than permitting verb overloading.
J excels in composition rather than permitting verb overloading. Express a dyadic operation as verb__object1 object2 rather than object1 verb object2 . The example uses the verb ''add'' . The constructor, create, retains j's array data structure opposed to limiting to an atom.
<lang J>
<lang J>
NB. le provides total ordering to control the error when non-numeric types are arguments
le_z_=: 0 1-:"1 /:@(,&<"0)
le_z_=: 0 1-:"1 /:@(,&<"0)

NB. used to ensure the object has the value field, again, to control errors.
nameClass_z_=: 4!:0
nameClass_z_=: 4!:0
signalError_z_=: 13!:8
signalError_z_=: 13!:8
Line 1,180: Line 1,183:
)
)


NB. return a new restrict object as the sum of two restrict-like objects

add_restrict_=: monad define
add_restrict_=: monad define
if. 0 = nameClass<'value__y' do.
if. 0 = nameClass<'value__y' do.
Line 1,195: Line 1,198:
1 2 3
1 2 3
4 5 6
4 5 6

B =: 1 4 conew 'restrict'
B =: 1 4 conew 'restrict'