Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #35812
| From | "WJ" <w_a_x_man@yahoo.com> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: How to solve this problem in FORTH? |
| Date | 2015-01-14 14:00 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <m95spm$7b8$1@dont-email.me> (permalink) |
| References | <f195a1a1-8609-4319-9df9-d8cbb2a11fdb@googlegroups.com> <28a7cd52-ef88-46b9-98be-4997ab0dafc9@googlegroups.com> |
november.nihal@gmail.com wrote:
> variable v1{
> variable v2{
> variable v3{
>
> : } cells swap @ + ;
>
> : vadd ( v3 v2 v1 -- )
> rot >r
> over 0 } @ over 0 } @ + r@ 0 } !
> over 1 } @ over 1 } @ + r@ 1 } !
> 2 } @ swap 2 } @ + r> 2 } !
> ;
Indecipherable stack-juggling.
Haven't you ever heard of local variables?
And your function only handles vectors of length 3.
>
> : nn 1000 random ; immediate
>
> ( load values )
> here v1{ ! nn , nn , nn ,
> here v2{ ! nn , nn , nn ,
> here v3{ ! 0 , 0 , 0 , ( answer zeroed )
>
> ( try it ) v3{ v2{ v1{ vadd
>
> cr .( v1 == ) v1{ 0 } @ . v1{ 1 } @ . v1{ 2 } @ .
> cr .( v2 == ) v2{ 0 } @ . v2{ 1 } @ . v2{ 2 } @ .
> cr .( Result == ) v3{ 0 } @ . v3{ 1 } @ . v3{ 2 } @ .
: vec{
here { head } 0 ,
begin
bl word dup count s" }vec" compare
while
count evaluate , 1 head +!
repeat
drop head ;
: } 1+ cells + ;
: vec-print { v{ -- }
v{ @ 0 do v{ i } @ . loop ;
: vec-add { v3{ v2{ v1{ -- }
v1{ @ 0 do
v2{ i } @ v1{ i } @ + v3{ i } !
loop ;
vec{ 10 20 30 40 }vec constant v1{
vec{ 100 200 300 400 }vec constant v2{
vec{ 0 0 0 0 }vec constant v3{
v3{ v2{ v1{ vec-add
cr .( v1 == ) v1{ vec-print
cr .( v2 == ) v2{ vec-print
cr .( Result == ) v3{ vec-print
Output:
v1 == 10 20 30 40 ok
v2 == 100 200 300 400 ok
Result == 110 220 330 440 ok
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How to solve this problem in FORTH? Marek Brunda <marekb@phoenics.org> - 2015-01-13 04:24 -0800
How to solve this problem in FORTH? Julian Fondren <julian.fondren@gmail.com> - 2015-01-13 05:02 -0800
How to solve this problem in FORTH? Julian Fondren <julian.fondren@gmail.com> - 2015-01-13 05:09 -0800
Re: How to solve this problem in FORTH? november.nihal@gmail.com - 2015-01-13 05:29 -0800
Re: How to solve this problem in FORTH? "WJ" <w_a_x_man@yahoo.com> - 2015-01-14 14:00 +0000
Re: How to solve this problem in FORTH? november.nihal@gmail.com - 2015-01-14 06:59 -0800
Re: How to solve this problem in FORTH? awegel@arcor.de (Alexander Wegel) - 2015-01-14 23:39 +0100
Re: How to solve this problem in FORTH? Coos Haak <chforth@hccnet.nl> - 2015-01-13 15:12 +0100
Re: How to solve this problem in FORTH? humptydumpty <ouatubi@gmail.com> - 2015-01-13 10:30 -0800
Re: How to solve this problem in FORTH? mhx@iae.nl - 2015-01-13 12:14 -0800
Re: How to solve this problem in FORTH? "WJ" <w_a_x_man@yahoo.com> - 2015-01-14 09:06 +0000
Re: How to solve this problem in FORTH? mhx@iae.nl - 2015-01-14 04:13 -0800
Re: How to solve this problem in FORTH? Julian Fondren <julian.fondren@gmail.com> - 2015-01-14 04:55 -0800
Re: How to solve this problem in FORTH? "WJ" <w_a_x_man@yahoo.com> - 2015-03-27 06:47 +0000
Re: How to solve this problem in FORTH? jrcd83@gmail.com - 2015-03-28 08:09 -0700
Re: How to solve this problem in FORTH? "Alex McDonald" <blog@rivadpm.com> - 2015-03-28 20:53 +0000
Re: How to solve this problem in FORTH? rickman <gnuarm@gmail.com> - 2015-03-28 20:32 -0400
Re: How to solve this problem in FORTH? hughaguilar96@gmail.com - 2015-03-28 21:16 -0700
Re: How to solve this problem in FORTH? hughaguilar96@gmail.com - 2015-03-29 12:16 -0700
csiph-web