Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #28448
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: Jensen's device (was: Rosetta Code: ...) |
| Date | 2014-02-15 13:36 +0000 |
| Organization | Institut fuer Computersprachen, Technische Universitaet Wien |
| Message-ID | <2014Feb15.143618@mips.complang.tuwien.ac.at> (permalink) |
| References | (2 earlier) <52fd0ac4$0$2922$e4fe514c@news2.news.xs4all.nl> <30dc37b6-5be5-4c68-a7c5-1aa3b1e67cfd@googlegroups.com> <52fde87f$0$2872$e4fe514c@news2.news.xs4all.nl> <2014Feb14.124846@mips.complang.tuwien.ac.at> <52fe3a54$0$2863$e4fe514c@news2.news.xs4all.nl> |
Hans Bezemer <the.beez.speaks@gmail.com> writes:
>Anton Ertl wrote:
>
>> Hans Bezemer <the.beez.speaks@gmail.com> writes:
>>>Take a look at http://rosettacode.org/wiki/Jensen%27s_Device#Forth
>>>
>>>I did it in two lines.
>>
>> These lines are:
>>
>> : sum 0 s>f 1+ swap ?do i over execute f+ loop drop ;
>> :noname s>f 1 s>f fswap f/ ; 1 100 sum f.
>>
>> Whereas the core of the original is:
>>
>> print (sum (i, 1, 100, 1/i))
>>
>> where the parameters are passed by name.
>>
>> However, you pass i to the :noname definition on the stack, not by
>> name. The following passes both i and 1/i as an xt:
>>
>> fvariable ii \ I is a Forth word that we need
>> : sum ( xt1 lo hi xt2 -- r )
>> 0e swap 1+ rot ?do ( addr xt r1 )
>> i s>f over execute f! dup execute f+
>> loop 2drop ;
>> ' ii 1 100 :noname 1e ii f@ f/ ; sum f.
>>
>> I have added it to the Rosettacode page.
>I see the point of your argument, but note the idea of Rosetta code is: how
>would you solve it in YOUR language.
It seems to me that the general Rosetta code idea is at odds with the
idea of the "Jensen's device" task then. The example is called
"Jensen's device", not "the 100th harmonic number", and the task
description says: "This task is an exercise in call by name.". Now it
seems to me that, for languages that don't have call-by-name, the task
is to do something that is relatively close to call-by-name, and
that's what I did.
If the task was just "the 100th harmonic number", the Forth solution
(following Chuck Moore's philosophy) is
.( 5.1873775...)
- 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 2013: http://www.euroforth.org/ef13/
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Rosetta Code: Top rank per group Julian Fondren <julian.fondren@gmail.com> - 2014-02-12 17:37 -0800
Re: Rosetta Code: Top rank per group "Rod Pemberton" <dont_use_email@xnohavenotit.cnm> - 2014-02-13 03:58 -0500
Re: Rosetta Code: Top rank per group Hans Bezemer <the.beez.speaks@gmail.com> - 2014-02-13 19:11 +0100
Re: Rosetta Code: Top rank per group Julian Fondren <julian.fondren@gmail.com> - 2014-02-13 12:08 -0800
Re: Rosetta Code: Top rank per group Hans Bezemer <the.beez.speaks@gmail.com> - 2014-02-14 10:57 +0100
Re: Rosetta Code: Top rank per group Paul Rubin <no.email@nospam.invalid> - 2014-02-14 02:50 -0800
Jensen's device (was: Rosetta Code: ...) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2014-02-14 11:48 +0000
Re: Jensen's device (was: Rosetta Code: ...) Hans Bezemer <the.beez.speaks@gmail.com> - 2014-02-14 16:46 +0100
Re: Jensen's device (was: Rosetta Code: ...) "Rod Pemberton" <dont_use_email@xnohavenotit.cnm> - 2014-02-14 11:30 -0500
Re: Jensen's device (was: Rosetta Code: ...) Hans Bezemer <the.beez.speaks@gmail.com> - 2014-02-14 23:35 +0100
Re: Jensen's device (was: Rosetta Code: ...) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2014-02-15 13:36 +0000
Re: Jensen's device (was: Rosetta Code: ...) albert@spenarnc.xs4all.nl (Albert van der Horst) - 2014-02-14 19:12 +0000
Re: Jensen's device (was: Rosetta Code: ...) mhx@iae.nl - 2014-02-14 12:13 -0800
Re: Jensen's device (was: Rosetta Code: ...) Hans Bezemer <the.beez.speaks@gmail.com> - 2014-02-14 23:47 +0100
Re: Jensen's device (was: Rosetta Code: ...) mhx@iae.nl - 2014-02-14 23:45 -0800
Re: Jensen's device (was: Rosetta Code: ...) mhx@iae.nl - 2014-02-15 02:49 -0800
Re: Jensen's device (was: Rosetta Code: ...) albert@spenarnc.xs4all.nl (Albert van der Horst) - 2014-02-15 11:54 +0000
Re: Rosetta Code: Top rank per group Hans Bezemer <the.beez.speaks@gmail.com> - 2014-02-13 23:20 +0100
Re: Rosetta Code: Top rank per group Andrew Haley <andrew29@littlepinkcloud.invalid> - 2014-02-13 04:11 -0600
Re: Rosetta Code: Top rank per group humptydumpty <ouatubi@gmail.com> - 2014-02-13 10:48 -0800
Re: Rosetta Code: Top rank per group humptydumpty <ouatubi@gmail.com> - 2014-02-13 20:23 -0800
csiph-web