Vector: Difference between revisions

557 bytes added ,  1 month ago
m
Update Lang example: Use new struct definition syntax
(Update Lang example: Use new operation parser syntax)
m (Update Lang example: Use new struct definition syntax)
 
(3 intermediate revisions by 2 users not shown)
Line 704:
(55,0 + i77,0)
(2,5 + i3,5)
</pre>
 
=={{header|EasyLang}}==
<syntaxhighlight>
func[] vadd a[] b[] .
for i to len a[]
r[] &= a[i] + b[i]
.
return r[]
.
func[] vsub a[] b[] .
for i to len a[]
r[] &= a[i] - b[i]
.
return r[]
.
func[] vmul a[] b .
for i to len a[]
r[] &= a[i] * b
.
return r[]
.
func[] vdiv a[] b .
for i to len a[]
r[] &= a[i] / b
.
return r[]
.
print vadd [ 5 7 ] [ 2 3 ]
print vsub [ 5 7 ] [ 2 3 ]
print vmul [ 5 7 ] 11
print vdiv [ 5 7 ] 2
</syntaxhighlight>
 
{{out}}
<pre>
[ 7 10 ]
[ 3 4 ]
[ 55 77 ]
[ 2.50 3.50 ]
</pre>
 
Line 1,443 ⟶ 1,483:
=={{header|Lang}}==
<syntaxhighlight lang="lang">
struct &Vector = {
$x
$y
Line 3,413 ⟶ 3,453:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">class Vector2D {
construct new(x, y) {
_x = x
Line 3,462 ⟶ 3,502:
{{libheader|Wren-vector}}
Alternatively, using the above module and producing exactly the same output as before:
<syntaxhighlight lang="ecmascriptwren">import "./vector" for Vector2
 
var v1 = Vector2.new(5, 7)
168

edits