Vector: Difference between revisions

888 bytes added ,  3 years ago
Added Forth entry
m (→‎{{header|Phix}}: added syntax colouring the hard way, phix/basics)
(Added Forth entry)
Line 464:
VEC{ 5 2 } 1.3 v* = VEC{ 6.5 2.6 }
</pre>
 
 
 
=={{header|Forth}}==
 
{{works with|gforth|0.7.3}}
This is integer only implementation. A vector is two numbers on the stack. "pretty print" is just printing the two numbers in the desired order.
<lang forth>: v. swap . . ;
: v* swap over * >r * r> ;
: v/ swap over / >r / r> ;
: v+ >r swap >r + r> r> + ;
: v- >r swap >r - r> r> - ;</lang>
 
{{out}}
As Forth is [[wp:Read–eval–print_loop|REPL]], to add (1 , 2) to (3 , 4), just type <code>1 2 3 4 v+ v.</code> (followed by [Enter]):
<pre>1 2 3 4 v+ v. 4 6 ok</pre>
To substract (1 , 4) from (3 , 5), just type <code>3 5 1 4 v- v.</code> (followed by [Enter]):
<pre>3 5 1 4 v- v. 2 1 ok</pre>
To multiply (2 , 4) by 3, just type <code>2 4 3 v* v.</code> (followed by [Enter]):
<pre>2 4 3 v* v. 6 12 ok</pre>
To divide (12 , 33) by 3, just type <code>12 33 3 v/ v.</code> (followed by [Enter]):
<pre>12 33 3 v/ v. 4 11 ok</pre>
 
 
 
=={{header|Fortran}}==
Anonymous user