Example #1
0
struct byteArray *K() {
    //i 0 = 0 S K
    // = K I S K
    // = I K
    // = K
    return iotaGen(ChurchZero());
}
Example #2
0
struct byteArray *ChurchZero() {
    //i I x y = I S K x y
    // = S K x y
    // = K y (x y)
    // = y
    //0 x y = y
    //i I = 0
    //K I x y = I y = y
    return iotaGen(I());
}
Example #3
0
struct byteArray *I() {
    //i i x = i S K x
    // = S S K K x
    // = S K (K K) x
    // = K x (K K x = K)
    // = x
    //i i x = x
    // && I x = x
    // => i i = I
    return iotaGen(tcPtr(iota));
}
Example #4
0
File: alg1.cpp Project: Quna/mspdev
// Illustrate the use of the generate and genrate_n functions.
void generate_example ()
{
    std::cout << "Illustrate generate algorithm\n";
    
    // Example 1, generate a std::list of label numbers.
    std::list<std::string, std::allocator<std::string> > labelList;
    
    std::generate_n (std::inserter (labelList, labelList.begin ()),
                     4, generateLabel);  
    std::copy (labelList.begin (), labelList.end (),
               str_ostrm_iter (std::cout, " "));
    
    std::cout << '\n';
    
    // Example 2, generate an arithmetic progression.
    std::vector<int, std::allocator<int> > iVec (10);
    
    std::generate (iVec.begin (), iVec.end (), iotaGen (2));
    std::generate_n (iVec.begin (), 5, iotaGen (7));
    std::copy (iVec.begin (), iVec.end (), int_ostrm_iter (std::cout, " "));
    
    std::cout << '\n';
}
Example #5
0
File: alg1.cpp Project: Quna/mspdev
// Illustrate the use of the fill and fill_n functions.
void fill_example ()
{
    std::cout << "Illustrate fill function\n";
    
    // Example 1, fill an array with initial values
    char buffer [100];
    char *bufferp = buffer;
    
    std::fill (bufferp, (bufferp + 100), '\0');
    std::fill_n (bufferp, 10, 'x');
    
    std::cout << buffer << '\n';
    
    // Example 2, use fill to initialize a std::list.
    std::list<std::string, std::allocator<std::string> > aList;
    
    std::fill_n (std::inserter (aList, aList.begin ()), 10, "empty");
    std::copy (aList.begin (), aList.end (),
               str_ostrm_iter (std::cout, " "));
    
    std::cout << '\n';
    
    // Example 3, use fill to overwrite values in a std::list.
    std::fill (aList.begin (), aList.end (), "full");
    std::copy (aList.begin (), aList.end (),
               str_ostrm_iter (std::cout, " "));
    
    std::cout << '\n';
    
    // Example 4, fill in a portion of a std::list.
    std::vector<int, std::allocator<int> > iVec (10);
    
    std::generate (iVec.begin (), iVec.end (), iotaGen (1));
    std::vector<int, std::allocator<int> >::iterator
        seven = std::find (iVec.begin (), iVec.end (), 7);
    std::fill (iVec.begin (), seven, 0);
    std::copy (iVec.begin (), iVec.end (), int_ostrm_iter (std::cout));
    
    std::cout << '\n';
}
Example #6
0
File: alg1.cpp Project: Quna/mspdev
// Illustrate the use of the algorithm swap_ranges.
void swap_example ()
{
    std::cout << "Illustrate swap_ranges algorithm\n";
    
    // First make two parallel sequences.
    int data[] = {12, 27, 14, 64}, *datap = data;
    std::vector<int, std::allocator<int> > aVec (4);
    
    std::generate (aVec.begin (), aVec.end (), iotaGen (1));
    
    // Illustrate swap and iter_swap.
    std::swap (data [0], data [2]);
    std::copy (data, data + 4, int_ostrm_iter (std::cout, " "));
    
    std::cout << '\n';
    
    std::vector<int, std::allocator<int> >::iterator last =
        aVec.end ();

    --last;
    
    std::iter_swap (aVec.begin (),  last);
    std::copy  (aVec.begin (), aVec.end (),
                int_ostrm_iter (std::cout, " "));
    
    std::cout << '\n';
    
    // Now swap the entire sequence.
    std::swap_ranges (aVec.begin (), aVec.end (), datap);
    std::copy (data, data+4, int_ostrm_iter (std::cout, " "));
    
    std::cout << '\n';
    
    std::copy (aVec.begin (), aVec.end (),
               int_ostrm_iter (std::cout, " "));
    
    std::cout << '\n';
}
Example #7
0
struct byteArray *S() {
    //i K = K S K
    // = S
    return iotaGen(K());
}