Jensen's Device: Difference between revisions

Content added Content deleted
m (→‎{{header|Wren}}: Changed to Wren S/H)
(→‎{{header|Forth}}: replaced FVARIABLE ii with VARIABLE i1 (i is integer in the task description))
Line 733: Line 733:
The following version passes i and 1/i as execution tokens and is thus closer to the original, but less idiomatic:
The following version passes i and 1/i as execution tokens and is thus closer to the original, but less idiomatic:


<syntaxhighlight lang="forth">fvariable ii \ i is a Forth word that we need
<syntaxhighlight lang="forth">: sum ( i-xt lo hi term-xt -- r )
: sum ( xt1 lo hi xt2 -- r )
\ stack effects: i-xt ( -- addr ); term-xt ( -- r1 )
0e swap 1+ rot ?do ( addr xt r1 )
0e swap 1+ rot ?do ( r1 xt1 xt2 )
i s>f over execute f! dup execute f+
i 2 pick execute ! dup execute f+
loop 2drop ;
loop 2drop ;

' ii 1 100 :noname 1e ii f@ f/ ; sum f.</syntaxhighlight>
variable i1 \ avoid conflict with Forth word I
' i1 1 100 :noname 1e i1 @ s>f f/ ; sum f.</syntaxhighlight>


=={{header|Fortran}}==
=={{header|Fortran}}==