Compound data type: Difference between revisions

Content added Content deleted
m (syntax ighlighting fixup automation)
Line 2,543: Line 2,543:


TI-89 BASIC does not have user-defined data structures. The specific example of a point is best handled by using the built-in vectors or complex numbers.
TI-89 BASIC does not have user-defined data structures. The specific example of a point is best handled by using the built-in vectors or complex numbers.

=={{header|Transd}}==
<syntaxhighlight lang="Scheme">#lang transd

// If the Point type needs encapsulation and/or methods, it should be
// implemented as class. Otherwise, the named tuple will do.

class Point: {
x: Double(), y: Double(),
@init: (λ _x Double() _y Double() (= x _x) (= y _y)),
@to-String: (λ ss StringStream() (textout to: ss
"Point( x: " x "; y: " y " )"))
// ... other methods can be defined here ...
}

MainModule: {
Point2: typealias(Tuple<Double Double>()),
_start: (λ
(with pt Point(2.5 3.7)
(lout "Class: " pt)
)
(with pt Point2(2.5 3.7)
(lout "\nNamed tuple: " pt)
)
)
}</syntaxhighlight>
{{out}}
<pre>
Class: Point( x: 2.5; y: 3.7 )

Named tuple: [[2.5, 3.7]]
</pre>


=={{header|TXR}}==
=={{header|TXR}}==