September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -0,0 +1,11 @@
function sumr(integer lo, hi, rid)
atom res = 0
for i=lo to hi do
res += call_func(rid,{i})
end for
return res
end function
function reciprocal(atom i) return 1/i end function
?sumr(1, 100, routine_id("reciprocal"))

View file

@ -1,12 +1,15 @@
/*REXX program demonstrates Jensen's device (via call subroutine, and args by name).*/
numeric digits 90 /*use 90 decimal digits (9 is default).*/
parse arg d .; if d=='' | d=="," then d=100 /*Not specified? Then use the default.*/
numeric digits d /*use D decimal digits (9 is default)*/
say 'using ' d " decimal digits:" /*display what's being used for digits.*/
say
say sum( 'i', "1", '100', "1/i" ) /*invoke SUM (100th harmonic number).*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
sum: procedure; parse arg j,start,finish,exp; $=0
sum: procedure; parse arg j,start,finish,exp; $=0
interpret 'do' j "=" start 'to' finish"; $=$+" exp '; end'
/* ──── ═ ─── ═════ ──── ══════────────── ═══ ───────── */
/* lit var lit var lit var literal var literal */
interpret 'do' j "=" start 'to' finish"; $=$+" exp '; end'
/* ──── ═ ─── ═════ ──── ══════────────── ═══ ───────── */
/* lit var lit var lit var literal var literal */
return $
return $

View file

@ -0,0 +1,23 @@
comment Jensen's Device;
begin
integer i;
real procedure sum (i, lo, hi, term);
name i, term;
value lo, hi;
integer i, lo, hi;
real term;
comment term is passed by-name, and so is i;
begin
integer j;
real temp;
temp := 0;
for j := lo step 1 until hi do
begin
i := j;
temp := temp + term
end;
sum := temp
end;
comment note the correspondence between the mathematical notation and the call to sum;
outreal (sum (i, 1, 100, 1/i), 7, 14)
end

View file

@ -0,0 +1,6 @@
fcn sum(ri, lo,hi, term){
temp:=0.0; ri.set(lo);
do{ temp+=term(ri); } while(ri.inc()<hi); // inc return previous value
return(temp);
}
sum(Ref(0), 1,100, fcn(ri){ 1.0/ri.value }).println();

View file

@ -0,0 +1,7 @@
fcn sum2(ri, lo,hi, term){
temp:=0.0; ri.set(lo);
do{ temp=term + temp; } while(ri.inc()<hi); // inc return previous value
return(temp);
}
ri:=Ref(0);
sum2(ri, 1,100, 'wrap(){ 1.0/ri.value }).println();

View file

@ -0,0 +1,2 @@
fcn sum3(lo,hi, term){ [lo..hi].reduce('wrap(sum,i){ sum + term(i) },0.0) }
sum3(1,100, fcn(i){ 1.0/i }).println();