Name:

bind partially applies a procedure to an argument, returning a procedure with one argument less

Usage:

bind(proc, ident, obj) : (procedure, identifier type, any type) -> procedure

Parameters:

Description:

Example 1:

   > procedure add(X,Y) { return X + Y; };
   > succ = bind(add,X,1);
   > succ(5);
   6
   > succ;
   proc(Y)
   {
   nop;
   return (proc(X, Y)
   {
   nop;
   return (X) + (Y);
   })(1, Y);
   }

Example 2:

   > procedure add(X,Y) { return X + Y; };
   > succ = bind(add,X,1);
   > five = bind(succ,Y,4);
   > five();
   5
   > five;
   proc()
   {
   nop;
   return (proc(Y)
   {
   nop;
   return (proc(X, Y)
   {
   nop;
   return (X) + (Y);
   })(1, Y);
   })(4);
   }

Example 3:

   > verbosity = 1!;
   > procedure add(X,Y) { return X + Y; };
   > foo = bind(add,R,1);
   Warning: the given procedure has no argument named "R". The procedure is returned unchanged.
   > foo;
   proc(X, Y)
   {
   nop;
   return (X) + (Y);
   }

Example 4:

   > procedure sum_times(l=...) { var s, i; s = 0; for i in l do s = s + i; return c * s; };
   > foo = bind(sum_times, c, 17);
   > foo;
   proc(l = ...)
   {
   var c;
   c = 17;
   return (proc(l = ...)
   {
   var s, i;
   s = 0;
   for i in l do
   s = (s) + (i);
   return (c) * (s);
   }) @ (l);
   }
   > foo(1, 2, 3);
   102
See also: procedure, proc, function, @
Go back to the list of commands