Skip to content

Instantly share code, notes, and snippets.

View Baha's full-sized avatar

Adrian Palacios Baha

View GitHub Profile
@Baha
Baha / transform.erl
Created October 22, 2017 16:56
Core Erlang Metaprogramming example
-module(transform).
-export([main/1]).
main(File) ->
case compile:file(File, [to_core, binary, no_copt]) of
{ok, ModuleName, CoreForms} ->
TransForms = cerl_trees:map(fun replace_concat/1, CoreForms),
CoreName = atom_to_list(ModuleName) ++ ".core",
file:write_file(CoreName,
cerl_prettypr:format(TransForms));
@Baha
Baha / filtrado_lista.erl
Created January 20, 2016 14:11
Filtrado lista funciones
2> Name = resta.
resta
3> Lista = [{function,suma,3},{function,resta,5},{function,mult,4}].
[{function,suma,3},{function,resta,5},{function,mult,4}]
4> [FunctionName || Form = {function,FunctionName,_} <- Lista, FunctionName == Name].
[resta]
-module(receiver).
-export([main/0]).
main() -> receive
terminate -> io:fwrite("Receiver process finished\n")
end.
@Baha
Baha / Newpending definition.lhs
Created December 17, 2011 17:20
A well functioning definiton for the add function in a partial evaluator.
> add :: [(String,[Expr])] -> [(String,[Expr])] -> [(String,[Expr])] -> [(String,[Expr])]
>
> add succ pending marked = difference (union pending succ) marked
>
> union pending [] = pending
> union pending (call:res)
> | elem call pending = union pending res
> | otherwise = union (call:pending) res
>
> difference pend marked = [x | x <- pend, not (elem x marked)]
@Baha
Baha / C - toUpper function
Created October 4, 2011 17:45
A gist for a toUpper function written in C
p1 = cadena1;
p2 = cadena2;
for (int i = 0; i < strlen(cadena1); i++)
{
if (*p1 > 'a' && *p1 < 'z')
*p2 = *p1 + ('A' - 'a');
else *p2 = *p1;
p1++;
p2++;