Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #40777

Re: Forth programming style...

Newsgroups comp.lang.forth
Date 2015-07-24 03:48 -0700
References (5 earlier) <55357ad6-5a4b-4ef6-b46b-7d05f9c5b3cf@googlegroups.com> <80ebb1e3-e866-447b-94f5-1bd49481b09b@googlegroups.com> <moqanv$g2b$1@dont-email.me> <c2df7c0b-90ac-4354-99f6-981ec8abf600@googlegroups.com> <22264b92-31dd-408a-a9b9-37491958e810@googlegroups.com>
Message-ID <04a1bfca-2bb4-40df-839b-ea720f50a76c@googlegroups.com> (permalink)
Subject Re: Forth programming style...
From franck.bensusan@gmail.com

Show all headers | View raw


Le vendredi 24 juillet 2015 10:24:20 UTC+2, Mark Wills a écrit :
> It's also utterly un-readble gibberish. I mean, lets face it, in the
> vast majority of languages, you can normally get an idea of what some
> piece of code is doing, even if you don't understand all of it.
> 
> And people say Forth is write only! Pah!
> 
> Respect to WJ for being able to write it, I suppose, but it's not for
> me.

In Oforth :

// parn ( rl -- r ) : Calculate parallel resistance of 2 or more resistors
: parn { #[ dup2 * tor + / ] swap reduce }

[ 24, 24 ] parn .
12 ok
[ 24, 24, 24, 24 ] parn .
6 ok


If #par word is also needed, it can be created and used instead of the 
quotation : 

// par ( r1 r2 -- r )
: par { dup2 * tor + / }

// parn ( rl -- r )
: parn { #par swap reduce }


About #reduce, it is a high order word : 

// reduce ( aWord aCollection -- x )
It just applies the word between each element of a collection to
compute something :  

>#+ [ 1, 2, 3, 4, 5 ] reduce .
15 ok 
(this computes : 1 2 + 3 + 4 + 5 + )

>#max [ 1, 2, 3, 8, 2 ] reduce .
8 ok

Franck

Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Forth programming style... Mux <Yvo.Zoer@gmail.com> - 2015-07-21 15:40 -0700
  Re: Forth programming style... Julian Fondren <ayrnieu@gmail.com> - 2015-07-21 17:28 -0700
    Re: Forth programming style... Julian Fondren <ayrnieu@gmail.com> - 2015-07-21 17:39 -0700
      Re: Forth programming style... Mark Wills <markwills1970@gmail.com> - 2015-07-22 00:48 -0700
        Re: Forth programming style... "Elizabeth D. Rather" <erather@forth.com> - 2015-07-21 22:25 -1000
          Re: Forth programming style... onewingedshark@gmail.com - 2015-07-22 15:13 -0700
            Re: Forth programming style... "Elizabeth D. Rather" <erather@forth.com> - 2015-07-22 13:24 -1000
            Re: Forth programming style... stephen@mpeforth.com (Stephen Pelc) - 2015-07-23 08:28 +0000
        Re: Forth programming style... Raimond Dragomir <raimond.dragomir@gmail.com> - 2015-07-22 02:38 -0700
          Re: Forth programming style... Mark Wills <markwills1970@gmail.com> - 2015-07-22 03:14 -0700
            Re: Forth programming style... humptydumpty <ouatubi@gmail.com> - 2015-07-22 03:45 -0700
              Re: Forth programming style... "Elizabeth D. Rather" <erather@forth.com> - 2015-07-22 08:37 -1000
              Re: Forth programming style... Paul Rubin <no.email@nospam.invalid> - 2015-07-22 12:51 -0700
                Re: Forth programming style... "Elizabeth D. Rather" <erather@forth.com> - 2015-07-22 10:14 -1000
                Re: Forth programming style... anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-07-23 06:23 +0000
                Re: Forth programming style... hughaguilar96@gmail.com - 2015-07-23 16:59 -0700
                Re: Forth programming style... hughaguilar96@gmail.com - 2015-07-23 20:18 -0700
                Re: Forth programming style... "HAA" <someone@microsoft.com> - 2015-07-28 21:06 +1000
                Re: Forth programming style... "Alex McDonald" <blog@rivadpm.com> - 2015-07-28 12:38 +0100
            Re: Forth programming style... "HAA" <someone@microsoft.com> - 2015-07-23 00:02 +1000
            Re: Forth programming style... hughaguilar96@gmail.com - 2015-07-22 21:21 -0700
              Re: Forth programming style... "WJ" <w_a_x_man@yahoo.com> - 2015-07-23 09:05 +0000
                Re: Forth programming style... hughaguilar96@gmail.com - 2015-07-23 16:47 -0700
                Re: Forth programming style... Mark Wills <markwills1970@gmail.com> - 2015-07-24 01:24 -0700
                Re: Forth programming style... franck.bensusan@gmail.com - 2015-07-24 03:48 -0700
                Re: Forth programming style... Paul Rubin <no.email@nospam.invalid> - 2015-07-24 18:15 -0700
                Re: Forth programming style... "HAA" <someone@microsoft.com> - 2015-08-01 13:21 +1000
            Re: Forth programming style... hughaguilar96@gmail.com - 2015-07-22 21:48 -0700
            Re: Forth programming style... Raimond Dragomir <raimond.dragomir@gmail.com> - 2015-07-22 22:28 -0700
              Re: Forth programming style... Bernd Paysan <bernd.paysan@gmx.de> - 2015-08-02 00:43 +0200
            Re: Forth programming style... Bernd Paysan <bernd.paysan@gmx.de> - 2015-08-02 00:22 +0200
              Re: Forth programming style... hughaguilar96@gmail.com - 2015-08-01 16:41 -0700
                Re: Forth programming style... "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-08-01 22:01 -0400
              Re: Forth programming style... anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-08-02 05:50 +0000
                Re: Forth programming style... Bernd Paysan <bernd.paysan@gmx.de> - 2015-08-02 16:33 +0200
            Re: Forth programming style... "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-08-01 22:04 -0400
              Re: Forth programming style... "Elizabeth D. Rather" <erather@forth.com> - 2015-08-02 08:54 -0500
                Re: Forth programming style... "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-08-03 04:51 -0400
                Re: Forth programming style... "Elizabeth D. Rather" <erather@forth.com> - 2015-08-03 17:36 -0500
        Re: Forth programming style... anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-07-22 10:16 +0000
      Re: Forth programming style... mhx@iae.nl - 2015-07-22 10:02 -0700
    Re: Forth programming style... anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-07-22 10:09 +0000
  Re: Forth programming style... Syd Rumpo <usenet@nononono.co.uk> - 2015-07-22 12:16 +0100
    Re: Forth programming style... Raimond Dragomir <raimond.dragomir@gmail.com> - 2015-07-22 07:59 -0700
  Re: Forth programming style... glidedog@gmail.com - 2015-07-23 04:24 -0700
  Re: Forth programming style... "Ala'a Alawi" <amalawi@gmail.com> - 2015-07-23 19:32 -0700
    Re: Forth programming style... hughaguilar96@gmail.com - 2015-07-23 21:33 -0700
      Re: Forth programming style... borota@gmail.com - 2015-07-23 22:09 -0700
        Re: Forth programming style... hughaguilar96@gmail.com - 2015-07-23 22:57 -0700
        Re: Forth programming style... "Ala'a Alawi" <amalawi@gmail.com> - 2015-07-24 09:26 -0700
      Re: Forth programming style... "Ala'a Alawi" <amalawi@gmail.com> - 2015-07-24 09:26 -0700

csiph-web