retroforth/example/AddingVectors.forth
crc 73493f92f4 complete renaming of words in the examples
FossilOrigin-Name: c9ea59275146e3ccddbcfc3c8e2aa12e0c1f51f6d54c9674cf7d9a3b0500bf7c
2018-05-07 16:36:37 +00:00

24 lines
423 B
Forth

This is an example adding two three element vectors.
~~~
:vadd (v1v2v3-)
'abc 'cabcabcab reorder
[ #2 + ] tri@ [ fetch ] bi@ + swap store
[ n:inc ] tri@ [ fetch ] bi@ + swap store
[ fetch ] bi@ + swap store ;
~~~
A test case:
~~~
'a d:create #1 , #2 , #3 ,
'b d:create #2 , #3 , #4 ,
'c d:create #3 allot
&a &b &c vadd
&c fetch-next n:put nl
fetch-next n:put nl
fetch n:put nl
~~~