Vector: Difference between revisions

added Arturo
m (BASIC256 moved to the BASIC section.)
(added Arturo)
Line 166:
a/2 : [2.5000, 3.5000]
</pre>
 
=={{header|Arturo}}==
<syntaxhighlight lang="arturo">define :vector [
x y
][
print: -> render "(|this\x|, |this\y|)" ; prettyprint function
]
 
ensureVector: function [block][
ensure -> every? @block => [is? :vector &]
]
 
vadd: function [a b][
ensureVector [a b]
to :vector @[a\x + b\x, a\y + b\y]
]
 
vsub: function [a b][
ensureVector [a b]
to :vector @[a\x - b\x, a\y - b\y]
]
 
vmul: function [a n][
ensureVector [a]
to :vector @[a\x * n, a\y * n]
]
 
vdiv: function [a n][
ensureVector [a]
to :vector @[a\x // n, a\y // n]
]
 
; test our vector object
a: to :vector [5 7]
b: to :vector [2 3]
print [a '+ b '= vadd a b]
print [a '- b '= vsub a b]
print [a '* 11 '= vmul a 11]
print [a '/ 11 '= vdiv a 2]</syntaxhighlight>
 
{{out}}
 
<pre>(5, 7) + (2, 3) = (7, 10)
(5, 7) - (2, 3) = (3, 4)
(5, 7) * 11 = (55, 77)
(5, 7) / 11 = (2.5, 3.5)</pre>
 
=={{header|BASIC}}==
1,532

edits