Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -0,0 +1,28 @@
begin
% record type to hold a singly linked list of integers %
record ListI ( integer iValue; reference(ListI) next );
% inserts a new value after the specified element of a list %
procedure insert( reference(ListI) value list
; integer value newValue
) ;
next(list) := ListI( newValue, next(list) );
% declare variables to hold the list %
reference(ListI) head, pos;
% create a list of integers %
head := ListI( 1701, ListI( 9000, ListI( 42, ListI( 90210, null ) ) ) );
% insert a new value into the list %
insert( next(head), 4077 );
% traverse the list %
pos := head;
while pos not = null do begin
write( iValue(pos) );
pos := next(pos);
end;
end.

View file

@ -0,0 +1,9 @@
#include <iostream>
#include <forward_list>
int main()
{
std::forward_list<int> list{1, 2, 3, 4, 5};
for (int e : list)
std::cout << e << std::endl;
}

View file

@ -0,0 +1,46 @@
var map = function (fn, list) {
return list.map(fn);
},
foldr = function (fn, acc, list) {
var listr = list.slice();
listr.reverse();
return listr.reduce(fn, acc);
},
traverse = function (list, fn) {
return list.forEach(fn);
};
var range = function (m, n) {
return Array.apply(null, Array(n - m + 1)).map(
function (x, i) {
return m + i;
}
);
};
// --> [false, false, false, false, false, true, true, true, true, true]
map(function (x) {
return x > 5;
}, range(1, 10));
// --> ["Apples", "Oranges", "Mangos", "Pears"]
map(function (x) {
return x + 's';
}, ["Apple", "Orange", "Mango", "Pear"])
// --> 55
foldr(function (acc, x) {
return acc + x;
}, 0, range(1, 10))
traverse(["Apple", "Orange", "Mango", "Pear"], function (x) {
console.log(x);
})
/* Apple */
/* Orange */
/* Mango */
/* Pear */