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


Groups > comp.lang.forth > #36466

Re: lisp can sum a list of numbers with 2 parens and a +, can forth useloop to make something similar?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail
From Unknown <dog@gmail.com>
Newsgroups comp.lang.forth
Subject Re: lisp can sum a list of numbers with 2 parens and a +, can forth useloop to make something similar?
Date Wed, 11 Feb 2015 09:19:16 +0000 (UTC)
Organization A noiseless patient Spider
Lines 55
Message-ID <pan.2015.02.11.09.28.06@gmail.com> (permalink)
References <6c04408e-ec35-4a54-b066-e25ee55f4f07@googlegroups.com> <mb9sme$le0$1@dont-email.me> <54d8af54$0$282$14726298@news.sunsite.dk>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 8bit
Injection-Date Wed, 11 Feb 2015 09:19:16 +0000 (UTC)
Injection-Info mx02.eternal-september.org; posting-host="b4e86702a125c9837ba0173f2541fe79"; logging-data="18827"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/6OaFDmLv4Dqclb2UjoDdzRf9QsHB2RpQ="
User-Agent Pan/0.133 (House of Butterflies)
Cancel-Lock sha1:ZFDKBLly/x0suPXQ0kJxvuhlryw=
Xref csiph.com comp.lang.forth:36466

Show key headers only | View raw


On Mon, 09 Feb 2015 08:00:02 -0500, Doug Hoffman wrote:

> On 2/9/15 3:55 AM, WJ wrote:
> 
>> Calculate the average of the numbers in a list, traversing it only once
>> and making no assignments to a variable:
>>
>> Gauche Scheme:
>>
>> (define (average numbers)
>>    (apply /
>>      (fold (lambda (x accum) (map + (list x 1) accum))
>>            '(0 0)
>>            numbers)))
>>
>> (define numbers `(,@(iota 9 -9 2) 633 ,@(iota 9 22))) numbers
>>   ===>
>> (-9 -7 -5 -3 -1 1 3 5 7 633 22 23 24 25 26 27 28 29 30)
>>
>> (average numbers)
>>   ===>
>> 858/19
>>
>> (inexact (average numbers))
>>   ===>
>> 45.1578947368421
>>
>>
>> The easy way would be
>>
>> (/. (apply + numbers) (length numbers))
>>   ===>
>> 45.1578947368421
>>
>> but that traverses the list twice: once to add up the numbers and once
>> to determine the length of the list.
> 
> 
> : ave{ 0e 0
>    begin parse-name 2dup s" }" compare
>    while >float drop f+ 1+
>    repeat 2drop s>f f/ f. ;
> 
> ave{ -9 -7 -5 -3 -1 1 3 5 7 633 22 23 24 25 26 27 28 29 30 }
> 45.1578947368421 ok
> 
> \ the easier way would be to use library code: f{ -9 -7 -5 -3 -1 1 3 5 7
> 633 22 23 24 25 26 27 28 29 30 } average: f. 45.1578947368421 ok

Computing is no longer 'about computors' it's about human cognition:
saving effort. Yes, minimal text is part of saving-effort.
But recognise & select [ie. menu] instead of 'coding' is cheaper.
Also color economically adds cognitive power.
Where's the VISUAL forth?

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


Thread

lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? the_gavino_himself <visphatesjava@gmail.com> - 2015-01-22 19:34 -0800
  Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? foxaudioresearch@gmail.com - 2015-01-22 20:08 -0800
    Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? Mark Wills <markwills1970@gmail.com> - 2015-01-23 02:00 -0800
    Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? Coos Haak <chforth@hccnet.nl> - 2015-01-23 14:07 +0100
      Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? "WJ" <w_a_x_man@yahoo.com> - 2015-01-24 01:43 +0000
      Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? beeflo <beeflobill@gmail.com> - 2015-01-29 08:22 -0800
        Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? "Elizabeth D. Rather" <erather@forth.com> - 2015-01-29 11:35 -1000
          Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-01-30 16:20 +0000
            Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? Bernd Paysan <bernd.paysan@gmx.de> - 2015-01-30 21:48 +0100
    Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? the_gavino_himself <visphatesjava@gmail.com> - 2015-01-23 13:09 -0800
    Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? empty-buffers <empty.buffersYOU-DONT-WANT-THIS@gmail.NEITHER-THIS.com> - 2015-01-29 00:38 +0000
      Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? Coos Haak <chforth@hccnet.nl> - 2015-01-29 02:49 +0100
      Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? "Elizabeth D. Rather" <erather@forth.com> - 2015-01-28 16:34 -1000
  Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? the_gavino_himself <visphatesjava@gmail.com> - 2015-01-29 16:04 -0800
    Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? Paul E Bennett <Paul_E.Bennett@topmail.co.uk> - 2015-01-30 08:46 +0000
  Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? skydda.barnen@gmail.com - 2015-01-30 02:39 -0800
    Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? "Alex McDonald" <blog@rivadpm.com> - 2015-01-30 11:32 +0000
      Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? lehs <skydda.barnen@gmail.com> - 2015-01-30 04:08 -0800
      Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? lehs <skydda.barnen@gmail.com> - 2015-01-30 08:38 -0800
        Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? Coos Haak <chforth@hccnet.nl> - 2015-01-30 22:01 +0100
          Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? lehs <skydda.barnen@gmail.com> - 2015-01-30 22:16 -0800
            Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? Coos Haak <chforth@hccnet.nl> - 2015-02-01 00:23 +0100
              Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? lehs <skydda.barnen@gmail.com> - 2015-02-01 00:35 -0800
                Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? Coos Haak <chforth@hccnet.nl> - 2015-02-01 14:20 +0100
                Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? lehs <skydda.barnen@gmail.com> - 2015-02-01 07:42 -0800
                Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? albert@spenarnc.xs4all.nl (Albert van der Horst) - 2015-02-01 17:24 +0000
                Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? lehs <skydda.barnen@gmail.com> - 2015-02-01 09:58 -0800
                Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? albert@spenarnc.xs4all.nl (Albert van der Horst) - 2015-02-02 00:46 +0000
                Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? "Elizabeth D. Rather" <erather@forth.com> - 2015-02-01 08:59 -1000
                Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? lehs <skydda.barnen@gmail.com> - 2015-02-01 12:06 -0800
                Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? hughaguilar96@gmail.com - 2015-02-08 18:43 -0800
                Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? Ron Aaron <rambamist@gmail.com> - 2015-02-09 08:36 +0200
    Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-01-30 16:27 +0000
      Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? lehs <skydda.barnen@gmail.com> - 2015-02-01 01:24 -0800
        Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-02-01 16:13 +0000
          Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? lehs <skydda.barnen@gmail.com> - 2015-02-01 10:54 -0800
  Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? hughaguilar96@gmail.com - 2015-02-08 18:07 -0800
  Re: lisp can sum a list of numbers with 2 parens and a +, can forth useloop to make something similar? "WJ" <w_a_x_man@yahoo.com> - 2015-02-09 08:55 +0000
    Re: lisp can sum a list of numbers with 2 parens and a +, can forth useloop to make something similar? Doug Hoffman <glidedog@gmail.com> - 2015-02-09 08:00 -0500
      Re: lisp can sum a list of numbers with 2 parens and a +, can forth useloop to make something similar? Unknown <dog@gmail.com> - 2015-02-11 09:19 +0000

csiph-web