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


Groups > comp.lang.forth > #54076

Re: Rosetta Code: Accumulator factory

From anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups comp.lang.forth
Subject Re: Rosetta Code: Accumulator factory
Date 2017-01-17 13:54 +0000
Organization Institut fuer Computersprachen, Technische Universitaet Wien
Message-ID <2017Jan17.145454@mips.complang.tuwien.ac.at> (permalink)
References <o5kmev$tfm$1@gioia.aioe.org> <877f5uxbyq.fsf@nightsong.com>

Show all headers | View raw


Paul Rubin <no.email@nospam.invalid> writes:
>"Robert L." <No_spamming@noWhere_7073.org> writes:
>> f20 = factory(20)
>> f500 = factory(500)
>> p f500.call(3) ; p f500[3.0] ; p f500.(3)
>
>: acc ( n -- ) CREATE , DOES> ( n a -- n ) tuck @ + over ! @ ;

Looking at the Rosettacode page
<https://rosettacode.org/wiki/Accumulator_factory#Forth>, Ian Osgood
has partially solved this in 2010 (in a similar way).  Requirement 2
does not fit Forth at all, but I have now added an FP version and
explained the idiomatic Forth way to deal with the requirement 2.

What this example shows is that CREATE should really FALIGN its body,
otherwise we get cumbersome and inefficient use of FALIGN and
FALIGNED, like this:

: faccumulator ( r "name" -- )
  create falign f,
does> ( r1 -- r2 )
  faligned dup f@ f+ fdup f! ;

- anton
-- 
M. Anton Ertl  http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
     New standard: http://www.forth200x.org/forth200x.html
   EuroForth 2016: http://www.euroforth.org/ef16/

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


Thread

Rosetta Code: Accumulator factory "Robert L." <No_spamming@noWhere_7073.org> - 2017-01-17 09:00 +0000
  Re: Rosetta Code: Accumulator factory Paul Rubin <no.email@nospam.invalid> - 2017-01-17 01:38 -0800
    Re: Rosetta Code: Accumulator factory anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-01-17 13:54 +0000
      Re: Rosetta Code: Accumulator factory Paul Rubin <no.email@nospam.invalid> - 2017-01-17 13:10 -0800
        Re: Rosetta Code: Accumulator factory Andrew Haley <andrew29@littlepinkcloud.invalid> - 2017-01-18 03:15 -0600
        Re: Rosetta Code: Accumulator factory anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-01-18 13:43 +0000
          Re: Rosetta Code: Accumulator factory Paul Rubin <no.email@nospam.invalid> - 2017-01-18 13:20 -0800
            Re: Rosetta Code: Accumulator factory albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-01-19 02:40 +0100
            Re: Rosetta Code: Accumulator factory anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-01-19 16:27 +0000

csiph-web