How to resolve the algorithm Partial function application step by step in the Sidef programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Partial function application step by step in the Sidef programming language

Table of Contents

Problem Statement

Partial function application   is the ability to take a function of many parameters and apply arguments to some of the parameters to create a new function that needs only the application of the remaining arguments to produce the equivalent of applying all arguments to the original function. E.g:

Note that in the partial application of a parameter, (in the above case param1), other parameters are not explicitly mentioned. This is a recurring feature of partial function application.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Partial function application step by step in the Sidef programming language

Source code in the sidef programming language

func fs(f) {
    func(*args) {
        args.map {f(_)}
    }
}

func double(n) { n  * 2 };
func square(n) { n ** 2 };

var fs_double = fs(double);
var fs_square = fs(square);

var s = (0 .. 3);
say "fs_double(#{s}): #{fs_double(s...)}";
say "fs_square(#{s}): #{fs_square(s...)}";

s = [2, 4, 6, 8];
say "fs_double(#{s}): #{fs_double(s...)}";
say "fs_square(#{s}): #{fs_square(s...)}";


  

You may also check:How to resolve the algorithm Write entire file step by step in the Ada programming language
You may also check:How to resolve the algorithm Reverse a string step by step in the C# programming language
You may also check:How to resolve the algorithm Run-length encoding step by step in the K programming language
You may also check:How to resolve the algorithm Doubly-linked list/Definition step by step in the Oberon-2 programming language
You may also check:How to resolve the algorithm Van der Corput sequence step by step in the MATLAB / Octave programming language