Jensen's Device: Difference between revisions

Content added Content deleted
(GP can't; PARI solution is C's)
Line 441: Line 441:
in
in
{Show {Sum 1 100 fun {$ I} 1.0/{Int.toFloat I} end}}</lang>
{Show {Sum 1 100 fun {$ I} 1.0/{Int.toFloat I} end}}</lang>

=={{header|PARI/GP}}==
GP does not have pass-by-reference semantics for user-generated functions, though some predefined functions do. PARI programming allows this, though such a solution would essentially be identical to the [[#C|C]] solution above.


=={{header|Perl}}==
=={{header|Perl}}==
Line 469: Line 472:
print sum($i, 1, 100, sub { 1 / $i }), "\n";</lang>
print sum($i, 1, 100, sub { 1 / $i }), "\n";</lang>
Output: 5.18737751763962
Output: 5.18737751763962

=={{header|Perl 6}}==
=={{header|Perl 6}}==
Rather than playing tricks like Perl&nbsp;5 does, the declarations of the formal parameters are quite straightforward in Perl&nbsp;6:
Rather than playing tricks like Perl&nbsp;5 does, the declarations of the formal parameters are quite straightforward in Perl&nbsp;6: