Skip to content

Instantly share code, notes, and snippets.

View shintakezou's full-sized avatar

Mauro Panigada shintakezou

View GitHub Profile
@shintakezou
shintakezou / lambdacpp11.cpp
Created March 30, 2012 21:16
lambda in C++11
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int main()
{
vector<int> array = {1, 2, 3, 4, 5};
@shintakezou
shintakezou / lambdaclisp.cl
Created March 30, 2012 21:19
fold left and lambda in common lisp
(reduce (lambda (x y) (+ x (* y 2))) '(1 2 3 4 5) :initial-value 0)
@shintakezou
shintakezou / lambdafoldl.hs
Created March 30, 2012 21:20
foldl and lambda
foldl (\x y -> x + y*2) 0 [1, 2, 3, 4, 5]
@shintakezou
shintakezou / foldll.erl
Created March 30, 2012 21:21
fold left and lambda
lists:foldl(fun(Y, X) -> X + Y*2 end, 0, [1,2,3,4,5]).
@shintakezou
shintakezou / reducell.pl
Created March 30, 2012 21:22
fold left and lambda
use List::Util qw(reduce);
my $r = reduce { $a + $b * 2 } 0, 1..5;
@shintakezou
shintakezou / reducell.py
Created March 30, 2012 21:23
fold left and lambda
reduce(lambda x, y: x + y*2, [1,2,3,4,5], 0)
@shintakezou
shintakezou / injectinto.st
Created March 30, 2012 21:24
fold left and closure(!)
#(1 2 3 4 5) inject: 0 into: [ :x :y | x + (y*2) ].
@shintakezou
shintakezou / noboilerlamb.cpp
Created March 30, 2012 21:25
fold left, lambda in C++11, no boilerplate code
accumulate(array.begin(),
array.end(), 0,
[](const int& x, const int& y) -> int { return x + y*2; })
@shintakezou
shintakezou / matrixfoo.c
Created March 30, 2012 21:27
old foo example
int foo()
{
matrix a = NULL, b = NULL, c = NULL;
matrix_ctx ctx = NULL;
matrix_start(ctx);
a = matrix_new(ctx, 1000, 1000);
b = matrix_new(ctx, 1000, 1000);
@shintakezou
shintakezou / rel-article.prolog
Created April 9, 2012 16:39
Modelling social relationships in Prolog
%{ knowledge starts from here
%% the database knows these people
person('Mary Brod').
person('Carl Stuckart').
person('Rudolf Fisher').
person('Amanda Least').
person('Minority Report').
%% when they are born
born('Mary Brod', date(1988, 3, 11)).