Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #37688
| From | "WJ" <w_a_x_man@yahoo.com> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: How to solve this problem in FORTH? |
| Date | 2015-03-27 06:47 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <mf2ue4$rdc$1@dont-email.me> (permalink) |
| References | <f195a1a1-8609-4319-9df9-d8cbb2a11fdb@googlegroups.com> <d71058a5-aa4c-4308-acf3-346b610d6d8c@googlegroups.com> <m95bjd02k4l@enews6.newsguy.com> |
WJ wrote: > mhx@iae.nl wrote: > > > Marek Brunda <marekb@phoenics.org> writes > > > How to solve this problem in FORTH? What do you thing about this post? http://prog21.dadgum.com/33.html > > > > > My hurriedly solution is this: > > > > [..] > > > > > : ADD ( A1 A2 A3 U -- A1 A2 A3 ) > > > CELLS SWAP >R >R > > > 2DUP R@ + @ > > > SWAP R@ + @ + > > > R> R@ + ! R> ; > > > > > : VADD ( A1 A2 A3 -- ) > > > 0 ADD 1 ADD 2 ADD 2DROP DROP ; > > > > Not on every Forth of course, but I would try this: > > > > FORTH> : vadd params| a b c | > > a @ b @ + c ! > > a cell+ @ b cell+ @ + c cell+ ! > > a 2 cell[] @ b 2 cell[] @ + c 2 cell[] ! ; ok > > > > That awkward, inelegant, tedious to write, tedious to read > "solution" only works for vectors of length 3. > > Gauche Scheme: > > Creates a new vector: > > (define (v-add v1 v2) > (vector-map + v1 v2)) > > > Changes an existing vector: > > (define (v-add! v1 v2 v3) > (vector-map! > (lambda (_ val1 val2) (+ val1 val2)) > v3 v1 v2)) > > > Testing: > > (define v1 #(10 20 30 40 50 60 70 80 90)) > (define v2 #(100 200 300 400 500 600 700 800 900)) > (define v3 #(0 0 0 0 0 0 0 0 0)) > > (v-add v1 v2) > ===> > #(110 220 330 440 550 660 770 880 990) Oforth: [10, 20, 30, 40, 50, 60, 70, 80, 90] [100, 200, 300, 400, 500, 600, 700, 800, 900] zipWith( #+ ) println ===> [110, 220, 330, 440, 550, 660, 770, 880, 990]
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