Skip to content

Instantly share code, notes, and snippets.

Avatar

Hernán Rivas Acosta HernanRivasAcosta

  • Olympus Mons
View GitHub Profile
@HernanRivasAcosta
HernanRivasAcosta / gist:93d6384b69c208b73ecf
Last active Aug 29, 2015
Partial application in erlang!
View gist:93d6384b69c208b73ecf
partial_application(F, Args) ->
{arity, InitialArity} = erlang:fun_info(F, arity),
case length(Args) of
L when L < InitialArity ->
MissingArgs = [{var, 1, N} || N <- lists:seq(1, InitialArity - L)],
ArgList = [case is_function(A) of
false -> erl_parse:abstract(A);
true -> {var, 1, erlang:fun_to_list(A)}
end || A <- Args] ++ MissingArgs,
Parsed = [{'fun', 1,
@HernanRivasAcosta
HernanRivasAcosta / gist:948983b72becbd0ab1ce
Last active Sep 20, 2016
Parse transform to add partial application to erlang
View gist:948983b72becbd0ab1ce
-module(pt).
-export([parse_transform/2]).
parse_transform(ASTIn, _Options) ->
format(ASTIn).
format({call, Line, {atom, _, FName}, FixedArgs} = Call) ->
case handle_partial_application(FName, Line) of
undefined ->
format_tuple(Call);
@HernanRivasAcosta
HernanRivasAcosta / build.c
Last active Aug 29, 2015
Erlang dummy code generaor
View build.c
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef enum {NONE, WHITESPACE, BINARY, FUNCTIONS, CLAUSES} MODE;
int showHelp();
MODE getMode(const char *modeString, MODE *mode);
void writeFile(FILE *fd, MODE mode, int size);
const char *nameForMode(MODE mode);