├── .gitignore ├── AUTHORS ├── CHANGELOG ├── LICENSE ├── Makefile ├── README.md ├── doc └── Readme ├── ebin └── Readme ├── edd_comp.erl ├── examples ├── 24_game │ ├── Readme │ ├── dbg.pdf │ ├── dbg_zoom.pdf │ ├── g24.erl │ ├── g24_ok.erl │ ├── session.txt │ └── session_zoom.txt ├── Concurrency │ ├── Producer-Consumer-Problem │ │ ├── buffer.erl │ │ ├── comm_seq_diag.pdf │ │ ├── consumer.erl │ │ ├── eval_tree.pdf │ │ ├── item.erl │ │ ├── master.erl │ │ ├── pids_tree.pdf │ │ ├── producer.erl │ │ └── session.txt │ ├── mapreduce │ │ ├── comm_seq_diag.pdf │ │ ├── eval_tree.pdf │ │ ├── mapreduce.erl │ │ └── session.txt │ ├── mergesort │ │ ├── comm_seq_diag.pdf │ │ ├── eval_tree.pdf │ │ ├── mergesort.core │ │ ├── mergesort.erl │ │ ├── pids_tree.pdf │ │ └── session.txt │ ├── philosophers │ │ ├── comm_seq_diag.pdf │ │ ├── eval_tree.pdf │ │ ├── philosophers.erl │ │ ├── pids_tree.pdf │ │ └── session.txt │ ├── poolboy │ │ ├── bug1 │ │ │ ├── bug1.txt │ │ │ ├── bug1_alternative.txt │ │ │ ├── comm_seq_diag.pdf │ │ │ ├── eval_tree.pdf │ │ │ └── pids_tree.pdf │ │ ├── bug2 │ │ │ ├── bug2.txt │ │ │ ├── bug2_alternative.txt │ │ │ ├── comm_seq_diag.pdf │ │ │ ├── eval_tree.pdf │ │ │ └── pids_tree.pdf │ │ ├── bug3 │ │ │ ├── bug3.txt │ │ │ ├── comm_seq_diag.pdf │ │ │ ├── eval_tree.pdf │ │ │ └── pids_tree.pdf │ │ ├── bug4 │ │ │ ├── bug4.txt │ │ │ ├── comm_seq_diag.pdf │ │ │ ├── eval_tree.pdf │ │ │ └── pids_tree.pdf │ │ ├── main.erl │ │ ├── poolboy.erl │ │ ├── poolboy_sup.erl │ │ └── poolboy_test_worker.erl │ └── tcp │ │ ├── session1 │ │ ├── comm_seq_diag.pdf │ │ ├── eval_tree.pdf │ │ ├── pids_tree.pdf │ │ └── session1.txt │ │ ├── session2 │ │ ├── comm_seq_diag.pdf │ │ ├── eval_tree.pdf │ │ ├── pids_tree.pdf │ │ └── session2.txt │ │ └── tcp.erl ├── Unified_Framework │ ├── 24_game │ │ ├── README.md │ │ ├── g24_ok.erl │ │ ├── no_tests │ │ │ ├── colors.dot │ │ │ ├── dbg.dot │ │ │ ├── dbg.pdf │ │ │ └── g24.erl │ │ ├── session.txt │ │ └── tests │ │ │ ├── colors.dot │ │ │ ├── dbg.dot │ │ │ ├── dbg.pdf │ │ │ └── g24.erl │ ├── ackermann │ │ ├── README.md │ │ ├── ackermann_ok.erl │ │ ├── no_tests │ │ │ ├── ackermann.erl │ │ │ ├── colors.dot │ │ │ ├── dbg.dot │ │ │ └── dbg.pdf │ │ ├── session.txt │ │ └── tests │ │ │ └── ackermann.erl │ ├── align_cols │ │ ├── README.md │ │ ├── align_columns_ok.erl │ │ ├── no_tests │ │ │ ├── align_columns.erl │ │ │ ├── colors.dot │ │ │ ├── dbg.dot │ │ │ └── dbg.pdf │ │ ├── session.txt │ │ └── tests │ │ │ ├── align_columns.erl │ │ │ ├── colors.dot │ │ │ ├── dbg.dot │ │ │ └── dbg.pdf │ ├── caesar │ │ ├── README.md │ │ ├── caesar_ok.erl │ │ ├── no_tests │ │ │ ├── caesar.erl │ │ │ ├── colors.dot │ │ │ ├── dbg.dot │ │ │ └── dbg.pdf │ │ ├── session.txt │ │ └── tests │ │ │ ├── caesar.erl │ │ │ ├── colors.dot │ │ │ ├── dbg.dot │ │ │ └── dbg.pdf │ ├── complex │ │ ├── README.md │ │ ├── complex_number_ok.erl │ │ ├── no_tests │ │ │ ├── colors.dot │ │ │ ├── complex_number.erl │ │ │ ├── dbg.dot │ │ │ └── dbg.pdf │ │ ├── session.txt │ │ └── tests │ │ │ ├── colors.dot │ │ │ ├── complex_number.erl │ │ │ ├── dbg.dot │ │ │ └── dbg.pdf │ ├── dutch │ │ ├── README.md │ │ ├── dutch_ok.erl │ │ ├── no_tests │ │ │ ├── colors.dot │ │ │ ├── dbg.dot │ │ │ ├── dbg.pdf │ │ │ └── dutch.erl │ │ ├── session.txt │ │ └── tests │ │ │ ├── colors.dot │ │ │ ├── dbg.dot │ │ │ ├── dbg.pdf │ │ │ └── dutch.erl │ ├── mergesort │ │ ├── no_tests │ │ │ ├── colors.dot │ │ │ ├── dbg.dot │ │ │ ├── dbg.pdf │ │ │ └── mergesort.erl │ │ ├── session.txt │ │ └── tests │ │ │ ├── colors.dot │ │ │ ├── dbg.dot │ │ │ ├── dbg.pdf │ │ │ └── mergesort.erl │ ├── miller_rabin │ │ ├── README.md │ │ ├── miller_rabin_ok.erl │ │ ├── no_tests │ │ │ ├── colors.dot │ │ │ ├── dbg.dot │ │ │ ├── dbg.pdf │ │ │ └── miller_rabin.erl │ │ ├── session.txt │ │ └── tests │ │ │ ├── colors.dot │ │ │ ├── dbg.dot │ │ │ ├── dbg.pdf │ │ │ └── miller_rabin.erl │ ├── rfib │ │ ├── README.md │ │ ├── no_tests │ │ │ ├── colors.dot │ │ │ ├── dbg.dot │ │ │ ├── dbg.pdf │ │ │ └── rfib.erl │ │ ├── rfib_ok.erl │ │ ├── session.txt │ │ └── tests │ │ │ ├── colors.dot │ │ │ ├── dbg.dot │ │ │ ├── dbg.pdf │ │ │ └── rfib.erl │ ├── rle │ │ ├── README.md │ │ ├── no_tests │ │ │ ├── colors.dot │ │ │ ├── dbg.dot │ │ │ ├── dbg.pdf │ │ │ └── rle.erl │ │ ├── rle_ok.erl │ │ ├── session.txt │ │ └── tests │ │ │ ├── colors.dot │ │ │ ├── dbg.dot │ │ │ ├── dbg.pdf │ │ │ └── rle.erl │ ├── roman │ │ ├── README.md │ │ ├── no_tests │ │ │ ├── colors.dot │ │ │ ├── dbg.dot │ │ │ ├── dbg.pdf │ │ │ └── roman.erl │ │ ├── roman_ok.erl │ │ ├── session.txt │ │ └── tests │ │ │ ├── colors.dot │ │ │ ├── dbg.dot │ │ │ ├── dbg.pdf │ │ │ └── roman.erl │ ├── sieve │ │ ├── README.md │ │ ├── no_tests │ │ │ ├── colors.dot │ │ │ ├── dbg.dot │ │ │ ├── dbg.pdf │ │ │ └── sieve.erl │ │ ├── session.txt │ │ ├── sieve_ok.erl │ │ └── tests │ │ │ ├── colors.dot │ │ │ ├── dbg.dot │ │ │ ├── dbg.pdf │ │ │ └── sieve.erl │ ├── stock │ │ ├── README.md │ │ ├── no_tests │ │ │ ├── colors.dot │ │ │ ├── dbg.dot │ │ │ ├── dbg.pdf │ │ │ └── stock.erl │ │ ├── session.txt │ │ ├── stock_ok.erl │ │ └── tests │ │ │ ├── colors.dot │ │ │ ├── dbg.dot │ │ │ ├── dbg.pdf │ │ │ └── stock.erl │ ├── sum_digits │ │ ├── README.md │ │ ├── no_tests │ │ │ ├── colors.dot │ │ │ ├── dbg.dot │ │ │ ├── dbg.pdf │ │ │ └── sum_digits.erl │ │ ├── session.txt │ │ ├── sum_digits_ok.erl │ │ └── tests │ │ │ ├── colors.dot │ │ │ ├── dbg.dot │ │ │ ├── dbg.pdf │ │ │ └── sum_digits.erl │ ├── ternary │ │ ├── README.md │ │ ├── no_tests │ │ │ ├── colors.dot │ │ │ ├── dbg.dot │ │ │ ├── dbg.pdf │ │ │ └── ternary.erl │ │ ├── session.txt │ │ ├── ternary_ok.erl │ │ └── tests │ │ │ ├── colors.dot │ │ │ ├── dbg.dot │ │ │ ├── dbg.pdf │ │ │ └── ternary.erl │ ├── turing │ │ ├── README.md │ │ ├── no_tests │ │ │ ├── colors.dot │ │ │ ├── dbg.dot │ │ │ ├── dbg.pdf │ │ │ └── turing.erl │ │ ├── session.txt │ │ ├── tests │ │ │ ├── colors.dot │ │ │ ├── dbg.dot │ │ │ ├── dbg.pdf │ │ │ └── turing.erl │ │ └── turing_ok.erl │ └── vigenere │ │ ├── README.md │ │ ├── no_tests │ │ └── vigenere.erl │ │ ├── session.txt │ │ ├── tests │ │ └── vigenere.erl │ │ └── vigenere_ok.erl ├── ackermann │ ├── Readme │ ├── ackermann.erl │ ├── ackermann_ok.erl │ ├── dbg.pdf │ └── session.txt ├── align_columns │ ├── Readme │ ├── align_columns.erl │ ├── align_columns_ok.erl │ ├── dbg.pdf │ ├── dbg_zoom.pdf │ ├── session.txt │ └── session_zoom.txt ├── caesar │ ├── Readme │ ├── caesar.erl │ ├── caesar_ok.erl │ ├── dbg.pdf │ ├── dbg_zoom.pdf │ ├── session.txt │ └── session_zoom.txt ├── complex_number │ ├── Readme │ ├── complex_number.erl │ ├── complex_number_ok.erl │ ├── dbg.pdf │ ├── dbg_zoom.pdf │ ├── session.txt │ └── session_zoom.txt ├── dns │ ├── Readme │ └── session.txt ├── dutch │ ├── Readme │ ├── dbg.pdf │ ├── dutch.erl │ ├── dutch_ok.erl │ └── session.txt ├── erlson_1 │ ├── Readme │ └── session.txt ├── erlson_2 │ ├── Readme │ └── session.txt ├── etorrent │ ├── Readme │ └── session.txt ├── io_lib_format │ ├── Readme │ ├── dbg.pdf │ ├── dbg_zoom.pdf │ ├── io_lib_format_old.erl │ └── session.txt ├── luerl_1 │ ├── Readme │ └── session.txt ├── luerl_2 │ ├── Readme │ └── session.txt ├── luerl_3 │ ├── Readme │ └── session.txt ├── mergesort │ ├── dbg.pdf │ ├── dbg_zoom.pdf │ ├── merge.erl │ └── merge_ok.erl ├── miller_rabin │ ├── Readme │ ├── dbg.pdf │ ├── dbg_zoom.pdf │ ├── miller_rabin.erl │ ├── miller_rabin_ok.erl │ ├── session.txt │ └── session_zoom.txt ├── queue │ ├── Readme │ ├── dbg.pdf │ ├── dbg_zoom.pdf │ ├── queue.erl │ ├── queue_ok.erl │ └── session.txt ├── quicksort │ ├── Readme │ ├── bug1_tree.pdf │ ├── bug2_tree.pdf │ ├── dbg.dot │ └── quicksort.erl ├── quicksort_proper │ └── quicksort.erl ├── random │ ├── Readme │ └── session.txt ├── rat │ ├── rat.erl │ └── rat_eqc.erl ├── redbug_msc │ ├── Readme │ └── session.txt ├── rfib │ ├── Readme │ ├── dbg.pdf │ ├── rfib.erl │ ├── rfib_ok.erl │ └── session.txt ├── rle │ ├── Readme │ ├── dbg.pdf │ ├── dbg_zoom.pdf │ ├── rle.erl │ ├── rle_ok.erl │ ├── session.txt │ └── session_zoom.txt ├── roman │ ├── Readme │ ├── dbg.pdf │ ├── dbg_zoom.pdf │ ├── roman.erl │ ├── roman_ok.erl │ ├── session.txt │ └── session_zoom.txt ├── sieve_module │ ├── Readme │ ├── dbg.pdf │ ├── dbg_zoom.pdf │ ├── session.txt │ ├── session_zoom.txt │ ├── sieve_module.erl │ └── sieve_module_ok.erl ├── stock │ ├── Readme │ ├── dbg.pdf │ ├── dbg_zoom.pdf │ ├── session.txt │ ├── stock.erl │ └── stock_ok.erl ├── sum_digits │ ├── Readme │ ├── dbg.pdf │ ├── dbg_zoom.pdf │ ├── session.txt │ ├── session_zoom.txt │ ├── sum_digits.erl │ └── sum_digits_ok.erl ├── ternary │ ├── Readme │ ├── dbg.pdf │ ├── dbg_zoom.pdf │ ├── session.txt │ ├── session_zoom.txt │ ├── ternary.erl │ └── ternary_ok.erl ├── turing │ ├── Readme │ ├── dbg.pdf │ ├── dbg_zoom.pdf │ ├── session.txt │ ├── session_zoom.txt │ ├── turing.erl │ └── turing_ok.erl └── vigenere │ ├── Readme │ ├── dbg.pdf │ ├── session.txt │ ├── vigenere.erl │ └── vigenere_ok.erl ├── java ├── EDDJInterface.java ├── README.md └── load_erlang_server.sh └── src ├── edd.erl ├── edd_client.erl ├── edd_con.erl ├── edd_con.hrl ├── edd_con_lib.erl ├── edd_con_pt.erl ├── edd_jserver.erl ├── edd_lib.erl ├── edd_proper_reader.erl ├── edd_server.erl ├── edd_tcp.erl ├── edd_test_reader.erl ├── edd_test_writer.erl ├── edd_trace.erl ├── edd_trusted_rw.erl ├── edd_zoom.erl ├── edd_zoom_lib.erl ├── mochijson.erl └── smerl.erl /.gitignore: -------------------------------------------------------------------------------- 1 | colors.pdf 2 | *.bak 3 | examples/Unified_Framework/*/*.dot 4 | *~ 5 | .DS_Store 6 | *.beam 7 | 8 | *.html 9 | 10 | doc/edoc-info 11 | 12 | doc/erlang.png 13 | 14 | *.css 15 | 16 | *.dump 17 | 18 | *.class 19 | 20 | mails/* 21 | 22 | test.erl 23 | 24 | examples/mergesort/dbg_zoom.dot 25 | 26 | examples/mergesort/dbg.dot 27 | 28 | *.core 29 | 30 | examples/stock/dbg_zoom.dot 31 | 32 | examples/stock/dbg.dot 33 | 34 | examples/tcp/dbg.dot 35 | 36 | src/edd_con_lib_just_in_case.erl 37 | 38 | examples/tcp/tcp_mod.erl 39 | 40 | src/prova* 41 | src/test_pt.erl 42 | 43 | src/tcp.erl 44 | 45 | examples/test_reader/* 46 | 47 | examples/tcp/prova.pdf 48 | 49 | examples/tcp/prova.dot 50 | 51 | src/edd_con.erl 52 | 53 | examples/tcp/comm_seq_diag.dot 54 | 55 | examples/tcp/comm_seq_diag.pdf 56 | 57 | examples/tcp/pids_tree.dot 58 | 59 | examples/tcp/pids_tree.pdf 60 | 61 | examples/tcp/eval_tree.pdf 62 | 63 | examples/tcp/eval_tree.dot 64 | 65 | pids_tree.pdf 66 | 67 | pids_tree.dot 68 | 69 | 70 | examples/quicksort/quicksort.erl 71 | 72 | examples/quicksort/dbg.pdf 73 | 74 | eval_tree.pdf 75 | 76 | eval_tree.dot 77 | 78 | 79 | examples/tcp/comm_seq_diag2.dot 80 | 81 | comm_seq_diag.pdf 82 | 83 | comm_seq_diag.dot 84 | 85 | run_examples.txt 86 | 87 | examples/quicksort_proper/dbg.pdf 88 | 89 | examples/quicksort_proper/dbg.dot 90 | 91 | examples/rat/dbg.pdf 92 | 93 | examples/rat/dbg.dot 94 | 95 | examples/quicksort_proper/edd_temp.erl 96 | 97 | examples/quicksort_proper/colors.pdf 98 | 99 | examples/quicksort_proper/colors.dot 100 | 101 | examples/rat/colors.dot 102 | 103 | examples/rat/colors.pdf 104 | 105 | *result.txt 106 | 107 | philosophers.erl 108 | 109 | *.merge 110 | 111 | *.core_old 112 | 113 | pc/*.erl 114 | 115 | mapreduce.erl 116 | 117 | tcp.erl 118 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Main Author: 2 | Salvador Tamarit 3 | 4 | Contributors: 5 | Rafael Caballero 6 | Enrique Martin-Martin 7 | Adrián Riesco 8 | -------------------------------------------------------------------------------- /CHANGELOG: -------------------------------------------------------------------------------- 1 | 2013/02/01 2 | ========== 3 | [version 0.1] 4 | * Initial release: Erlang Declarative Debugger for a sequential subset of the 5 | Erlang language. 6 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Compiles Erlang Declarative Debugger source files and edoc 2 | 3 | all: 4 | erlc edd_comp.erl 5 | erl -run edd_comp compile -noshell -s erlang halt 6 | 7 | load: 8 | erl -run edd_comp load -rsh ssh -sname edd_main -setcookie edd_cookie 9 | 10 | # --- remove compiled beam and edoc 11 | clean: 12 | rm ebin/*.beam doc/*.png doc/*.css doc/*.html doc/edoc-info 13 | -------------------------------------------------------------------------------- /doc/Readme: -------------------------------------------------------------------------------- 1 | Directory 'doc' to contain HTML edoc documentation 2 | -------------------------------------------------------------------------------- /ebin/Readme: -------------------------------------------------------------------------------- 1 | Directory 'ebin' to contain compiled binaries 2 | -------------------------------------------------------------------------------- /examples/24_game/Readme: -------------------------------------------------------------------------------- 1 | 24 game 2 | http://rosettacode.org/wiki/24_game 3 | -------------------------------------------------------------------------------- /examples/24_game/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/24_game/dbg.pdf -------------------------------------------------------------------------------- /examples/24_game/dbg_zoom.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/24_game/dbg_zoom.pdf -------------------------------------------------------------------------------- /examples/24_game/g24_ok.erl: -------------------------------------------------------------------------------- 1 | %edd:dd("g24:test([9,2,2,3],\"(9*2)+(2*3)\")"). 2 | -module(g24_ok). 3 | -export([main/0,test/2,correct_nums/2]). 4 | 5 | 6 | test(Digts,Exp) -> 7 | io:format("Your digits\t~w~n", [Digts]), 8 | io:format("Your expression\t~p~n", [Exp]), 9 | read_eval(Digts,Exp). 10 | 11 | main() -> 12 | random:seed(now()), 13 | io:format("24 Game~n"), 14 | play(). 15 | 16 | play() -> 17 | io:format("Generating 4 digits...~n"), 18 | Digts = [random:uniform(X) || X <- [9,9,9,9]], 19 | io:format("Your digits\t~w~n", [Digts]), 20 | Exp = string:strip(io:get_line(standard_io, "Your expression: "), both, $\n), 21 | read_eval(Digts,Exp), 22 | play(). 23 | 24 | read_eval(Digits,Exp) -> 25 | case {correct_nums(Exp, Digits), eval(Exp)} of 26 | {ok, X} when X == 24 -> io:format("You Win!~n"), {win, X} ; 27 | {ok, X} -> io:format("You Lose with ~p!~n",[X]), {lose, X}; 28 | {List, _} -> io:format("The following numbers are wrong: ~p~n", [List]), 29 | {invalid_chars, List} 30 | end. 31 | 32 | correct_nums(Exp, Digits) -> 33 | case re:run(Exp, "([0-9]+)", [global, {capture, all_but_first, list}]) of 34 | nomatch -> 35 | "No number entered"; 36 | {match, IntLs} -> 37 | case [X || [X] <- IntLs, not lists:member(list_to_integer(X), Digits)] of 38 | [] -> ok; 39 | L -> L 40 | end 41 | end. 42 | 43 | eval(Exp) -> 44 | {X, _} = eval(re:replace(Exp, "\\s", "", [{return, list},global]), 45 | 0), 46 | X. 47 | 48 | eval([], Val) -> 49 | {Val,[]}; 50 | eval([$(|Rest], Val) -> 51 | {NewVal, Exp} = eval(Rest, Val), 52 | eval(Exp, NewVal); 53 | eval([$)|Rest], Val) -> 54 | {Val, Rest}; 55 | eval([$[|Rest], Val) -> 56 | {NewVal, Exp} = eval(Rest, Val), 57 | eval(Exp, NewVal); 58 | eval([$]|Rest], Val) -> 59 | {Val, Rest}; 60 | eval([$+|Rest], Val) -> 61 | {NewOperand, Exp} = eval(Rest, 0), 62 | eval(Exp, Val + NewOperand); 63 | eval([$-|Rest], Val) -> 64 | {NewOperand, Exp} = eval(Rest, 0), 65 | eval(Exp, Val - NewOperand); 66 | eval([$*|Rest], Val) -> 67 | {NewOperand, Exp} = eval(Rest, 0), 68 | eval(Exp, Val * NewOperand); 69 | eval([$/|Rest], Val) -> 70 | {NewOperand, Exp} = eval(Rest, 0), 71 | eval(Exp, Val / NewOperand); 72 | eval([X|Rest], 0) when X >= $1, X =< $9 -> 73 | eval(Rest, X-$0). 74 | -------------------------------------------------------------------------------- /examples/24_game/session.txt: -------------------------------------------------------------------------------- 1 | > edd:dd("g24:test([9,2,2,3],\"(9*2)+(2*3)\")"). 2 | Your digits [9,2,2,3] 3 | Your expression "(9*2)+(2*3)" 4 | The following numbers are wrong: [] 5 | Total number of tree nodes: 19 6 | Tree size: 7 | 3759 words 8 | 30072 bytes 9 | 10 | You Lose with 12! 11 | Please, insert a list of trusted functions [m1:f1/a1, m2:f2/a2 ...]: 12 | g24:eval("+(2*3)", 18) = {12, []}? [y/n/t/d/i/s/u/a]: n 13 | g24:eval("*3)", 2) = {6, []}? [y/n/t/d/i/s/u/a]: y 14 | g24:eval("(2*3)", 0) = {6, []}? [y/n/t/d/i/s/u/a]: y 15 | g24:eval([], 12) = {12, []}? [y/n/t/d/i/s/u/a]: y 16 | Call to a function that contains an error: 17 | g24:eval("+(2*3)", 18) = {12, []} 18 | Please, revise the sixth clause: 19 | eval([$+ | Rest], Val) -> 20 | {NewOperand, Exp} = eval(Rest, 0), 21 | eval(Exp, Val - NewOperand). 22 | -------------------------------------------------------------------------------- /examples/Concurrency/Producer-Consumer-Problem/buffer.erl: -------------------------------------------------------------------------------- 1 | -module(buffer). 2 | -export([init/1, listen/3, output/1]). 3 | 4 | init(MaxSize) -> 5 | io:format("Buffer created~n"), 6 | %MaxSize = 10, 7 | BufferArray = [], 8 | ItemId_Prod = 1, 9 | listen(MaxSize, BufferArray, ItemId_Prod). 10 | 11 | listen(MaxSize, BufferArray, ItemId_Prod) -> 12 | receive 13 | 14 | {available, From, Item, Prod_Id} -> 15 | if length(BufferArray) < MaxSize -> 16 | %Item ! {assignId, ItemId_Prod}, 17 | NewBufferArray = lists:append(BufferArray, [Item]), 18 | From ! putItem, 19 | io:format("Producer ~w inserted item ~w. There are ~w items in buffer.~n", [Prod_Id, ItemId_Prod, length(NewBufferArray)]), 20 | output(NewBufferArray), 21 | listen(MaxSize, NewBufferArray, ItemId_Prod + 1); 22 | true -> 23 | From ! full, 24 | listen(MaxSize, BufferArray, ItemId_Prod) 25 | end; 26 | 27 | {occupied, From, Cons_Id} -> 28 | if length(BufferArray) > 0 -> 29 | [Item | NewBufferArray] = BufferArray, 30 | ItemId_Cons = Item, 31 | From ! removeItem, 32 | io:format("Consumer ~w removed item ~w. There are ~w items in buffer.~n", [Cons_Id, ItemId_Cons, length(NewBufferArray)]), 33 | output(NewBufferArray), 34 | listen(MaxSize, NewBufferArray, ItemId_Prod); 35 | true -> 36 | From ! empty, 37 | listen(MaxSize, BufferArray, ItemId_Prod) 38 | end 39 | 40 | end. 41 | 42 | 43 | 44 | output(Buffer) -> 45 | io:format("Buffer: ["), 46 | fnl(Buffer). 47 | 48 | 49 | fnl([H]) -> 50 | % io:format("~w]~n", [getItemId(H)]); 51 | io:format("~w]~n", [H]); 52 | fnl([H|T]) -> 53 | % io:format("~w, ", [getItemId(H)]), 54 | io:format("~w, ", [H]), 55 | fnl(T); 56 | fnl([]) -> 57 | io:format("]~n"). 58 | -------------------------------------------------------------------------------- /examples/Concurrency/Producer-Consumer-Problem/comm_seq_diag.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Concurrency/Producer-Consumer-Problem/comm_seq_diag.pdf -------------------------------------------------------------------------------- /examples/Concurrency/Producer-Consumer-Problem/consumer.erl: -------------------------------------------------------------------------------- 1 | -module(consumer). 2 | -export([init/3]). 3 | 4 | -define(WAITING_CONSUMER, 10). 5 | 6 | init(Buffer, Cons_Id, TimesC) -> 7 | io:format("Consumer number ~w created~n",[Cons_Id]), 8 | listen(Buffer, Cons_Id, TimesC). 9 | 10 | listen(Buffer, Cons_Id, TimesC) when TimesC > 0 -> 11 | timer:sleep(rand:uniform(5)*?WAITING_CONSUMER), 12 | Buffer ! {occupied, self(), Cons_Id}, 13 | receive 14 | empty -> 15 | io:format("Consumer ~w tried to remove item. But buffer is empty. ~n", [Cons_Id]), 16 | listen(Buffer, Cons_Id, TimesC); 17 | removeItem -> 18 | %listen(Buffer, Cons_Id, TimesC - 1) %% OK 19 | listen(Buffer, Cons_Id, TimesC - 2) %% BUG 20 | end; 21 | listen(_Buffer, Cons_Id, _TimesC) -> 22 | io:format("Consumer number ~w finished~n",[Cons_Id]). 23 | -------------------------------------------------------------------------------- /examples/Concurrency/Producer-Consumer-Problem/eval_tree.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Concurrency/Producer-Consumer-Problem/eval_tree.pdf -------------------------------------------------------------------------------- /examples/Concurrency/Producer-Consumer-Problem/item.erl: -------------------------------------------------------------------------------- 1 | -module(item). 2 | -export([init/0]). 3 | 4 | init() -> 5 | listen(0). 6 | 7 | listen(Id) -> 8 | receive 9 | {assignId, ItemId} -> 10 | listen(ItemId); 11 | {From, getId} -> 12 | From ! {itemid, Id}, 13 | listen(Id) 14 | end. 15 | -------------------------------------------------------------------------------- /examples/Concurrency/Producer-Consumer-Problem/master.erl: -------------------------------------------------------------------------------- 1 | %% Obtained from https://github.com/NachiketUN/Producer-Consumer-Problem 2 | %% Modified to be terminating 3 | 4 | -module(master). 5 | -export([init/1, init/5]). 6 | 7 | % benchmark function 8 | init(N) -> 9 | init(N, N, N, 2, 2). 10 | 11 | init(MaxSize, NP, NC, TimesP, TimesC) -> 12 | %% Assume that (NP * TimesP) = (NC * TimesC) 13 | Buffer = spawn(fun() -> buffer:init(MaxSize) end), 14 | start_prod(1, NP, TimesP, Buffer), 15 | start_cons(1, NC, TimesC, Buffer). 16 | 17 | start_prod(Prod_Id, Num_Prod, TimesP, Buffer) when Prod_Id =< Num_Prod -> 18 | spawn(fun() -> producer:init(Buffer, Prod_Id, TimesP) end), 19 | start_prod(Prod_Id + 1, Num_Prod, TimesP, Buffer); 20 | start_prod(_Prod_Id, _Num_Prod, _TimesP, _Buffer) -> 21 | ok. 22 | 23 | start_cons(Cons_Id, Num_Cons, TimesC, Buffer) when Cons_Id =< Num_Cons -> 24 | spawn(fun() -> consumer:init(Buffer, Cons_Id, TimesC) end), 25 | start_cons(Cons_Id + 1, Num_Cons, TimesC, Buffer); 26 | start_cons(_Cons_Id, _Num_Prod, _TimesP, _Buffer) -> 27 | ok. 28 | -------------------------------------------------------------------------------- /examples/Concurrency/Producer-Consumer-Problem/pids_tree.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Concurrency/Producer-Consumer-Problem/pids_tree.pdf -------------------------------------------------------------------------------- /examples/Concurrency/Producer-Consumer-Problem/producer.erl: -------------------------------------------------------------------------------- 1 | -module(producer). 2 | -export([init/3]). 3 | 4 | -define(WAITING_PRODUCER, 10). 5 | 6 | init(Buffer, Prod_Id, TimesP) -> 7 | io:format("Producer number ~w created~n",[Prod_Id]), 8 | listen(Buffer, Prod_Id, TimesP). 9 | 10 | listen(Buffer, Prod_Id, TimesP) when TimesP > 0 -> 11 | timer:sleep(rand:uniform(5)*?WAITING_PRODUCER), 12 | %Item = spawn(fun() -> item:init() end), 13 | Item = {item, Prod_Id, TimesP}, % Generates Item 14 | Buffer ! {available, self(), Item, Prod_Id}, 15 | receive 16 | full -> 17 | io:format("Producer ~w tried to insert item. But buffer is full.~n", [Prod_Id]), 18 | listen(Buffer, Prod_Id, TimesP); 19 | putItem -> 20 | %listen(Buffer, Prod_Id, TimesP - 1) %% OK 21 | listen(Buffer, Prod_Id, TimesP - 2) %% BUG 22 | end; 23 | listen(_Buffer, Prod_Id, _TimesC) -> 24 | io:format("Producer number ~w finished~n",[Prod_Id]). 25 | -------------------------------------------------------------------------------- /examples/Concurrency/mapreduce/comm_seq_diag.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Concurrency/mapreduce/comm_seq_diag.pdf -------------------------------------------------------------------------------- /examples/Concurrency/mapreduce/eval_tree.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Concurrency/mapreduce/eval_tree.pdf -------------------------------------------------------------------------------- /examples/Concurrency/mergesort/comm_seq_diag.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Concurrency/mergesort/comm_seq_diag.pdf -------------------------------------------------------------------------------- /examples/Concurrency/mergesort/eval_tree.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Concurrency/mergesort/eval_tree.pdf -------------------------------------------------------------------------------- /examples/Concurrency/mergesort/mergesort.erl: -------------------------------------------------------------------------------- 1 | -module(mergesort). 2 | -export([mergesort/1, mergesort/2, mergesort/3, comp/2]). 3 | 4 | 5 | mergesort(L) -> 6 | mergesort(L, fun ?MODULE:comp/2, none). 7 | 8 | mergesort(L, Comp) -> 9 | mergesort(L, Comp, none). 10 | 11 | mergesort([], _Comp, Parent) -> send_return([],Parent); 12 | mergesort([X], _Comp, Parent) -> send_return([X],Parent); 13 | mergesort(L, Comp, Parent) -> 14 | Half = length(L) div 2, 15 | L1 = take(Half, L), 16 | L2 = last(length(L) - Half, L), 17 | spawn(?MODULE, mergesort , [L1, Comp, self()]), 18 | spawn(?MODULE, mergesort , [L2, Comp, self()]), 19 | LOrd1 = 20 | receive 21 | {result, LOrd1_} -> 22 | LOrd1_ 23 | end, 24 | LOrd2 = 25 | receive 26 | {result, LOrd2_} -> 27 | LOrd2_ 28 | end, 29 | send_return(merge(LOrd1, LOrd2, Comp), Parent). 30 | 31 | send_return(Result,none) -> 32 | Result; 33 | send_return(Result,Pid) -> 34 | Pid!{result, Result}. 35 | 36 | merge([], [], _Comp) -> 37 | []; 38 | merge([], S2, _Comp) -> 39 | S2; 40 | merge(S1, [], _Comp) -> 41 | S1; 42 | merge([H1 | T1], [H2 | T2], Comp) -> 43 | case Comp(H1,H2) of 44 | false -> [H2 | merge([H1 | T1], T2, Comp)]; % Correct 45 | %false -> [H1 | merge([H2 | T1], T2, Comp)]; % Incorrect 46 | true -> [H1 | merge(T1, [H2 | T2], Comp)] 47 | end. 48 | 49 | 50 | comp(X,Y) -> 51 | X < Y. 52 | 53 | 54 | take(0,_) -> []; 55 | take(1,[H|_])->[H]; 56 | take(_,[])->[]; 57 | % take(N,[H|T])->[H | take(N-1, T)]. % Correct 58 | take(N,[_|T])->[N | take(N-1, T)]. % Incorrect 59 | 60 | last(N, List) -> 61 | lists:reverse(take(N, lists:reverse(List))). 62 | -------------------------------------------------------------------------------- /examples/Concurrency/mergesort/pids_tree.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Concurrency/mergesort/pids_tree.pdf -------------------------------------------------------------------------------- /examples/Concurrency/philosophers/comm_seq_diag.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Concurrency/philosophers/comm_seq_diag.pdf -------------------------------------------------------------------------------- /examples/Concurrency/philosophers/eval_tree.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Concurrency/philosophers/eval_tree.pdf -------------------------------------------------------------------------------- /examples/Concurrency/philosophers/pids_tree.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Concurrency/philosophers/pids_tree.pdf -------------------------------------------------------------------------------- /examples/Concurrency/poolboy/bug1/comm_seq_diag.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Concurrency/poolboy/bug1/comm_seq_diag.pdf -------------------------------------------------------------------------------- /examples/Concurrency/poolboy/bug1/eval_tree.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Concurrency/poolboy/bug1/eval_tree.pdf -------------------------------------------------------------------------------- /examples/Concurrency/poolboy/bug1/pids_tree.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Concurrency/poolboy/bug1/pids_tree.pdf -------------------------------------------------------------------------------- /examples/Concurrency/poolboy/bug2/comm_seq_diag.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Concurrency/poolboy/bug2/comm_seq_diag.pdf -------------------------------------------------------------------------------- /examples/Concurrency/poolboy/bug2/eval_tree.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Concurrency/poolboy/bug2/eval_tree.pdf -------------------------------------------------------------------------------- /examples/Concurrency/poolboy/bug2/pids_tree.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Concurrency/poolboy/bug2/pids_tree.pdf -------------------------------------------------------------------------------- /examples/Concurrency/poolboy/bug3/comm_seq_diag.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Concurrency/poolboy/bug3/comm_seq_diag.pdf -------------------------------------------------------------------------------- /examples/Concurrency/poolboy/bug3/eval_tree.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Concurrency/poolboy/bug3/eval_tree.pdf -------------------------------------------------------------------------------- /examples/Concurrency/poolboy/bug3/pids_tree.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Concurrency/poolboy/bug3/pids_tree.pdf -------------------------------------------------------------------------------- /examples/Concurrency/poolboy/bug4/comm_seq_diag.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Concurrency/poolboy/bug4/comm_seq_diag.pdf -------------------------------------------------------------------------------- /examples/Concurrency/poolboy/bug4/eval_tree.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Concurrency/poolboy/bug4/eval_tree.pdf -------------------------------------------------------------------------------- /examples/Concurrency/poolboy/bug4/pids_tree.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Concurrency/poolboy/bug4/pids_tree.pdf -------------------------------------------------------------------------------- /examples/Concurrency/poolboy/poolboy_sup.erl: -------------------------------------------------------------------------------- 1 | %% Poolboy - A hunky Erlang worker pool factory 2 | 3 | -module(poolboy_sup). 4 | -behaviour(supervisor). 5 | 6 | -export([start_link/2, init/1]). 7 | 8 | start_link(Mod, Args) -> 9 | supervisor:start_link(?MODULE, {Mod, Args}). 10 | 11 | init({Mod, Args}) -> 12 | {ok, {{simple_one_for_one, 0, 1}, 13 | [{Mod, {Mod, start_link, [Args]}, 14 | temporary, brutal_kill, worker, [Mod]}]}}. 15 | -------------------------------------------------------------------------------- /examples/Concurrency/poolboy/poolboy_test_worker.erl: -------------------------------------------------------------------------------- 1 | %% Test Worker for poolboy symptoms 2 | %% Simple server for arithmetic operations (only addition) 3 | 4 | -module(poolboy_test_worker). 5 | 6 | -behaviour(gen_server). 7 | 8 | -export([start_link/1]). 9 | -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, 10 | code_change/3]). 11 | 12 | -record(state, {}). 13 | 14 | start_link(_Args) -> 15 | gen_server:start_link(?MODULE, [], []). 16 | 17 | init([]) -> 18 | {ok, #state{}}. 19 | 20 | handle_call(die, _From, State) -> 21 | {stop, {error, died}, dead, State}; 22 | handle_call({add, A, B}, _From, State) -> 23 | {reply, A + B, State}; 24 | handle_call(_Event, _From, State) -> 25 | {reply, ok, State}. 26 | 27 | handle_cast(_Event, State) -> 28 | {noreply, State}. 29 | 30 | handle_info(stop, State) -> 31 | {stop, normal, State}; 32 | handle_info(_Info, State) -> 33 | {noreply, State}. 34 | 35 | terminate(_Reason, _State) -> 36 | ok. 37 | 38 | code_change(_OldVsn, State, _Extra) -> 39 | {ok, State}. 40 | -------------------------------------------------------------------------------- /examples/Concurrency/tcp/session1/comm_seq_diag.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Concurrency/tcp/session1/comm_seq_diag.pdf -------------------------------------------------------------------------------- /examples/Concurrency/tcp/session1/eval_tree.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Concurrency/tcp/session1/eval_tree.pdf -------------------------------------------------------------------------------- /examples/Concurrency/tcp/session1/pids_tree.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Concurrency/tcp/session1/pids_tree.pdf -------------------------------------------------------------------------------- /examples/Concurrency/tcp/session2/comm_seq_diag.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Concurrency/tcp/session2/comm_seq_diag.pdf -------------------------------------------------------------------------------- /examples/Concurrency/tcp/session2/eval_tree.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Concurrency/tcp/session2/eval_tree.pdf -------------------------------------------------------------------------------- /examples/Concurrency/tcp/session2/pids_tree.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Concurrency/tcp/session2/pids_tree.pdf -------------------------------------------------------------------------------- /examples/Concurrency/tcp/tcp.erl: -------------------------------------------------------------------------------- 1 | -module(tcp). 2 | -export([main/0, server_fun/3, client_fun/4, ack/5]). 3 | 4 | 5 | 6 | main() -> 7 | Server_PID = spawn(?MODULE, server_fun, [self(), 50, 500]), 8 | spawn(?MODULE, client_fun, [Server_PID, 57, 100, client1]), 9 | spawn(?MODULE, client_fun, [Server_PID, 50, 200, client2]), 10 | receive {data,D} -> D end. 11 | 12 | server_fun(Main_PID, Port, Seq) -> 13 | receive 14 | {Client_PID, {syn, Port, SeqCl}} -> 15 | Ack_PID = spawn(?MODULE, ack, [Main_PID, Port, SeqCl+1, Seq+1, Client_PID]), 16 | Client_PID ! {Ack_PID, {syn_ack, SeqCl+1, Seq}}, 17 | server_fun(Main_PID, Port, Seq+1); 18 | {Client_PID, {syn, _, _}} -> 19 | Client_PID ! rst%, server_fun(Main_PID,Port,Seq+1) % BUG 20 | %Client_PID ! rst, server_fun(Main_PID,Port,Seq+1) % OK 21 | end. 22 | 23 | ack(Main_PID, Port, Ack, Seq, Client_PID) -> 24 | receive 25 | {Client_PID, {ack, Port, Seq, Ack}} -> 26 | receive 27 | {Client_PID, {data, Port, D}} -> Main_PID ! {data, D}; 28 | _ -> Main_PID ! {data, error_data} 29 | end; 30 | _ -> Main_PID ! {data, error_ack} 31 | end. 32 | 33 | client_fun(Server_PID, Port, Seq, Data) -> 34 | Server_PID ! {self(), {syn, Port, Seq}}, syn_ack(Port, Data, Seq+1). 35 | 36 | syn_ack(Port, Data, Ack) -> 37 | receive 38 | rst -> {port_rejected, Port} ; 39 | {Ack_PID, {syn_ack, Ack, Seq}} -> 40 | Ack_PID ! {self(), {Ack, Port, Seq+1, ack}}, % BUG 41 | %Ack_PID ! {self(), {ack, Port, Seq+1, Ack}}, % OK 42 | Ack_PID ! {self(), {data, Port, Data}}, 43 | {Seq+1, Ack, Port, Data} 44 | end. 45 | 46 | -------------------------------------------------------------------------------- /examples/Unified_Framework/24_game/README.md: -------------------------------------------------------------------------------- 1 | # 24 game 2 | http://rosettacode.org/wiki/24_game 3 | -------------------------------------------------------------------------------- /examples/Unified_Framework/24_game/g24_ok.erl: -------------------------------------------------------------------------------- 1 | %edd:dd("g24:test([9,2,2,3],\"(9*2)+(2*3)\")"). 2 | -module(g24_ok). 3 | %-export([main/0,test/2,correct_nums/2]). 4 | -compile(export_all). 5 | 6 | 7 | test(Digts,Exp) -> 8 | io:format("Your digits\t~w~n", [Digts]), 9 | io:format("Your expression\t~p~n", [Exp]), 10 | read_eval(Digts,Exp). 11 | 12 | main() -> 13 | random:seed(now()), 14 | io:format("24 Game~n"), 15 | play(). 16 | 17 | play() -> 18 | io:format("Generating 4 digits...~n"), 19 | Digts = [random:uniform(X) || X <- [9,9,9,9]], 20 | io:format("Your digits\t~w~n", [Digts]), 21 | Exp = string:strip(io:get_line(standard_io, "Your expression: "), both, $\n), 22 | read_eval(Digts,Exp), 23 | play(). 24 | 25 | read_eval(Digits,Exp) -> 26 | case {correct_nums(Exp, Digits), eval(Exp)} of 27 | {ok, X} when X == 24 -> io:format("You Win!~n"), {win, X} ; 28 | {ok, X} -> io:format("You Lose with ~p!~n",[X]), {lose, X}; 29 | {List, _} -> io:format("The following numbers are wrong: ~p~n", [List]), 30 | {invalid_chars, List} 31 | end. 32 | 33 | correct_nums(Exp, Digits) -> 34 | case re:run(Exp, "([0-9]+)", [global, {capture, all_but_first, list}]) of 35 | nomatch -> 36 | "No number entered"; 37 | {match, IntLs} -> 38 | case [X || [X] <- IntLs, not lists:member(list_to_integer(X), Digits)] of 39 | [] -> ok; 40 | L -> L 41 | end 42 | end. 43 | 44 | eval(Exp) -> 45 | {X, _} = eval(re:replace(Exp, "\\s", "", [{return, list},global]), 46 | 0), 47 | X. 48 | 49 | eval([], Val) -> 50 | {Val,[]}; 51 | eval([$(|Rest], Val) -> 52 | {NewVal, Exp} = eval(Rest, Val), 53 | eval(Exp, NewVal); 54 | eval([$)|Rest], Val) -> 55 | {Val, Rest}; 56 | eval([$[|Rest], Val) -> 57 | {NewVal, Exp} = eval(Rest, Val), 58 | eval(Exp, NewVal); 59 | eval([$]|Rest], Val) -> 60 | {Val, Rest}; 61 | eval([$+|Rest], Val) -> 62 | {NewOperand, Exp} = eval(Rest, 0), 63 | eval(Exp, Val + NewOperand); 64 | eval([$-|Rest], Val) -> 65 | {NewOperand, Exp} = eval(Rest, 0), 66 | eval(Exp, Val - NewOperand); 67 | eval([$*|Rest], Val) -> 68 | {NewOperand, Exp} = eval(Rest, 0), 69 | eval(Exp, Val * NewOperand); 70 | eval([$/|Rest], Val) -> 71 | {NewOperand, Exp} = eval(Rest, 0), 72 | eval(Exp, Val / NewOperand); 73 | eval([X|Rest], 0) when X >= $1, X =< $9 -> 74 | eval(Rest, X-$0). 75 | -------------------------------------------------------------------------------- /examples/Unified_Framework/24_game/no_tests/colors.dot: -------------------------------------------------------------------------------- 1 | digraph PDG { 2 | 15 [shape=ellipse, label="15 .- g24:eval2(\"(9*2)+(2*3)\", 0) = {24, []}"]; 3 | 13 [shape=ellipse, label="13 .- g24:eval2(\"9*2)+(2*3)\", 0) = {24, []}"]; 4 | 8 [shape=ellipse, label="8 .- g24:eval2([], 6) = {6, []}"]; 5 | 11 [shape=ellipse, label="11 .- g24:eval2(\"+(2*3)\", 18) = {24, []}"]; 6 | 1 [shape=ellipse, label="1 .- g24:eval2(\")+(2*3)\", 2) = {2, \"+(2*3)\"}"]; 7 | 14 [shape=ellipse, label="14 .- g24:eval2([], 24) = {24, []}"]; 8 | 16 [shape=ellipse, label="16 .- g24:eval1(\"(9*2)+(2*3)\") = 24"]; 9 | 12 [shape=ellipse, label="12 .- g24:eval2(\"*2)+(2*3)\", 9) = {24, []}"]; 10 | 7 [shape=ellipse, label="7 .- g24:eval2(\"2*3)\", 0) = {6, []}"]; 11 | 3 [shape=ellipse, label="3 .- g24:eval2(\")\", 3) = {3, []}"]; 12 | 10 [shape=ellipse, label="10 .- g24:eval2([], 24) = {24, []}"]; 13 | 9 [shape=ellipse, label="9 .- g24:eval2(\"(2*3)\", 0) = {6, []}"]; 14 | 18 [shape=ellipse, label="18 .- g24:test([9, 2, 2, 3], \"(9*2)+(2*3)\") = {invalid_chars, []}"]; 15 | 4 [shape=ellipse, label="4 .- g24:eval2(\"3)\", 0) = {3, []}"]; 16 | 17 [shape=ellipse, label="17 .- g24:read_eval([9, 2, 2, 3], \"(9*2)+(2*3)\") = {invalid_chars, []}"]; 17 | 0 [shape=ellipse, label="0 .- g24:correct_nums(\"(9*2)+(2*3)\", [9, 2, 2, 3]) = []"]; 18 | 6 [shape=ellipse, label="6 .- g24:eval2(\"*3)\", 2) = {6, []}"]; 19 | 2 [shape=ellipse, label="2 .- g24:eval2(\"2)+(2*3)\", 0) = {2, \"+(2*3)\"}"]; 20 | 5 [shape=ellipse, label="5 .- g24:eval2([], 6) = {6, []}"]; 21 | 15 -> 14 [color=black, penwidth=3]; 22 | 15 -> 13 [color=black, penwidth=3]; 23 | 13 -> 12 [color=black, penwidth=3]; 24 | 11 -> 10 [color=black, penwidth=3]; 25 | 11 -> 9 [color=black, penwidth=3]; 26 | 16 -> 15 [color=black, penwidth=3]; 27 | 12 -> 11 [color=black, penwidth=3]; 28 | 12 -> 2 [color=black, penwidth=3]; 29 | 7 -> 6 [color=black, penwidth=3]; 30 | 9 -> 8 [color=black, penwidth=3]; 31 | 9 -> 7 [color=black, penwidth=3]; 32 | 18 -> 17 [color=black, penwidth=3]; 33 | 4 -> 3 [color=black, penwidth=3]; 34 | 17 -> 16 [color=black, penwidth=3]; 35 | 17 -> 0 [color=black, penwidth=3]; 36 | 6 -> 5 [color=black, penwidth=3]; 37 | 6 -> 4 [color=black, penwidth=3]; 38 | 2 -> 1 [color=black, penwidth=3]; 39 | } -------------------------------------------------------------------------------- /examples/Unified_Framework/24_game/no_tests/dbg.dot: -------------------------------------------------------------------------------- 1 | digraph PDG { 2 | 15 [shape=ellipse, label="15 .- g24:eval2(\"(9*2)+(2*3)\", 0) = {24, []}"]; 3 | 13 [shape=ellipse, label="13 .- g24:eval2(\"9*2)+(2*3)\", 0) = {24, []}"]; 4 | 8 [shape=ellipse, label="8 .- g24:eval2([], 6) = {6, []}"]; 5 | 11 [shape=ellipse, label="11 .- g24:eval2(\"+(2*3)\", 18) = {24, []}"]; 6 | 1 [shape=ellipse, label="1 .- g24:eval2(\")+(2*3)\", 2) = {2, \"+(2*3)\"}"]; 7 | 14 [shape=ellipse, label="14 .- g24:eval2([], 24) = {24, []}"]; 8 | 16 [shape=ellipse, label="16 .- g24:eval1(\"(9*2)+(2*3)\") = 24"]; 9 | 12 [shape=ellipse, label="12 .- g24:eval2(\"*2)+(2*3)\", 9) = {24, []}"]; 10 | 7 [shape=ellipse, label="7 .- g24:eval2(\"2*3)\", 0) = {6, []}"]; 11 | 3 [shape=ellipse, label="3 .- g24:eval2(\")\", 3) = {3, []}"]; 12 | 10 [shape=ellipse, label="10 .- g24:eval2([], 24) = {24, []}"]; 13 | 9 [shape=ellipse, label="9 .- g24:eval2(\"(2*3)\", 0) = {6, []}"]; 14 | 18 [shape=ellipse, label="18 .- g24:test([9, 2, 2, 3], \"(9*2)+(2*3)\") = {invalid_chars, []}"]; 15 | 4 [shape=ellipse, label="4 .- g24:eval2(\"3)\", 0) = {3, []}"]; 16 | 17 [shape=ellipse, label="17 .- g24:read_eval([9, 2, 2, 3], \"(9*2)+(2*3)\") = {invalid_chars, []}"]; 17 | 0 [shape=ellipse, label="0 .- g24:correct_nums(\"(9*2)+(2*3)\", [9, 2, 2, 3]) = []"]; 18 | 6 [shape=ellipse, label="6 .- g24:eval2(\"*3)\", 2) = {6, []}"]; 19 | 2 [shape=ellipse, label="2 .- g24:eval2(\"2)+(2*3)\", 0) = {2, \"+(2*3)\"}"]; 20 | 5 [shape=ellipse, label="5 .- g24:eval2([], 6) = {6, []}"]; 21 | 15 -> 14 [color=black, penwidth=3]; 22 | 15 -> 13 [color=black, penwidth=3]; 23 | 13 -> 12 [color=black, penwidth=3]; 24 | 11 -> 10 [color=black, penwidth=3]; 25 | 11 -> 9 [color=black, penwidth=3]; 26 | 16 -> 15 [color=black, penwidth=3]; 27 | 12 -> 11 [color=black, penwidth=3]; 28 | 12 -> 2 [color=black, penwidth=3]; 29 | 7 -> 6 [color=black, penwidth=3]; 30 | 9 -> 8 [color=black, penwidth=3]; 31 | 9 -> 7 [color=black, penwidth=3]; 32 | 18 -> 17 [color=black, penwidth=3]; 33 | 4 -> 3 [color=black, penwidth=3]; 34 | 17 -> 16 [color=black, penwidth=3]; 35 | 17 -> 0 [color=black, penwidth=3]; 36 | 6 -> 5 [color=black, penwidth=3]; 37 | 6 -> 4 [color=black, penwidth=3]; 38 | 2 -> 1 [color=black, penwidth=3]; 39 | } -------------------------------------------------------------------------------- /examples/Unified_Framework/24_game/no_tests/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Unified_Framework/24_game/no_tests/dbg.pdf -------------------------------------------------------------------------------- /examples/Unified_Framework/24_game/tests/colors.dot: -------------------------------------------------------------------------------- 1 | digraph PDG { 2 | 15 [shape=ellipse, label="15 .- g24:eval2(\"(9*2)+(2*3)\", 0) = {24, []}"]; 3 | 13 [shape=ellipse, label="13 .- g24:eval2(\"9*2)+(2*3)\", 0) = {24, []}"]; 4 | 8 [shape=ellipse, label="8 .- g24:eval2([], 6) = {6, []}"]; 5 | 11 [shape=ellipse, label="11 .- g24:eval2(\"+(2*3)\", 18) = {24, []}"]; 6 | 1 [shape=ellipse, label="1 .- g24:eval2(\")+(2*3)\", 2) = {2, \"+(2*3)\"}"]; 7 | 14 [shape=ellipse, label="14 .- g24:eval2([], 24) = {24, []}"]; 8 | 16 [shape=ellipse, label="16 .- g24:eval1(\"(9*2)+(2*3)\") = 24" style=filled color="green" fontcolor="white" fillcolor="green"]; 9 | 12 [shape=ellipse, label="12 .- g24:eval2(\"*2)+(2*3)\", 9) = {24, []}"]; 10 | 7 [shape=ellipse, label="7 .- g24:eval2(\"2*3)\", 0) = {6, []}"]; 11 | 3 [shape=ellipse, label="3 .- g24:eval2(\")\", 3) = {3, []}"]; 12 | 10 [shape=ellipse, label="10 .- g24:eval2([], 24) = {24, []}"]; 13 | 9 [shape=ellipse, label="9 .- g24:eval2(\"(2*3)\", 0) = {6, []}"]; 14 | 18 [shape=ellipse, label="18 .- g24:test([9, 2, 2, 3], \"(9*2)+(2*3)\") = {invalid_chars, []}"]; 15 | 4 [shape=ellipse, label="4 .- g24:eval2(\"3)\", 0) = {3, []}"]; 16 | 17 [shape=ellipse, label="17 .- g24:read_eval([9, 2, 2, 3], \"(9*2)+(2*3)\") = {invalid_chars, []}"]; 17 | 0 [shape=ellipse, label="0 .- g24:correct_nums(\"(9*2)+(2*3)\", [9, 2, 2, 3]) = []"]; 18 | 6 [shape=ellipse, label="6 .- g24:eval2(\"*3)\", 2) = {6, []}"]; 19 | 2 [shape=ellipse, label="2 .- g24:eval2(\"2)+(2*3)\", 0) = {2, \"+(2*3)\"}"]; 20 | 5 [shape=ellipse, label="5 .- g24:eval2([], 6) = {6, []}"]; 21 | 15 -> 14 [color=black, penwidth=3]; 22 | 15 -> 13 [color=black, penwidth=3]; 23 | 13 -> 12 [color=black, penwidth=3]; 24 | 11 -> 10 [color=black, penwidth=3]; 25 | 11 -> 9 [color=black, penwidth=3]; 26 | 16 -> 15 [color=black, penwidth=3]; 27 | 12 -> 11 [color=black, penwidth=3]; 28 | 12 -> 2 [color=black, penwidth=3]; 29 | 7 -> 6 [color=black, penwidth=3]; 30 | 9 -> 8 [color=black, penwidth=3]; 31 | 9 -> 7 [color=black, penwidth=3]; 32 | 18 -> 17 [color=black, penwidth=3]; 33 | 4 -> 3 [color=black, penwidth=3]; 34 | 17 -> 16 [color=black, penwidth=3]; 35 | 17 -> 0 [color=black, penwidth=3]; 36 | 6 -> 5 [color=black, penwidth=3]; 37 | 6 -> 4 [color=black, penwidth=3]; 38 | 2 -> 1 [color=black, penwidth=3]; 39 | } -------------------------------------------------------------------------------- /examples/Unified_Framework/24_game/tests/dbg.dot: -------------------------------------------------------------------------------- 1 | digraph PDG { 2 | 15 [shape=ellipse, label="15 .- g24:eval2(\"(9*2)+(2*3)\", 0) = {24, []}"]; 3 | 13 [shape=ellipse, label="13 .- g24:eval2(\"9*2)+(2*3)\", 0) = {24, []}"]; 4 | 8 [shape=ellipse, label="8 .- g24:eval2([], 6) = {6, []}"]; 5 | 11 [shape=ellipse, label="11 .- g24:eval2(\"+(2*3)\", 18) = {24, []}"]; 6 | 1 [shape=ellipse, label="1 .- g24:eval2(\")+(2*3)\", 2) = {2, \"+(2*3)\"}"]; 7 | 14 [shape=ellipse, label="14 .- g24:eval2([], 24) = {24, []}"]; 8 | 16 [shape=ellipse, label="16 .- g24:eval1(\"(9*2)+(2*3)\") = 24"]; 9 | 12 [shape=ellipse, label="12 .- g24:eval2(\"*2)+(2*3)\", 9) = {24, []}"]; 10 | 7 [shape=ellipse, label="7 .- g24:eval2(\"2*3)\", 0) = {6, []}"]; 11 | 3 [shape=ellipse, label="3 .- g24:eval2(\")\", 3) = {3, []}"]; 12 | 10 [shape=ellipse, label="10 .- g24:eval2([], 24) = {24, []}"]; 13 | 9 [shape=ellipse, label="9 .- g24:eval2(\"(2*3)\", 0) = {6, []}"]; 14 | 18 [shape=ellipse, label="18 .- g24:test([9, 2, 2, 3], \"(9*2)+(2*3)\") = {invalid_chars, []}"]; 15 | 4 [shape=ellipse, label="4 .- g24:eval2(\"3)\", 0) = {3, []}"]; 16 | 17 [shape=ellipse, label="17 .- g24:read_eval([9, 2, 2, 3], \"(9*2)+(2*3)\") = {invalid_chars, []}"]; 17 | 0 [shape=ellipse, label="0 .- g24:correct_nums(\"(9*2)+(2*3)\", [9, 2, 2, 3]) = []"]; 18 | 6 [shape=ellipse, label="6 .- g24:eval2(\"*3)\", 2) = {6, []}"]; 19 | 2 [shape=ellipse, label="2 .- g24:eval2(\"2)+(2*3)\", 0) = {2, \"+(2*3)\"}"]; 20 | 5 [shape=ellipse, label="5 .- g24:eval2([], 6) = {6, []}"]; 21 | 15 -> 14 [color=black, penwidth=3]; 22 | 15 -> 13 [color=black, penwidth=3]; 23 | 13 -> 12 [color=black, penwidth=3]; 24 | 11 -> 10 [color=black, penwidth=3]; 25 | 11 -> 9 [color=black, penwidth=3]; 26 | 16 -> 15 [color=black, penwidth=3]; 27 | 12 -> 11 [color=black, penwidth=3]; 28 | 12 -> 2 [color=black, penwidth=3]; 29 | 7 -> 6 [color=black, penwidth=3]; 30 | 9 -> 8 [color=black, penwidth=3]; 31 | 9 -> 7 [color=black, penwidth=3]; 32 | 18 -> 17 [color=black, penwidth=3]; 33 | 4 -> 3 [color=black, penwidth=3]; 34 | 17 -> 16 [color=black, penwidth=3]; 35 | 17 -> 0 [color=black, penwidth=3]; 36 | 6 -> 5 [color=black, penwidth=3]; 37 | 6 -> 4 [color=black, penwidth=3]; 38 | 2 -> 1 [color=black, penwidth=3]; 39 | } -------------------------------------------------------------------------------- /examples/Unified_Framework/24_game/tests/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Unified_Framework/24_game/tests/dbg.pdf -------------------------------------------------------------------------------- /examples/Unified_Framework/ackermann/README.md: -------------------------------------------------------------------------------- 1 | # Ackermann function 2 | http://rosettacode.org/wiki/Ackermann_function 3 | -------------------------------------------------------------------------------- /examples/Unified_Framework/ackermann/ackermann_ok.erl: -------------------------------------------------------------------------------- 1 | -module(ack_ok). 2 | -export([ack/2]). 3 | 4 | ack(0,N) -> N + 1; 5 | ack(M,0) -> ack(M-1, 1); 6 | ack(M,N) -> ack(M-1,ack(M,N-1)). 7 | -------------------------------------------------------------------------------- /examples/Unified_Framework/ackermann/no_tests/ackermann.erl: -------------------------------------------------------------------------------- 1 | -module(ackermann). 2 | -compile(export_all). 3 | 4 | -include_lib("proper/include/proper.hrl"). 5 | -include_lib("eunit/include/eunit.hrl"). 6 | 7 | main( [A, B] ) -> 8 | % io:fwrite("~p~n",[ack(A,B)]). 9 | ack(A,B). 10 | 11 | %toi(E) -> element(1,string:to_integer(E)). 12 | 13 | ack(0,N) -> N + 1; 14 | ack(M,0) -> %ack(M-1, 1); %RIGHT 15 | ack(M-1, 0); %WRONG 16 | ack(M,N) -> ack(M-1,ack(M,N-1)). 17 | 18 | -------------------------------------------------------------------------------- /examples/Unified_Framework/ackermann/no_tests/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Unified_Framework/ackermann/no_tests/dbg.pdf -------------------------------------------------------------------------------- /examples/Unified_Framework/ackermann/session.txt: -------------------------------------------------------------------------------- 1 | WITHOUT TESTS 2 | ============= 3 | > edd:dd("ackermann:main([3,4])", [tree]). 4 | Total number of tree nodes: 91 5 | Tree size: 6 | 9345 words 7 | 74760 bytes 8 | Please, insert a list of trusted functions [m1:f1/a1, m2:f2/a2 ...]: 9 | ackerman:ack(3, 3) = 4? [y/n/t/d/i/s/u/a]: n 10 | ackerman:ack(3, 2) = 3? [y/n/t/d/i/s/u/a]: n 11 | ackerman:ack(2, 2) = 3? [y/n/t/d/i/s/u/a]: n 12 | ackerman:ack(2, 1) = 2? [y/n/t/d/i/s/u/a]: n 13 | ackerman:ack(1, 1) = 2? [y/n/t/d/i/s/u/a]: n 14 | ackerman:ack(1, 0) = 1? [y/n/t/d/i/s/u/a]: n 15 | ackerman:ack(0, 0) = 1? [y/n/t/d/i/s/u/a]: y 16 | Call to a function that contains an error: 17 | ackermann:ack(1, 0) = 1 18 | Please, revise the second clause: 19 | ack(M, 0) -> ack(M - 1, 0). 20 | 21 | 22 | USING TESTS 23 | =========== 24 | > edd:dd("ackermann:main([3,4])", [tree]). 25 | Total number of tree nodes: 91 26 | Tree size: 27 | 9345 words 28 | 74760 bytes 29 | Please, insert a list of trusted functions [m1:f1/a1, m2:f2/a2 ...]: 30 | Call to a function that contains an error: 31 | ackermann:ack(1, 0) = 1 32 | Please, revise the second clause: 33 | ack(M, 0) -> ack(M - 1, 0). 34 | -------------------------------------------------------------------------------- /examples/Unified_Framework/ackermann/tests/ackermann.erl: -------------------------------------------------------------------------------- 1 | -module(ackermann). 2 | -compile(export_all). 3 | 4 | -include_lib("proper/include/proper.hrl"). 5 | -include_lib("eunit/include/eunit.hrl"). 6 | 7 | main( [A, B] ) -> 8 | % io:fwrite("~p~n",[ack(A,B)]). 9 | ack(A,B). 10 | 11 | %toi(E) -> element(1,string:to_integer(E)). 12 | 13 | ack(0,N) -> N + 1; 14 | ack(M,0) -> %ack(M-1, 1); %RIGHT 15 | ack(M-1, 0); %WRONG 16 | ack(M,N) -> ack(M-1,ack(M,N-1)). 17 | 18 | 19 | %% Tests %% 20 | ack0_proper_complete() -> 21 | ?FORALL(N, non_neg_integer(), ack(0, N) =:= N + 1). 22 | 23 | ack1_proper_complete() -> 24 | ?FORALL(N, non_neg_integer(), ack(1, N) =:= N + 2). 25 | 26 | -------------------------------------------------------------------------------- /examples/Unified_Framework/align_cols/README.md: -------------------------------------------------------------------------------- 1 | # Align columns 2 | http://rosettacode.org/wiki/Align_columns 3 | -------------------------------------------------------------------------------- /examples/Unified_Framework/align_cols/align_columns_ok.erl: -------------------------------------------------------------------------------- 1 | %align_columns:align_left(). 2 | -module(align_columns_ok). 3 | 4 | %-export([align_left/0, align_right/0, align_center/0]). 5 | -compile(export_all). 6 | 7 | align_left()-> align_columns(left). 8 | align_right()-> align_columns(right). 9 | align_center()-> align_columns(centre). 10 | align_columns(Alignment) -> 11 | Lines = 12 | ["Given\$a\$text\$file\$of\$many\$lines\$where\$fields\$within\$a\$line\$", 13 | "are\$delineated\$by\$a\$single\$'dollar'\$character,\$write\$a\$program", 14 | "that\$aligns\$each\$column\$of\$fields\$by\$ensuring\$that\$words\$in\$each\$", 15 | "column\$are\$separated\$by\$at\$least\$one\$space.", 16 | "Further,\$allow\$for\$each\$word\$in\$a\$column\$to\$be\$either\$left\$", 17 | "justified,\$right\$justified,\$or\$center\$justified\$within\$its\$column."], 18 | Words = [ string:tokens(Line, "\$") || Line <- Lines ], 19 | Words_length = lists:foldl( fun max_length/2, [], Words), 20 | Result = [prepare_line(Words_line, Words_length, Alignment) || Words_line <- Words], 21 | Result. 22 | 23 | max_length(Words_of_a_line, Acc_maxlength) -> 24 | Line_lengths = [length(W) || W <- Words_of_a_line ], 25 | Max_nb_of_length = lists:max([length(Acc_maxlength), length(Line_lengths)]), 26 | Line_lengths_prepared = adjust_list(Line_lengths, Max_nb_of_length, 0), 27 | Acc_maxlength_prepared = adjust_list(Acc_maxlength, Max_nb_of_length, 0), 28 | Two_lengths =lists:zip(Line_lengths_prepared, Acc_maxlength_prepared), 29 | [ lists:max([A, B]) || {A, B} <- Two_lengths]. 30 | 31 | adjust_list(L, Desired_length, Elem) -> 32 | L++lists:duplicate(Desired_length - length(L), Elem). 33 | 34 | prepare_line(Words_line, Words_length, Alignment) -> 35 | All_words = adjust_list(Words_line, length(Words_length), ""), 36 | Zipped = lists:zip (All_words, Words_length), 37 | [ apply(string, Alignment, [Word, Length + 1, $\s]) || {Word, Length} <- Zipped]. 38 | -------------------------------------------------------------------------------- /examples/Unified_Framework/align_cols/no_tests/align_columns.erl: -------------------------------------------------------------------------------- 1 | %edd:dd("align_columns:align_left()"). 2 | -module (align_columns). 3 | -export([align_left/0, align_right/0, align_center/0, prepare_line/3]). 4 | 5 | -include_lib("eunit/include/eunit.hrl"). 6 | 7 | align_left()-> align_columns(left). 8 | align_right()-> align_columns(right). 9 | align_center()-> align_columns(centre). 10 | align_columns(Alignment) -> 11 | Lines = 12 | ["Given\$a\$text\$file\$of\$many\$lines\$where\$fields\$within\$a\$line\$", 13 | "are\$delineated\$by\$a\$single\$'dollar'\$character,\$write\$a\$program", 14 | "that\$aligns\$each\$column\$of\$fields\$by\$ensuring\$that\$words\$in\$each\$", 15 | "column\$are\$separated\$by\$at\$least\$one\$space.", 16 | "Further,\$allow\$for\$each\$word\$in\$a\$column\$to\$be\$either\$left\$", 17 | "justified,\$right\$justified,\$or\$center\$justified\$within\$its\$column."], 18 | Words = [ string:tokens(Line, "\$") || Line <- Lines ], 19 | Words_length = lists:foldl( fun max_length/2, [], Words), 20 | Result = [prepare_line(Words_line, Words_length, Alignment) || Words_line <- Words], 21 | %[ io:fwrite("~s~n", [lists:flatten(Line)]) || Line <- Result], 22 | %ok. 23 | Result. 24 | 25 | max_length(Words_of_a_line, Acc_maxlength) -> 26 | Line_lengths = [length(W) || W <- Words_of_a_line ], 27 | Max_nb_of_length = lists:max([length(Acc_maxlength), length(Line_lengths)]), 28 | Line_lengths_prepared = adjust_list (Line_lengths, Max_nb_of_length, 0), 29 | Acc_maxlength_prepared = adjust_list(Acc_maxlength, Max_nb_of_length, 0), 30 | Two_lengths =lists:zip(Line_lengths_prepared, Acc_maxlength_prepared), 31 | [ lists:max([A, B]) || {A, B} <- Two_lengths]. 32 | 33 | adjust_list(L, Desired_length, Elem) -> 34 | L++lists:duplicate(Desired_length - length(L), Elem). 35 | 36 | prepare_line(Words_line, Words_length, Alignment) -> 37 | All_words = adjust_list(Words_line, length(Words_length), ""), 38 | Zipped = lists:zip (All_words, Words_length), 39 | [ apply(string, Alignment, [Word, Length-1, $\s]) %WRONG 40 | %[ apply(string, Alignment, [Word, Length + 1, $\s]) %RIGHT 41 | || {Word, Length} <- Zipped]. 42 | 43 | -------------------------------------------------------------------------------- /examples/Unified_Framework/align_cols/no_tests/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Unified_Framework/align_cols/no_tests/dbg.pdf -------------------------------------------------------------------------------- /examples/Unified_Framework/align_cols/tests/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Unified_Framework/align_cols/tests/dbg.pdf -------------------------------------------------------------------------------- /examples/Unified_Framework/caesar/README.md: -------------------------------------------------------------------------------- 1 | # Caesar cipher 2 | http://rosettacode.org/wiki/Caesar_cipher 3 | -------------------------------------------------------------------------------- /examples/Unified_Framework/caesar/caesar_ok.erl: -------------------------------------------------------------------------------- 1 | %edd:dd("caesar:test()"). 2 | %% Caesar cypher in Erlang for the rosetta code wiki. 3 | %% Implemented by J.W. Luiten 4 | 5 | -module(caesar_ok). 6 | -export([main/2,test/0, rot/2]). 7 | 8 | %% rot: rotate Char by Key places 9 | rot(Char,Key) when (Char >= $A) and (Char =< $Z) or 10 | (Char >= $a) and (Char =< $z) -> 11 | Offset = $A + Char band 32, 12 | N = Char - Offset, 13 | Offset + (N + Key) rem 26; %RIGHT 14 | rot(Char, _Key) -> 15 | Char. 16 | 17 | %% key: normalize key. 18 | key(Key) when Key < 0 -> 19 | 26 + Key rem 26; 20 | key(Key) when Key > 25 -> 21 | Key rem 26; 22 | key(Key) -> 23 | Key. 24 | 25 | main(PlainText, Key) -> 26 | Encode = key(Key), 27 | Decode = key(-Key), 28 | 29 | io:format("Plaintext ----> ~s~n", [PlainText]), 30 | 31 | CypherText = lists:map(fun(Char) -> rot(Char, Encode) end, PlainText), 32 | io:format("Cyphertext ---> ~s~n", [CypherText]), 33 | 34 | PlainText = lists:map(fun(Char) -> rot(Char, Decode) end, CypherText). 35 | 36 | test() -> 37 | main("The five boxing wizards jump quickly", 3). 38 | -------------------------------------------------------------------------------- /examples/Unified_Framework/caesar/no_tests/caesar.erl: -------------------------------------------------------------------------------- 1 | -module(caesar). 2 | -compile(export_all). 3 | 4 | -include_lib("proper/include/proper.hrl"). 5 | -include_lib("eunit/include/eunit.hrl"). 6 | 7 | %% rot: rotate Char by Key places 8 | rot(Char,Key) when (Char >= $A) and (Char =< $Z) or 9 | (Char >= $a) and (Char =< $z) -> 10 | Offset = $A + Char band 32, 11 | N = Char - Offset, 12 | %Offset + (N + Key) rem 26; %RIGHT 13 | Offset + (N - Key) rem 26; %WRONG 14 | rot(Char, _Key) -> 15 | Char. 16 | 17 | %% key: normalize key. 18 | key(Key) when Key < 0 -> 19 | 26 + Key rem 26; 20 | key(Key) when Key > 25 -> 21 | Key rem 26; 22 | key(Key) -> 23 | Key. 24 | 25 | main(PlainText, Key) -> 26 | Encode = key(Key), 27 | Decode = key(-Key), 28 | 29 | io:format("Plaintext ----> ~s~n", [PlainText]), 30 | 31 | CypherText = lists:map(fun(Char) -> rot(Char, Encode) end, PlainText), 32 | io:format("Cyphertext ---> ~s~n", [CypherText]), 33 | 34 | PlainText = lists:map(fun(Char) -> rot(Char, Decode) end, CypherText). 35 | 36 | test() -> 37 | main("The five boxing wizards jump quickly", 3). 38 | 39 | -------------------------------------------------------------------------------- /examples/Unified_Framework/caesar/no_tests/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Unified_Framework/caesar/no_tests/dbg.pdf -------------------------------------------------------------------------------- /examples/Unified_Framework/caesar/session.txt: -------------------------------------------------------------------------------- 1 | WITHOUT TESTS 2 | ------------- 3 | > edd:dd("caesar:test()", [tree]). 4 | Plaintext ----> The five boxing wizards jump quickly 5 | Cyphertext ---> Qeb cfsb _lufkd tfw^oap grjm nrf`hiv 6 | Total number of tree nodes: 148 7 | Tree size: 8 | 21380 words 9 | 171040 bytes 10 | Please, insert a list of trusted functions separated by commas (e.g. m1:f1/a1, m2:f2/a2 ...): 11 | 12 | fun (Char) -> rot(Char, 23) end(118) = 95 13 | fun location: (caesar.erl, line 39)? [y/n/t/v/d/i/s/u/a]: n 14 | caesar:rot(118, 23) = 95? [y/n/t/v/d/i/s/u/a]: n 15 | Call to a function that contains an error: 16 | caesar:rot(118, 23) = 95 17 | Please, revise the first clause: 18 | rot(Char, Key) 19 | when (Char >= $A) and (Char =< $Z) or 20 | (Char >= $a) and (Char =< $z) -> 21 | Offset = $A + Char band 32, 22 | N = Char - Offset, 23 | Offset + (N - Key) rem 26. 24 | 25 | 26 | 27 | USING TESTS 28 | ----------- 29 | > edd:dd("caesar:test()", [tree]). 30 | Plaintext ----> The five boxing wizards jump quickly 31 | Cyphertext ---> Qeb cfsb _lufkd tfw^oap grjm nrf`hiv 32 | Total number of tree nodes: 148 33 | Tree size: 34 | 21380 words 35 | 171040 bytes 36 | Please, insert a list of trusted functions separated by commas (e.g. m1:f1/a1, m2:f2/a2 ...): 37 | 38 | Call to a function that contains an error: 39 | caesar:rot(84, 3) = 81 40 | Please, revise the first clause: 41 | rot(Char, Key) 42 | when (Char >= $A) and (Char =< $Z) or 43 | (Char >= $a) and (Char =< $z) -> 44 | Offset = $A + Char band 32, 45 | N = Char - Offset, 46 | Offset + (N - Key) rem 26. 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /examples/Unified_Framework/caesar/tests/caesar.erl: -------------------------------------------------------------------------------- 1 | -module(caesar). 2 | -compile(export_all). 3 | 4 | -include_lib("proper/include/proper.hrl"). 5 | -include_lib("eunit/include/eunit.hrl"). 6 | 7 | %% rot: rotate Char by Key places 8 | rot(Char,Key) when (Char >= $A) and (Char =< $Z) or 9 | (Char >= $a) and (Char =< $z) -> 10 | Offset = $A + Char band 32, 11 | N = Char - Offset, 12 | %Offset + (N + Key) rem 26; %RIGHT 13 | Offset + (N - Key) rem 26; %WRONG 14 | rot(Char, _Key) -> 15 | Char. 16 | 17 | %% key: normalize key. 18 | key(Key) when Key < 0 -> 19 | 26 + Key rem 26; 20 | key(Key) when Key > 25 -> 21 | Key rem 26; 22 | key(Key) -> 23 | Key. 24 | 25 | main(PlainText, Key) -> 26 | Encode = key(Key), 27 | Decode = key(-Key), 28 | 29 | io:format("Plaintext ----> ~s~n", [PlainText]), 30 | 31 | CypherText = lists:map(fun(Char) -> rot(Char, Encode) end, PlainText), 32 | io:format("Cyphertext ---> ~s~n", [CypherText]), 33 | 34 | PlainText = lists:map(fun(Char) -> rot(Char, Decode) end, CypherText). 35 | 36 | test() -> 37 | main("The five boxing wizards jump quickly", 3). 38 | 39 | 40 | 41 | %% Tests %% 42 | prop_rot_lower1_subset() -> 43 | ?FORALL({Char, Key}, {range($a, $z), integer()}, rot(Char,Key) >= $a). 44 | 45 | -------------------------------------------------------------------------------- /examples/Unified_Framework/caesar/tests/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Unified_Framework/caesar/tests/dbg.pdf -------------------------------------------------------------------------------- /examples/Unified_Framework/complex/README.md: -------------------------------------------------------------------------------- 1 | # Arithmetic/Complex 2 | http://rosettacode.org/wiki/Arithmetic/Complex 3 | -------------------------------------------------------------------------------- /examples/Unified_Framework/complex/complex_number_ok.erl: -------------------------------------------------------------------------------- 1 | -module(complex_number_ok). 2 | -compile([export_all]). 3 | 4 | -record(complex, {real, img}). 5 | 6 | calculate() -> 7 | A = #complex{real=1, img=3}, 8 | B = #complex{real=5, img=2}, 9 | Sum = add (A, B), 10 | Product = multiply (A, B), 11 | Negation = negation (A), 12 | Inversion = inverse (A), 13 | Conjugate = conjugate (A), 14 | {Sum, Product, Negation, Inversion, Conjugate}. 15 | 16 | add (A, B) -> 17 | RealPart = A#complex.real + B#complex.real, 18 | ImgPart = A#complex.img + B#complex.img, 19 | #complex{real=RealPart, img=ImgPart}. 20 | 21 | multiply (A, B) -> 22 | RealPart = (A#complex.real * B#complex.real) - (A#complex.img * B#complex.img), 23 | ImgPart = (A#complex.real * B#complex.img) + (B#complex.real * A#complex.img), 24 | #complex{real=RealPart, img=ImgPart}. 25 | 26 | negation (A) -> 27 | #complex{real=-A#complex.real, img=-A#complex.img}. 28 | 29 | inverse (A) -> 30 | C = conjugate (A), 31 | Mod = (A#complex.real * A#complex.real) + (A#complex.img * A#complex.img), 32 | RealPart = C#complex.real / Mod, 33 | ImgPart = C#complex.img / Mod, 34 | #complex{real=RealPart, img=ImgPart}. 35 | 36 | conjugate (A) -> 37 | RealPart = A#complex.real, 38 | ImgPart = -A#complex.img, 39 | #complex{real=RealPart, img=ImgPart}. 40 | -------------------------------------------------------------------------------- /examples/Unified_Framework/complex/no_tests/colors.dot: -------------------------------------------------------------------------------- 1 | digraph PDG { 2 | 1 [shape=ellipse, label="1 .- complex_number:multiply({complex, 1, 3}, {complex, 5, 2}) = {complex, -1, 17}"]; 3 | 3 [shape=ellipse, label="3 .- complex_number:conjugate({complex, 1, 3}) = {complex, -1, -3}"]; 4 | 4 [shape=ellipse, label="4 .- complex_number:inverse({complex, 1, 3}) = {complex, -1.0e-1, -2.99999999999999988898e-1}"]; 5 | 0 [shape=ellipse, label="0 .- complex_number:add({complex, 1, 3}, {complex, 5, 2}) = {complex, 6, 5}"]; 6 | 6 [shape=ellipse, label="6 .- complex_number:calculate() = {{complex, 6, 5}, {complex, -1, 17}, {complex, -1, -3}, {complex, -1.0e-1, -2.99999999999999988898e-1}, {complex, -1, -3}}"]; 7 | 2 [shape=ellipse, label="2 .- complex_number:negation({complex, 1, 3}) = {complex, -1, -3}"]; 8 | 5 [shape=ellipse, label="5 .- complex_number:conjugate({complex, 1, 3}) = {complex, -1, -3}"]; 9 | 4 -> 3 [color=black, penwidth=3]; 10 | 6 -> 5 [color=black, penwidth=3]; 11 | 6 -> 4 [color=black, penwidth=3]; 12 | 6 -> 2 [color=black, penwidth=3]; 13 | 6 -> 1 [color=black, penwidth=3]; 14 | 6 -> 0 [color=black, penwidth=3]; 15 | } -------------------------------------------------------------------------------- /examples/Unified_Framework/complex/no_tests/complex_number.erl: -------------------------------------------------------------------------------- 1 | -module(complex_number). 2 | -compile(export_all). 3 | 4 | -include_lib("proper/include/proper.hrl"). 5 | -include_lib("eunit/include/eunit.hrl"). 6 | 7 | -record(complex, {real, img}). 8 | 9 | calculate() -> 10 | A = #complex{real=1, img=3}, 11 | B = #complex{real=5, img=2}, 12 | Sum = add (A, B), 13 | Product = multiply (A, B), 14 | Negation = negation (A), 15 | Inversion = inverse (A), 16 | Conjugate = conjugate (A), 17 | {Sum, Product, Negation, Inversion, Conjugate}. 18 | 19 | add (A, B) -> 20 | RealPart = A#complex.real + B#complex.real, 21 | ImgPart = A#complex.img + B#complex.img, 22 | #complex{real=RealPart, img=ImgPart}. 23 | 24 | multiply (A, B) -> 25 | RealPart = (A#complex.real * B#complex.real) - (A#complex.img * B#complex.img), 26 | ImgPart = (A#complex.real * B#complex.img) + (B#complex.real * A#complex.img), 27 | #complex{real=RealPart, img=ImgPart}. 28 | 29 | negation (A) -> 30 | #complex{real=-A#complex.real, img=-A#complex.img}. 31 | 32 | inverse (A) -> 33 | C = conjugate (A), 34 | Mod = (A#complex.real * A#complex.real) + (A#complex.img * A#complex.img), %RIGHT 35 | %Mod = (A#complex.real * A#complex.img) + (A#complex.img * A#complex.img), %WRONG 36 | RealPart = C#complex.real / Mod, 37 | ImgPart = C#complex.img / Mod, 38 | #complex{real=RealPart, img=ImgPart}. 39 | 40 | conjugate (A) -> 41 | RealPart = -A#complex.real, % WRONG 42 | % RealPart = A#complex.real, % RIGHT 43 | ImgPart = -A#complex.img, 44 | #complex{real=RealPart, img=ImgPart}. 45 | 46 | -------------------------------------------------------------------------------- /examples/Unified_Framework/complex/no_tests/dbg.dot: -------------------------------------------------------------------------------- 1 | digraph PDG { 2 | 1 [shape=ellipse, label="1 .- complex_number:multiply({complex, 1, 3}, {complex, 5, 2}) = {complex, -1, 17}"]; 3 | 3 [shape=ellipse, label="3 .- complex_number:conjugate({complex, 1, 3}) = {complex, -1, -3}"]; 4 | 4 [shape=ellipse, label="4 .- complex_number:inverse({complex, 1, 3}) = {complex, -1.0e-1, -2.99999999999999988898e-1}"]; 5 | 0 [shape=ellipse, label="0 .- complex_number:add({complex, 1, 3}, {complex, 5, 2}) = {complex, 6, 5}"]; 6 | 6 [shape=ellipse, label="6 .- complex_number:calculate() = {{complex, 6, 5}, {complex, -1, 17}, {complex, -1, -3}, {complex, -1.0e-1, -2.99999999999999988898e-1}, {complex, -1, -3}}"]; 7 | 2 [shape=ellipse, label="2 .- complex_number:negation({complex, 1, 3}) = {complex, -1, -3}"]; 8 | 5 [shape=ellipse, label="5 .- complex_number:conjugate({complex, 1, 3}) = {complex, -1, -3}"]; 9 | 4 -> 3 [color=black, penwidth=3]; 10 | 6 -> 5 [color=black, penwidth=3]; 11 | 6 -> 4 [color=black, penwidth=3]; 12 | 6 -> 2 [color=black, penwidth=3]; 13 | 6 -> 1 [color=black, penwidth=3]; 14 | 6 -> 0 [color=black, penwidth=3]; 15 | } -------------------------------------------------------------------------------- /examples/Unified_Framework/complex/no_tests/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Unified_Framework/complex/no_tests/dbg.pdf -------------------------------------------------------------------------------- /examples/Unified_Framework/complex/session.txt: -------------------------------------------------------------------------------- 1 | WITHOUT TESTS 2 | ------------- 3 | > edd:dd("complex_number:calculate()", [tree]). 4 | Total number of tree nodes: 7 5 | Tree size: 6 | 2359 words 7 | 18872 bytes 8 | Please, insert a list of trusted functions separated by commas (e.g. m1:f1/a1, m2:f2/a2 ...): 9 | 10 | complex_number:inverse({complex, 1, 3}) = {complex, -1.0e-1, -2.99999999999999988898e-1}? [y/n/t/v/d/i/s/u/a]: y 11 | complex_number:conjugate({complex, 1, 3}) = {complex, -1, -3}? [y/n/t/v/d/i/s/u/a]: n 12 | Call to a function that contains an error: 13 | complex_number:conjugate({complex, 1, 3}) = {complex, -1, -3} 14 | Please, revise the first clause: 15 | conjugate(A) -> 16 | RealPart = -A#complex.real, 17 | ImgPart = -A#complex.img, 18 | #complex{real = RealPart, img = ImgPart}. 19 | 20 | 21 | 22 | USING TESTS 23 | ----------- 24 | > edd:dd("complex_number:calculate()", [tree]). 25 | Total number of tree nodes: 7 26 | Tree size: 27 | 2359 words 28 | 18872 bytes 29 | Please, insert a list of trusted functions separated by commas (e.g. m1:f1/a1, m2:f2/a2 ...): 30 | 31 | Call to a function that contains an error: 32 | complex_number:conjugate({complex, 1, 3}) = {complex, -1, -3} 33 | Please, revise the first clause: 34 | conjugate(A) -> 35 | RealPart = -A#complex.real, 36 | ImgPart = -A#complex.img, 37 | #complex{real = RealPart, img = ImgPart}. 38 | 39 | -------------------------------------------------------------------------------- /examples/Unified_Framework/complex/tests/colors.dot: -------------------------------------------------------------------------------- 1 | digraph PDG { 2 | 1 [shape=ellipse, label="1 .- complex_number:multiply({complex, 1, 3}, {complex, 5, 2}) = {complex, -1, 17}"]; 3 | 3 [shape=ellipse, label="3 .- complex_number:conjugate({complex, 1, 3}) = {complex, -1, -3}" style=filled color="red" fontcolor="white" fillcolor="red"]; 4 | 4 [shape=ellipse, label="4 .- complex_number:inverse({complex, 1, 3}) = {complex, -1.0e-1, -2.99999999999999988898e-1}"]; 5 | 0 [shape=ellipse, label="0 .- complex_number:add({complex, 1, 3}, {complex, 5, 2}) = {complex, 6, 5}"]; 6 | 6 [shape=ellipse, label="6 .- complex_number:calculate() = {{complex, 6, 5}, {complex, -1, 17}, {complex, -1, -3}, {complex, -1.0e-1, -2.99999999999999988898e-1}, {complex, -1, -3}}"]; 7 | 2 [shape=ellipse, label="2 .- complex_number:negation({complex, 1, 3}) = {complex, -1, -3}"]; 8 | 5 [shape=ellipse, label="5 .- complex_number:conjugate({complex, 1, 3}) = {complex, -1, -3}" style=filled color="red" fontcolor="white" fillcolor="red"]; 9 | 4 -> 3 [color=black, penwidth=3]; 10 | 6 -> 5 [color=black, penwidth=3]; 11 | 6 -> 4 [color=black, penwidth=3]; 12 | 6 -> 2 [color=black, penwidth=3]; 13 | 6 -> 1 [color=black, penwidth=3]; 14 | 6 -> 0 [color=black, penwidth=3]; 15 | } -------------------------------------------------------------------------------- /examples/Unified_Framework/complex/tests/complex_number.erl: -------------------------------------------------------------------------------- 1 | -module(complex_number). 2 | -compile(export_all). 3 | 4 | -include_lib("proper/include/proper.hrl"). 5 | -include_lib("eunit/include/eunit.hrl"). 6 | 7 | -record(complex, {real, img}). 8 | 9 | calculate() -> 10 | A = #complex{real=1, img=3}, 11 | B = #complex{real=5, img=2}, 12 | Sum = add (A, B), 13 | Product = multiply (A, B), 14 | Negation = negation (A), 15 | Inversion = inverse (A), 16 | Conjugate = conjugate (A), 17 | {Sum, Product, Negation, Inversion, Conjugate}. 18 | 19 | add (A, B) -> 20 | RealPart = A#complex.real + B#complex.real, 21 | ImgPart = A#complex.img + B#complex.img, 22 | #complex{real=RealPart, img=ImgPart}. 23 | 24 | multiply (A, B) -> 25 | RealPart = (A#complex.real * B#complex.real) - (A#complex.img * B#complex.img), 26 | ImgPart = (A#complex.real * B#complex.img) + (B#complex.real * A#complex.img), 27 | #complex{real=RealPart, img=ImgPart}. 28 | 29 | negation (A) -> 30 | #complex{real=-A#complex.real, img=-A#complex.img}. 31 | 32 | inverse (A) -> 33 | C = conjugate (A), 34 | Mod = (A#complex.real * A#complex.real) + (A#complex.img * A#complex.img), %RIGHT 35 | %Mod = (A#complex.real * A#complex.img) + (A#complex.img * A#complex.img), %WRONG 36 | RealPart = C#complex.real / Mod, 37 | ImgPart = C#complex.img / Mod, 38 | #complex{real=RealPart, img=ImgPart}. 39 | 40 | conjugate (A) -> 41 | RealPart = -A#complex.real, % WRONG 42 | % RealPart = A#complex.real, % RIGHT 43 | ImgPart = -A#complex.img, 44 | #complex{real=RealPart, img=ImgPart}. 45 | 46 | 47 | 48 | %% Tests 49 | prop_conjugate_complete() -> 50 | ?FORALL({R,I}, 51 | {integer(), integer()}, 52 | conjugate(#complex{real=R, img=I}) =:= #complex{real=R, img=-I}). 53 | 54 | -------------------------------------------------------------------------------- /examples/Unified_Framework/complex/tests/dbg.dot: -------------------------------------------------------------------------------- 1 | digraph PDG { 2 | 1 [shape=ellipse, label="1 .- complex_number:multiply({complex, 1, 3}, {complex, 5, 2}) = {complex, -1, 17}"]; 3 | 3 [shape=ellipse, label="3 .- complex_number:conjugate({complex, 1, 3}) = {complex, -1, -3}"]; 4 | 4 [shape=ellipse, label="4 .- complex_number:inverse({complex, 1, 3}) = {complex, -1.0e-1, -2.99999999999999988898e-1}"]; 5 | 0 [shape=ellipse, label="0 .- complex_number:add({complex, 1, 3}, {complex, 5, 2}) = {complex, 6, 5}"]; 6 | 6 [shape=ellipse, label="6 .- complex_number:calculate() = {{complex, 6, 5}, {complex, -1, 17}, {complex, -1, -3}, {complex, -1.0e-1, -2.99999999999999988898e-1}, {complex, -1, -3}}"]; 7 | 2 [shape=ellipse, label="2 .- complex_number:negation({complex, 1, 3}) = {complex, -1, -3}"]; 8 | 5 [shape=ellipse, label="5 .- complex_number:conjugate({complex, 1, 3}) = {complex, -1, -3}"]; 9 | 4 -> 3 [color=black, penwidth=3]; 10 | 6 -> 5 [color=black, penwidth=3]; 11 | 6 -> 4 [color=black, penwidth=3]; 12 | 6 -> 2 [color=black, penwidth=3]; 13 | 6 -> 1 [color=black, penwidth=3]; 14 | 6 -> 0 [color=black, penwidth=3]; 15 | } -------------------------------------------------------------------------------- /examples/Unified_Framework/complex/tests/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Unified_Framework/complex/tests/dbg.pdf -------------------------------------------------------------------------------- /examples/Unified_Framework/dutch/README.md: -------------------------------------------------------------------------------- 1 | # Dutch national flag problem 2 | http://rosettacode.org/wiki/Dutch_national_flag_proble 3 | -------------------------------------------------------------------------------- /examples/Unified_Framework/dutch/dutch_ok.erl: -------------------------------------------------------------------------------- 1 | -module(dutch_ok). 2 | -compile([export_all]). 3 | 4 | ball(red) -> 1; 5 | ball(white) -> 2; 6 | ball(blue) -> 3. 7 | 8 | random_ball() -> lists:nth(random:uniform(3), [red, white, blue]). 9 | 10 | random_balls(N) -> random_balls(N,[]). 11 | random_balls(0,L) -> L; 12 | random_balls(N,L) when N > 0 -> 13 | B = random_ball(), 14 | random_balls(N-1, [B|L]). 15 | 16 | is_dutch([]) -> true; 17 | is_dutch([_]) -> true; 18 | is_dutch([B|[H|L]]) -> (ball(B) < ball(H)) and is_dutch([H|L]); 19 | is_dutch(_) -> false. 20 | 21 | dutch(L) -> dutch([],[],[],L). 22 | 23 | dutch(R, W, B, []) -> R ++ W ++ B; 24 | dutch(R, W, B, [red | L]) -> dutch([red|R], W, B, L); 25 | dutch(R, W, B, [white | L]) -> dutch(R, [white|W], B, L); 26 | dutch(R, W, B, [blue | L]) -> dutch(R, W, [blue|B], L). %RIGHT 27 | 28 | main() -> 29 | L = [white,red,white,white,red,white,red,blue,red,red,white,white,blue,blue,white,red,white,blue,blue,white], 30 | case is_dutch(L) of 31 | true -> L; 32 | false -> OrderedL = dutch(L), 33 | OrderedL 34 | end. 35 | -------------------------------------------------------------------------------- /examples/Unified_Framework/dutch/no_tests/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Unified_Framework/dutch/no_tests/dbg.pdf -------------------------------------------------------------------------------- /examples/Unified_Framework/dutch/no_tests/dutch.erl: -------------------------------------------------------------------------------- 1 | -module(dutch). 2 | -compile(export_all). 3 | 4 | -include_lib("proper/include/proper.hrl"). 5 | -include_lib("eunit/include/eunit.hrl"). 6 | 7 | ball(red) -> 1; 8 | ball(white) -> 2; 9 | ball(blue) -> 3. 10 | 11 | random_ball() -> lists:nth(random:uniform(3), [red, white, blue]). 12 | 13 | random_balls(N) -> random_balls(N,[]). 14 | random_balls(0,L) -> L; 15 | random_balls(N,L) when N > 0 -> 16 | B = random_ball(), 17 | random_balls(N-1, [B|L]). 18 | 19 | is_dutch([]) -> true; 20 | is_dutch([_]) -> true; 21 | is_dutch([B|[H|L]]) -> (ball(B) < ball(H)) and is_dutch([H|L]); 22 | is_dutch(_) -> false. 23 | 24 | dutch(L) -> dutch([],[],[],L). 25 | 26 | dutch(R, W, B, []) -> R ++ W ++ B; 27 | dutch(R, W, B, [red | L]) -> dutch([red|R], W, B, L); 28 | dutch(R, W, B, [white | L]) -> dutch(R, [white|W], B, L); 29 | %dutch(R, W, B, [blue | L]) -> dutch(R, W, [blue|B], L). % CORRECT 30 | dutch(R, W, B, [blue | L]) -> dutch(R, W, B, L). % WRONG 31 | 32 | main(N) -> 33 | L = random_balls(N), 34 | case is_dutch(L) of 35 | true -> io:format("The random sequence ~p is already in the order of the Dutch flag!~n", [L]); 36 | false -> io:format("The starting random sequence is ~p;~nThe ordered sequence is ~p.~n", [L, dutch(L)]) 37 | end. 38 | 39 | main() -> 40 | L = [white,red,white,white,red,white,red,blue,red,red,white,white,blue,blue,white,red,white,blue,blue,white], 41 | case is_dutch(L) of 42 | true -> L; 43 | false -> OrderedL = dutch(L), 44 | OrderedL 45 | end. 46 | 47 | -------------------------------------------------------------------------------- /examples/Unified_Framework/dutch/tests/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Unified_Framework/dutch/tests/dbg.pdf -------------------------------------------------------------------------------- /examples/Unified_Framework/dutch/tests/dutch.erl: -------------------------------------------------------------------------------- 1 | -module(dutch). 2 | -compile(export_all). 3 | 4 | -include_lib("proper/include/proper.hrl"). 5 | -include_lib("eunit/include/eunit.hrl"). 6 | 7 | ball(red) -> 1; 8 | ball(white) -> 2; 9 | ball(blue) -> 3. 10 | 11 | random_ball() -> lists:nth(random:uniform(3), [red, white, blue]). 12 | 13 | random_balls(N) -> random_balls(N,[]). 14 | random_balls(0,L) -> L; 15 | random_balls(N,L) when N > 0 -> 16 | B = random_ball(), 17 | random_balls(N-1, [B|L]). 18 | 19 | is_dutch([]) -> true; 20 | is_dutch([_]) -> true; 21 | is_dutch([B|[H|L]]) -> (ball(B) < ball(H)) and is_dutch([H|L]); 22 | is_dutch(_) -> false. 23 | 24 | dutch(L) -> dutch([],[],[],L). 25 | 26 | dutch(R, W, B, []) -> R ++ W ++ B; 27 | dutch(R, W, B, [red | L]) -> dutch([red|R], W, B, L); 28 | dutch(R, W, B, [white | L]) -> dutch(R, [white|W], B, L); 29 | %dutch(R, W, B, [blue | L]) -> dutch(R, W, [blue|B], L). % CORRECT 30 | dutch(R, W, B, [blue | L]) -> dutch(R, W, B, L). % WRONG 31 | 32 | main(N) -> 33 | L = random_balls(N), 34 | case is_dutch(L) of 35 | true -> io:format("The random sequence ~p is already in the order of the Dutch flag!~n", [L]); 36 | false -> io:format("The starting random sequence is ~p;~nThe ordered sequence is ~p.~n", [L, dutch(L)]) 37 | end. 38 | 39 | main() -> 40 | L = [white,red,white,white,red,white,red,blue,red,red,white,white,blue,blue,white,red,white,blue,blue,white], 41 | case is_dutch(L) of 42 | true -> L; 43 | false -> OrderedL = dutch(L), 44 | OrderedL 45 | end. 46 | 47 | 48 | %% Tests %% 49 | comp_color(red, red) -> true; 50 | comp_color(red, white) -> true; 51 | comp_color(red, blue) -> true; 52 | comp_color(white, red) -> false; 53 | comp_color(white, white) -> true; 54 | comp_color(white, blue) -> true; 55 | comp_color(blue, red) -> false; 56 | comp_color(blue, white) -> false; 57 | comp_color(blue, blue) -> true. 58 | 59 | prop_dutch_complete() -> 60 | ?FORALL({R,W,B,Rest}, 61 | {list(red), list(white), list(blue), list(atom())}, 62 | dutch(R,W,B,Rest) =:= lists:sort(fun comp_color/2, R++W++B++Rest)). 63 | 64 | -------------------------------------------------------------------------------- /examples/Unified_Framework/mergesort/no_tests/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Unified_Framework/mergesort/no_tests/dbg.pdf -------------------------------------------------------------------------------- /examples/Unified_Framework/mergesort/no_tests/mergesort.erl: -------------------------------------------------------------------------------- 1 | -module(mergesort). 2 | -compile(export_all). 3 | 4 | -include_lib("proper/include/proper.hrl"). 5 | -include_lib("eunit/include/eunit.hrl"). 6 | 7 | mergesort([], _Comp) -> []; 8 | mergesort([X], _Comp) -> [X]; 9 | mergesort(L, Comp) -> 10 | Half = length(L) div 2, 11 | L1 = take(Half, L), 12 | L2 = last(length(L) - Half, L), 13 | LOrd1 = mergesort(L1, Comp), 14 | LOrd2 = mergesort(L2, Comp), 15 | merge(LOrd1, LOrd2, Comp). 16 | 17 | merge([], [], _Comp) -> 18 | []; 19 | merge([], S2, _Comp) -> 20 | S2; 21 | merge(S1, [], _Comp) -> 22 | S1; 23 | merge([H1 | T1], [H2 | T2], Comp) -> 24 | case Comp(H1,H2) of 25 | % false -> [H2 | merge([H1 | T1], T2, Comp)]; % Correct 26 | false -> [H1 | merge([H2 | T1], T2, Comp)]; % Incorrect 27 | true -> [H1 | merge(T1, [H2 | T2], Comp)] 28 | end. 29 | 30 | 31 | comp(X,Y) when is_atom(X) and is_atom(Y) -> X < Y. 32 | 33 | 34 | take(0,_) -> []; 35 | take(1,[H|_])->[H]; 36 | take(_,[])->[]; 37 | take(N,[H|T])->[H | take(N-1, T)]. % Correct 38 | 39 | last(N, List) -> 40 | lists:reverse(take(N, lists:reverse(List))). 41 | 42 | -------------------------------------------------------------------------------- /examples/Unified_Framework/mergesort/session.txt: -------------------------------------------------------------------------------- 1 | WITHOUT TESTS 2 | ============= 3 | > edd:dd( "mergesort:mergesort([a,c,b,o,i,p,a,q,w,e,v], fun mergesort:comp/2)", [tree] ). 4 | Total number of tree nodes: 120 5 | Tree size: 6 | 18284 words 7 | 146272 bytes 8 | Please, insert a list of trusted functions separated by commas (e.g. m1:f1/a1, m2:f2/a2 ...): 9 | 10 | mergesort:mergesort([p, a, q, w, e, v], fun mergesort:comp/2) = [p, a, q, w, e, v]? [y/n/t/v/d/i/s/u/a]: n 11 | mergesort:mergesort([w, e, v], fun mergesort:comp/2) = [w, e, v]? [y/n/t/v/d/i/s/u/a]: n 12 | mergesort:mergesort([e, v], fun mergesort:comp/2) = [e, v]? [y/n/t/v/d/i/s/u/a]: y 13 | mergesort:merge([w], [e, v], fun mergesort:comp/2) = [w, e, v]? [y/n/t/v/d/i/s/u/a]: n 14 | mergesort:merge([e], [v], fun mergesort:comp/2) = [e, v]? [y/n/t/v/d/i/s/u/a]: y 15 | mergesort:comp(w, e) = false? [y/n/t/v/d/i/s/u/a]: t 16 | 17 | Call to a function that contains an error: 18 | mergesort:merge([w], [e, v], fun mergesort:comp/2) = [w, e, v] 19 | Please, revise the fourth clause: 20 | merge([H1 | T1], [H2 | T2], Comp) -> 21 | case Comp(H1, H2) of 22 | false -> [H1 | merge([H2 | T1], T2, Comp)]; 23 | true -> [H1 | merge(T1, [H2 | T2], Comp)] 24 | end. 25 | 26 | 27 | USING TESTS 28 | =========== 29 | > edd:dd( "mergesort:mergesort([a,c,b,o,i,p,a,q,w,e,v], fun mergesort:comp/2)", [tree] ). 30 | Total number of tree nodes: 120 31 | Tree size: 32 | 18284 words 33 | 146272 bytes 34 | Please, insert a list of trusted functions separated by commas (e.g. m1:f1/a1, m2:f2/a2 ...): 35 | 36 | mergesort:merge([o], [i], fun mergesort:comp/2) = [o, i]? [y/n/t/v/d/i/s/u/a]: n 37 | mergesort:merge([i], [], fun mergesort:comp/2) = [i]? [y/n/t/v/d/i/s/u/a]: y 38 | mergesort:comp(w, e) = false? [y/n/t/v/d/i/s/u/a]: t 39 | 40 | Call to a function that contains an error: 41 | mergesort:merge([o], [i], fun mergesort:comp/2) = [o, i] 42 | Please, revise the fourth clause: 43 | merge([H1 | T1], [H2 | T2], Comp) -> 44 | case Comp(H1, H2) of 45 | false -> [H1 | merge([H2 | T1], T2, Comp)]; 46 | true -> [H1 | merge(T1, [H2 | T2], Comp)] 47 | end. 48 | 49 | -------------------------------------------------------------------------------- /examples/Unified_Framework/mergesort/tests/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Unified_Framework/mergesort/tests/dbg.pdf -------------------------------------------------------------------------------- /examples/Unified_Framework/mergesort/tests/mergesort.erl: -------------------------------------------------------------------------------- 1 | -module(mergesort). 2 | -compile(export_all). 3 | 4 | -include_lib("proper/include/proper.hrl"). 5 | -include_lib("eunit/include/eunit.hrl"). 6 | 7 | mergesort([], _Comp) -> []; 8 | mergesort([X], _Comp) -> [X]; 9 | mergesort(L, Comp) -> 10 | Half = length(L) div 2, 11 | L1 = take(Half, L), 12 | L2 = last(length(L) - Half, L), 13 | LOrd1 = mergesort(L1, Comp), 14 | LOrd2 = mergesort(L2, Comp), 15 | merge(LOrd1, LOrd2, Comp). 16 | 17 | merge([], [], _Comp) -> 18 | []; 19 | merge([], S2, _Comp) -> 20 | S2; 21 | merge(S1, [], _Comp) -> 22 | S1; 23 | merge([H1 | T1], [H2 | T2], Comp) -> 24 | case Comp(H1,H2) of 25 | % false -> [H2 | merge([H1 | T1], T2, Comp)]; % Correct 26 | false -> [H1 | merge([H2 | T1], T2, Comp)]; % Incorrect 27 | true -> [H1 | merge(T1, [H2 | T2], Comp)] 28 | end. 29 | 30 | 31 | comp(X,Y) when is_atom(X) and is_atom(Y) -> X < Y. 32 | 33 | 34 | take(0,_) -> []; 35 | take(1,[H|_])->[H]; 36 | take(_,[])->[]; 37 | take(N,[H|T])->[H | take(N-1, T)]. % Correct 38 | 39 | last(N, List) -> 40 | lists:reverse(take(N, lists:reverse(List))). 41 | 42 | 43 | %% Tests %% 44 | mergesort_property_complete() -> 45 | ?FORALL(L, list(atom()), mergesort(L, fun comp/2) =:= lists:sort(fun mergesort:comp/2, L)). 46 | 47 | -------------------------------------------------------------------------------- /examples/Unified_Framework/miller_rabin/README.md: -------------------------------------------------------------------------------- 1 | # Miller-Rabin primality test 2 | http://rosettacode.org/wiki/Miller-Rabin_primality_test 3 | -------------------------------------------------------------------------------- /examples/Unified_Framework/miller_rabin/miller_rabin_ok.erl: -------------------------------------------------------------------------------- 1 | -module(miller_rabin_ok). 2 | -compile(export_all). 3 | 4 | basis(N) when N>2 -> 5 | 1 + random:uniform(N-2). 6 | 7 | find_ds(D, S) -> 8 | case D rem 2 == 0 of 9 | true -> 10 | find_ds(trunc(D/2), S+1); 11 | false -> 12 | {D, S} 13 | end. 14 | 15 | find_ds(N) -> 16 | find_ds(N-1, 0). 17 | 18 | pow_mod(_B, 0, _M) -> 19 | 1; 20 | pow_mod(B, E, M) -> 21 | case trunc(E) rem 2 == 0 of 22 | true -> trunc(math:pow(pow_mod(B, trunc(E/2), M), 2)) rem M; 23 | false -> trunc(B*pow_mod(B, E-1, M)) rem M % RIGHT 24 | end. 25 | 26 | mr_series(N, A, D, S) when N rem 2 == 1 -> 27 | Js = lists:seq(0, S), 28 | lists:map(fun(J) -> pow_mod(A, math:pow(2, J)*D, N) end, Js). 29 | 30 | is_mr_prime(N, As) when N>2, N rem 2 == 1 -> 31 | {D, S} = find_ds(N), 32 | not lists:any(fun(A) -> 33 | case mr_series(N, A, D, S) of 34 | [1|_] -> false; 35 | L -> not lists:member(N-1, L) 36 | end 37 | end, 38 | As). 39 | 40 | proving_bases(N) when N < 1373653 -> 41 | [2, 3]; 42 | proving_bases(N) when N < 25326001 -> 43 | [2, 3, 5]; 44 | proving_bases(N) when N < 25000000000 -> 45 | [2, 3, 5, 7]; 46 | proving_bases(N) when N < 2152302898747-> 47 | [2, 3, 5, 7, 11]; 48 | proving_bases(N) when N < 341550071728321 -> 49 | [2, 3, 5, 7, 11, 13]; 50 | proving_bases(N) when N < 341550071728321 -> 51 | [2, 3, 5, 7, 11, 13, 17]. 52 | 53 | random_bases(N, K) -> 54 | [basis(N) || _ <- lists:seq(1, K)]. 55 | 56 | is_prime(1) -> false; 57 | is_prime(2) -> true; 58 | is_prime(N) when N rem 2 == 0 -> false; 59 | is_prime(N) when N < 341550071728321 -> 60 | is_mr_prime(N, proving_bases(N)). 61 | 62 | is_probable_prime(N) -> 63 | is_mr_prime(N, random_bases(N, 20)). 64 | 65 | first_10() -> 66 | lists:filter( fun is_prime/1, lists:seq(1,10) ). 67 | 68 | -------------------------------------------------------------------------------- /examples/Unified_Framework/miller_rabin/no_tests/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Unified_Framework/miller_rabin/no_tests/dbg.pdf -------------------------------------------------------------------------------- /examples/Unified_Framework/miller_rabin/no_tests/miller_rabin.erl: -------------------------------------------------------------------------------- 1 | -module(miller_rabin). 2 | 3 | -compile(export_all). 4 | 5 | -include_lib("proper/include/proper.hrl"). 6 | -include_lib("eunit/include/eunit.hrl"). 7 | 8 | basis(N) when N>2 -> 9 | 1 + random:uniform(N-2). 10 | 11 | find_ds(D, S) -> 12 | case D rem 2 == 0 of 13 | true -> 14 | find_ds(trunc(D/2), S+1); 15 | false -> 16 | {D, S} 17 | end. 18 | 19 | find_ds(N) -> 20 | find_ds(N-1, 0). 21 | 22 | pow_mod(_B, 0, _M) -> 23 | 1; 24 | pow_mod(B, E, M) -> 25 | case trunc(E) rem 2 == 0 of 26 | true -> trunc(math:pow(pow_mod(B, trunc(E/2), M), 2)) rem M; 27 | false -> %trunc(B*pow_mod(B, E-1, M)) rem M % RIGHT 28 | trunc(pow_mod(B, E-1, M)) rem M % WRONG 29 | end. 30 | 31 | mr_series(N, A, D, S) when N rem 2 == 1 -> 32 | Js = lists:seq(0, S), 33 | lists:map(fun(J) -> pow_mod(A, math:pow(2, J)*D, N) end, Js). 34 | 35 | is_mr_prime(N, As) when N>2, N rem 2 == 1 -> 36 | {D, S} = find_ds(N), 37 | not lists:any(fun(A) -> 38 | case mr_series(N, A, D, S) of 39 | [1|_] -> false; 40 | L -> not lists:member(N-1, L) 41 | end 42 | end, 43 | As). 44 | 45 | proving_bases(N) when N < 1373653 -> 46 | [2, 3]; 47 | proving_bases(N) when N < 25326001 -> 48 | [2, 3, 5]; 49 | proving_bases(N) when N < 25000000000 -> 50 | [2, 3, 5, 7]; 51 | proving_bases(N) when N < 2152302898747-> 52 | [2, 3, 5, 7, 11]; 53 | proving_bases(N) when N < 341550071728321 -> 54 | [2, 3, 5, 7, 11, 13]; 55 | proving_bases(N) when N < 341550071728321 -> 56 | [2, 3, 5, 7, 11, 13, 17]. 57 | 58 | random_bases(N, K) -> 59 | [basis(N) || _ <- lists:seq(1, K)]. 60 | 61 | is_prime(1) -> false; 62 | is_prime(2) -> true; 63 | is_prime(N) when N rem 2 == 0 -> false; 64 | is_prime(N) when N < 341550071728321 -> 65 | is_mr_prime(N, proving_bases(N)). 66 | 67 | is_probable_prime(N) -> 68 | is_mr_prime(N, random_bases(N, 20)). 69 | 70 | first_10() -> 71 | lists:filter( fun is_prime/1, lists:seq(1,10) ). 72 | 73 | -------------------------------------------------------------------------------- /examples/Unified_Framework/miller_rabin/session.txt: -------------------------------------------------------------------------------- 1 | WITHOUT TESTS 2 | ============= 3 | > edd:dd("miller_rabin:first_10()", [tree]). 4 | Total number of tree nodes: 152 5 | Tree size: 6 | 24680 words 7 | 197440 bytes 8 | Please, insert a list of trusted functions separated by commas (e.g. m1:f1/a1, m2:f2/a2 ...): 9 | 10 | miller_rabin:is_prime(9) = true? [y/n/t/v/d/i/s/u/a]: n 11 | fun (A) -> 12 | case mr_series(9, A, 1, 3) of 13 | [1 | _] -> false; 14 | L -> not lists:member(9 - 1, L) 15 | end 16 | end(3) = 17 | false 18 | fun location: (miller_rabin.erl, line 37)? [y/n/t/v/d/i/s/u/a]: n 19 | fun (J) -> pow_mod(3, math:pow(2, J) * 1, 9) end(3) = 1 20 | fun location: (miller_rabin.erl, line 33)? [y/n/t/v/d/i/s/u/a]: n 21 | miller_rabin:pow_mod(3, 2, 9) = 1? [y/n/t/v/d/i/s/u/a]: n 22 | miller_rabin:pow_mod(3, 1, 9) = 1? [y/n/t/v/d/i/s/u/a]: n 23 | miller_rabin:pow_mod(3, 0, 9) = 1? [y/n/t/v/d/i/s/u/a]: y 24 | Call to a function that contains an error: 25 | miller_rabin:pow_mod(3, 1, 9) = 1 26 | Please, revise the second clause: 27 | pow_mod(B, E, M) -> 28 | case trunc(E) rem 2 == 0 of 29 | true -> 30 | trunc(math:pow(pow_mod(B, trunc(E / 2), M), 2)) rem M; 31 | false -> trunc(pow_mod(B, E - 1, M)) rem M 32 | end. 33 | 34 | 35 | USING TESTS 36 | ============= 37 | > edd:dd("miller_rabin:first_10()", [tree]). 38 | Total number of tree nodes: 152 39 | Tree size: 40 | 24680 words 41 | 197440 bytes 42 | Please, insert a list of trusted functions separated by commas (e.g. m1:f1/a1, m2:f2/a2 ...): 43 | 44 | Call to a function that contains an error: 45 | miller_rabin:pow_mod(2, 1, 3) = 1 46 | Please, revise the second clause: 47 | pow_mod(B, E, M) -> 48 | case trunc(E) rem 2 == 0 of 49 | true -> 50 | trunc(math:pow(pow_mod(B, trunc(E / 2), M), 2)) rem M; 51 | false -> trunc(pow_mod(B, E - 1, M)) rem M 52 | end. 53 | 54 | -------------------------------------------------------------------------------- /examples/Unified_Framework/miller_rabin/tests/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Unified_Framework/miller_rabin/tests/dbg.pdf -------------------------------------------------------------------------------- /examples/Unified_Framework/rfib/README.md: -------------------------------------------------------------------------------- 1 | # Adaptation from the faulty nofib library for Haskell 2 | -------------------------------------------------------------------------------- /examples/Unified_Framework/rfib/no_tests/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Unified_Framework/rfib/no_tests/dbg.pdf -------------------------------------------------------------------------------- /examples/Unified_Framework/rfib/rfib_ok.erl: -------------------------------------------------------------------------------- 1 | -module(rfib_ok). 2 | -compile([export_all]). 3 | 4 | main(N) -> 5 | nfib(N). 6 | 7 | nfib(N) when N =< 1 -> 1; 8 | nfib(N) when N > 1 -> nfib(N-1) + nfib(N-2). 9 | -------------------------------------------------------------------------------- /examples/Unified_Framework/rfib/session.txt: -------------------------------------------------------------------------------- 1 | WITHOUT TESTS 2 | ============= 3 | > edd:dd("rfib:main(10)", [tree]). 4 | Total number of tree nodes: 288 5 | Tree size: 6 | 30736 words 7 | 245888 bytes 8 | Please, insert a list of trusted functions separated by commas (e.g. m1:f1/a1, m2:f2/a2 ...): 9 | 10 | rfib:nfib(9) = 89? [y/n/t/v/d/i/s/u/a]: n 11 | rfib:nfib(8) = 55? [y/n/t/v/d/i/s/u/a]: n 12 | rfib:nfib(7) = 34? [y/n/t/v/d/i/s/u/a]: n 13 | rfib:nfib(6) = 21? [y/n/t/v/d/i/s/u/a]: n 14 | rfib:nfib(5) = 13? [y/n/t/v/d/i/s/u/a]: n 15 | rfib:nfib(4) = 8? [y/n/t/v/d/i/s/u/a]: n 16 | rfib:nfib(3) = 5? [y/n/t/v/d/i/s/u/a]: n 17 | rfib:nfib(2) = 3? [y/n/t/v/d/i/s/u/a]: n 18 | rfib:nfib(1) = 2? [y/n/t/v/d/i/s/u/a]: n 19 | rfib:nfib(-1) = 1? [y/n/t/v/d/i/s/u/a]: i 20 | rfib:nfib(0) = 1? [y/n/t/v/d/i/s/u/a]: y 21 | Call to a function that contains an error: 22 | rfib:nfib(1) = 2 23 | Please, revise the second clause: 24 | nfib(N) when N >= 1 -> nfib(N - 1) + nfib(N - 2). 25 | 26 | 27 | USING TESTS 28 | =========== 29 | > edd:dd("rfib:main(10)", [tree]). 30 | Total number of tree nodes: 288 31 | Tree size: 32 | 30736 words 33 | 245888 bytes 34 | Please, insert a list of trusted functions separated by commas (e.g. m1:f1/a1, m2:f2/a2 ...): 35 | 36 | rfib:nfib(-1) = 1? [y/n/t/v/d/i/s/u/a]: i 37 | Call to a function that contains an error: 38 | rfib:nfib(1) = 2 39 | Please, revise the second clause: 40 | nfib(N) when N >= 1 -> nfib(N - 1) + nfib(N - 2). 41 | 42 | -------------------------------------------------------------------------------- /examples/Unified_Framework/rfib/tests/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Unified_Framework/rfib/tests/dbg.pdf -------------------------------------------------------------------------------- /examples/Unified_Framework/rle/README.md: -------------------------------------------------------------------------------- 1 | # Run-length encoding 2 | http://rosettacode.org/wiki/Run-length_encoding 3 | -------------------------------------------------------------------------------- /examples/Unified_Framework/rle/no_tests/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Unified_Framework/rle/no_tests/dbg.pdf -------------------------------------------------------------------------------- /examples/Unified_Framework/rle/no_tests/rle.erl: -------------------------------------------------------------------------------- 1 | -module(rle). 2 | -compile([export_all]). 3 | 4 | -include_lib("proper/include/proper.hrl"). 5 | -include_lib("eunit/include/eunit.hrl"). 6 | 7 | encode(S) -> 8 | doEncode(string:substr(S, 2), string:substr(S, 1, 1), 1, []). 9 | 10 | doEncode([], CurrChar, Count, R) -> 11 | R ++ integer_to_list(Count) ++ CurrChar; 12 | doEncode(S, CurrChar, Count, R) -> 13 | NextChar = string:substr(S, 1, 1), 14 | if 15 | NextChar == CurrChar -> 16 | % doEncode(string:substr(S, 2), CurrChar, Count + 1, R); % CORRECT 17 | doEncode(string:substr(S, 3), CurrChar, Count + 1, R); % WRONG 18 | true -> 19 | doEncode(string:substr(S, 2), NextChar, 1, R ++ integer_to_list(Count) ++ CurrChar) 20 | end. 21 | 22 | decode(S) -> 23 | doDecode(string:substr(S, 2), string:substr(S, 1, 1), []). 24 | 25 | doDecode([], _, R) -> 26 | R; 27 | doDecode(S, CurrString, R) -> 28 | NextChar = string:substr(S, 1, 1), 29 | IsInt = erlang:is_integer(catch(erlang:list_to_integer(NextChar))), 30 | if 31 | IsInt -> 32 | doDecode(string:substr(S, 2), CurrString ++ NextChar, R); 33 | true -> 34 | doDecode(string:substr(S, 2), [], 35 | R ++ string:copies(NextChar, list_to_integer(CurrString))) 36 | end. 37 | 38 | test() -> 39 | PreEncoded = 40 | "WWWWWWWBWWWWWBBBWWWWWWWBWWWWW", 41 | Expected = "7W1B5W3B7W1B5W", 42 | (encode(PreEncoded) =:= Expected) 43 | and (decode(Expected) =:= PreEncoded) 44 | and(decode(encode(PreEncoded)) =:= PreEncoded). 45 | %encode(PreEncoded). 46 | 47 | -------------------------------------------------------------------------------- /examples/Unified_Framework/rle/rle_ok.erl: -------------------------------------------------------------------------------- 1 | -module(rle_ok). 2 | -compile([export_all]). 3 | 4 | 5 | encode(S) -> 6 | doEncode(string:substr(S, 2), string:substr(S, 1, 1), 1, []). 7 | 8 | doEncode([], CurrChar, Count, R) -> 9 | R ++ integer_to_list(Count) ++ CurrChar; 10 | doEncode(S, CurrChar, Count, R) -> 11 | NextChar = string:substr(S, 1, 1), 12 | if 13 | NextChar == CurrChar -> 14 | doEncode(string:substr(S, 2), CurrChar, Count + 1, R); % RIGHT 15 | %doEncode(string:substr(S, 3), CurrChar, Count + 1, R); % WRONG 16 | true -> 17 | doEncode(string:substr(S, 2), NextChar, 1, 18 | R ++ integer_to_list(Count) ++ CurrChar) 19 | end. 20 | 21 | decode(S) -> 22 | doDecode(string:substr(S, 2), string:substr(S, 1, 1), []). 23 | 24 | doDecode([], _, R) -> 25 | R; 26 | doDecode(S, CurrString, R) -> 27 | NextChar = string:substr(S, 1, 1), 28 | IsInt = erlang:is_integer(catch(erlang:list_to_integer(NextChar))), 29 | if 30 | IsInt -> 31 | doDecode(string:substr(S, 2), CurrString ++ NextChar, R); 32 | true -> 33 | doDecode(string:substr(S, 2), [], 34 | R ++ string:copies(NextChar, list_to_integer(CurrString))) 35 | end. 36 | 37 | test() -> 38 | PreEncoded = 39 | "WWWWWWWBWWWWWBBBWWWWWWWBWWWWW", 40 | Expected = "7W1B5W3B7W1B5W", 41 | (encode(PreEncoded) =:= Expected) 42 | and (decode(Expected) =:= PreEncoded) 43 | and(decode(encode(PreEncoded)) =:= PreEncoded). 44 | %encode(PreEncoded). 45 | -------------------------------------------------------------------------------- /examples/Unified_Framework/rle/session.txt: -------------------------------------------------------------------------------- 1 | WITHOUT TESTS 2 | ============= 3 | > edd:dd("rle:test()", [tree]). 4 | Total number of tree nodes: 69 5 | Tree size: 6 | 28141 words 7 | 225128 bytes 8 | Please, insert a list of trusted functions separated by commas (e.g. m1:f1/a1, m2:f2/a2 ...): 9 | 10 | rle:encode("WWWWWWWBWWWWWBBBWWWWWWWBWWWWW") = "4W1B3W2B4W1B3W"? [y/n/t/v/d/i/s/u/a]: n 11 | rle:doEncode("BBWWWWWWWBWWWWW", "B", 1, "4W1B3W") = "4W1B3W2B4W1B3W"? [y/n/t/v/d/i/s/u/a]: n 12 | rle:doEncode("BWWWWW", "W", 4, "4W1B3W2B") = "4W1B3W2B4W1B3W"? [y/n/t/v/d/i/s/u/a]: n 13 | rle:doEncode("WWWW", "W", 1, "4W1B3W2B4W1B") = "4W1B3W2B4W1B3W"? [y/n/t/v/d/i/s/u/a]: n 14 | rle:doEncode("WW", "W", 2, "4W1B3W2B4W1B") = "4W1B3W2B4W1B3W"? [y/n/t/v/d/i/s/u/a]: n 15 | rle:doEncode([], "W", 3, "4W1B3W2B4W1B") = "4W1B3W2B4W1B3W"? [y/n/t/v/d/i/s/u/a]: y 16 | Call to a function that contains an error: 17 | rle:doEncode("WW", "W", 2, "4W1B3W2B4W1B") = "4W1B3W2B4W1B3W" 18 | Please, revise the second clause: 19 | doEncode(S, CurrChar, Count, R) -> 20 | NextChar = string:substr(S, 1, 1), 21 | if NextChar == CurrChar -> 22 | doEncode(string:substr(S, 3), CurrChar, Count + 1, R); 23 | true -> 24 | doEncode(string:substr(S, 2), 25 | NextChar, 26 | 1, 27 | R ++ integer_to_list(Count) ++ CurrChar) 28 | end. 29 | PreviousTests: [] 30 | 31 | 32 | 33 | USING TESTS 34 | ============= 35 | > edd:dd("rle:test()", [tree]). 36 | Total number of tree nodes: 69 37 | Tree size: 38 | 28141 words 39 | 225128 bytes 40 | Please, insert a list of trusted functions separated by commas (e.g. m1:f1/a1, m2:f2/a2 ...): 41 | 42 | rle:doEncode([], "W", 3, "4W1B3W2B4W1B") = "4W1B3W2B4W1B3W"? [y/n/t/v/d/i/s/u/a]: y 43 | Call to a function that contains an error: 44 | rle:doEncode("WW", "W", 2, "4W1B3W2B4W1B") = "4W1B3W2B4W1B3W" 45 | Please, revise the second clause: 46 | doEncode(S, CurrChar, Count, R) -> 47 | NextChar = string:substr(S, 1, 1), 48 | if NextChar == CurrChar -> 49 | doEncode(string:substr(S, 3), CurrChar, Count + 1, R); 50 | true -> 51 | doEncode(string:substr(S, 2), 52 | NextChar, 53 | 1, 54 | R ++ integer_to_list(Count) ++ CurrChar) 55 | end. 56 | 57 | -------------------------------------------------------------------------------- /examples/Unified_Framework/rle/tests/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Unified_Framework/rle/tests/dbg.pdf -------------------------------------------------------------------------------- /examples/Unified_Framework/rle/tests/rle.erl: -------------------------------------------------------------------------------- 1 | -module(rle). 2 | -compile([export_all]). 3 | 4 | -include_lib("proper/include/proper.hrl"). 5 | -include_lib("eunit/include/eunit.hrl"). 6 | 7 | encode(S) -> 8 | doEncode(string:substr(S, 2), string:substr(S, 1, 1), 1, []). 9 | 10 | doEncode([], CurrChar, Count, R) -> 11 | R ++ integer_to_list(Count) ++ CurrChar; 12 | doEncode(S, CurrChar, Count, R) -> 13 | NextChar = string:substr(S, 1, 1), 14 | if 15 | NextChar == CurrChar -> 16 | % doEncode(string:substr(S, 2), CurrChar, Count + 1, R); % CORRECT 17 | doEncode(string:substr(S, 3), CurrChar, Count + 1, R); % WRONG 18 | true -> 19 | doEncode(string:substr(S, 2), NextChar, 1, R ++ integer_to_list(Count) ++ CurrChar) 20 | end. 21 | 22 | decode(S) -> 23 | doDecode(string:substr(S, 2), string:substr(S, 1, 1), []). 24 | 25 | doDecode([], _, R) -> 26 | R; 27 | doDecode(S, CurrString, R) -> 28 | NextChar = string:substr(S, 1, 1), 29 | IsInt = erlang:is_integer(catch(erlang:list_to_integer(NextChar))), 30 | if 31 | IsInt -> 32 | doDecode(string:substr(S, 2), CurrString ++ NextChar, R); 33 | true -> 34 | doDecode(string:substr(S, 2), [], 35 | R ++ string:copies(NextChar, list_to_integer(CurrString))) 36 | end. 37 | 38 | test() -> 39 | PreEncoded = 40 | "WWWWWWWBWWWWWBBBWWWWWWWBWWWWW", 41 | Expected = "7W1B5W3B7W1B5W", 42 | (encode(PreEncoded) =:= Expected) 43 | and (decode(Expected) =:= PreEncoded) 44 | and(decode(encode(PreEncoded)) =:= PreEncoded). 45 | %encode(PreEncoded). 46 | 47 | 48 | %% Tests %% 49 | doEnconde_test() -> 50 | ?assertNotEqual(doEncode([87, 87], 51 | [87], 52 | 2, 53 | [52, 87, 49, 66, 51, 87, 50, 66, 52, 87, 49, 66]), [52, 87, 49, 66, 51, 87, 50, 66, 52, 87, 49, 66, 51, 87]), 54 | ?assertNotEqual(doEncode([87, 87, 87, 87], 55 | [87], 56 | 1, 57 | [52, 87, 49, 66, 51, 87, 50, 66, 52, 87, 49, 66]), [52, 87, 49, 66, 51, 87, 50, 66, 52, 87, 49, 66, 51, 87]). 58 | 59 | -------------------------------------------------------------------------------- /examples/Unified_Framework/roman/README.md: -------------------------------------------------------------------------------- 1 | # Roman numerals/Encode 2 | http://rosettacode.org/wiki/Roman_numerals/Encode 3 | -------------------------------------------------------------------------------- /examples/Unified_Framework/roman/no_tests/colors.dot: -------------------------------------------------------------------------------- 1 | digraph PDG { 2 | 8 [shape=ellipse, label="8 .- roman:main() = \"MMCDLLXXIX\""]; 3 | 1 [shape=ellipse, label="1 .- roman:digit(8, 88, 76, 67) = \"LLXX\""]; 4 | 7 [shape=ellipse, label="7 .- roman:to_roman(2489) = \"MMCDLLXXIX\""]; 5 | 3 [shape=ellipse, label="3 .- roman:to_roman(9) = \"IX\""]; 6 | 4 [shape=ellipse, label="4 .- roman:to_roman(89) = \"LLXXIX\""]; 7 | 0 [shape=ellipse, label="0 .- roman:digit(4, 67, 68, 77) = \"CD\""]; 8 | 6 [shape=ellipse, label="6 .- roman:to_roman(1489) = \"MCDLLXXIX\""]; 9 | 2 [shape=ellipse, label="2 .- roman:digit(9, 73, 86, 88) = \"IX\""]; 10 | 5 [shape=ellipse, label="5 .- roman:to_roman(489) = \"CDLLXXIX\""]; 11 | 8 -> 7 [color=black, penwidth=3]; 12 | 7 -> 6 [color=black, penwidth=3]; 13 | 3 -> 2 [color=black, penwidth=3]; 14 | 4 -> 3 [color=black, penwidth=3]; 15 | 4 -> 1 [color=black, penwidth=3]; 16 | 6 -> 5 [color=black, penwidth=3]; 17 | 5 -> 4 [color=black, penwidth=3]; 18 | 5 -> 0 [color=black, penwidth=3]; 19 | } -------------------------------------------------------------------------------- /examples/Unified_Framework/roman/no_tests/dbg.dot: -------------------------------------------------------------------------------- 1 | digraph PDG { 2 | 8 [shape=ellipse, label="8 .- roman:main() = \"MMCDLLXXIX\""]; 3 | 1 [shape=ellipse, label="1 .- roman:digit(8, 88, 76, 67) = \"LLXX\""]; 4 | 7 [shape=ellipse, label="7 .- roman:to_roman(2489) = \"MMCDLLXXIX\""]; 5 | 3 [shape=ellipse, label="3 .- roman:to_roman(9) = \"IX\""]; 6 | 4 [shape=ellipse, label="4 .- roman:to_roman(89) = \"LLXXIX\""]; 7 | 0 [shape=ellipse, label="0 .- roman:digit(4, 67, 68, 77) = \"CD\""]; 8 | 6 [shape=ellipse, label="6 .- roman:to_roman(1489) = \"MCDLLXXIX\""]; 9 | 2 [shape=ellipse, label="2 .- roman:digit(9, 73, 86, 88) = \"IX\""]; 10 | 5 [shape=ellipse, label="5 .- roman:to_roman(489) = \"CDLLXXIX\""]; 11 | 8 -> 7 [color=black, penwidth=3]; 12 | 7 -> 6 [color=black, penwidth=3]; 13 | 3 -> 2 [color=black, penwidth=3]; 14 | 4 -> 3 [color=black, penwidth=3]; 15 | 4 -> 1 [color=black, penwidth=3]; 16 | 6 -> 5 [color=black, penwidth=3]; 17 | 5 -> 4 [color=black, penwidth=3]; 18 | 5 -> 0 [color=black, penwidth=3]; 19 | } -------------------------------------------------------------------------------- /examples/Unified_Framework/roman/no_tests/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Unified_Framework/roman/no_tests/dbg.pdf -------------------------------------------------------------------------------- /examples/Unified_Framework/roman/no_tests/roman.erl: -------------------------------------------------------------------------------- 1 | -module(roman). 2 | -compile(export_all). 3 | 4 | -include_lib("proper/include/proper.hrl"). 5 | -include_lib("eunit/include/eunit.hrl"). 6 | 7 | to_roman(0) -> []; 8 | to_roman(X) when X >= 1000 -> [$M | to_roman(X - 1000)]; 9 | to_roman(X) when X >= 100 -> 10 | digit(X div 100, $C, $D, $M) ++ to_roman(X rem 100); 11 | to_roman(X) when X >= 10 -> 12 | digit(X div 10, $X, $L, $C) ++ to_roman(X rem 10); 13 | to_roman(X) when X >= 1 -> digit(X, $I, $V, $X). 14 | 15 | digit(1, X, _, _) -> [X]; 16 | digit(2, X, _, _) -> [X, X]; 17 | digit(3, X, _, _) -> [X, X, X]; 18 | digit(4, X, Y, _) -> [X, Y]; 19 | digit(5, _, Y, _) -> [Y]; 20 | digit(6, X, Y, _) -> [Y, X]; 21 | digit(7, X, Y, _) -> [Y, X, X]; 22 | %digit(8, X, Y, _) -> [Y, X, X, X]; %RIGHT 23 | digit(8, X, Y, _) -> [Y, Y, X, X]; %WRONG 24 | digit(9, X, _, Z) -> [X, Z]. 25 | 26 | main() -> 27 | to_roman(2489). 28 | 29 | -------------------------------------------------------------------------------- /examples/Unified_Framework/roman/roman_ok.erl: -------------------------------------------------------------------------------- 1 | -module(roman_ok). 2 | -compile([export_all]). 3 | 4 | to_roman(0) -> []; 5 | to_roman(X) when X >= 1000 -> [$M | to_roman(X - 1000)]; 6 | to_roman(X) when X >= 100 -> 7 | digit(X div 100, $C, $D, $M) ++ to_roman(X rem 100); 8 | to_roman(X) when X >= 10 -> 9 | digit(X div 10, $X, $L, $C) ++ to_roman(X rem 10); 10 | to_roman(X) when X >= 1 -> digit(X, $I, $V, $X). 11 | 12 | digit(1, X, _, _) -> [X]; 13 | digit(2, X, _, _) -> [X, X]; 14 | digit(3, X, _, _) -> [X, X, X]; 15 | digit(4, X, Y, _) -> [X, Y]; 16 | digit(5, _, Y, _) -> [Y]; 17 | digit(6, X, Y, _) -> [Y, X]; 18 | digit(7, X, Y, _) -> [Y, X, X]; 19 | digit(8, X, Y, _) -> [Y, X, X, X]; 20 | digit(9, X, _, Z) -> [X, Z]. 21 | 22 | main() -> 23 | to_roman(2489). 24 | -------------------------------------------------------------------------------- /examples/Unified_Framework/roman/session.txt: -------------------------------------------------------------------------------- 1 | WITHOUT TESTS 2 | ============= 3 | > edd:dd("roman:main()", [tree]). 4 | Total number of tree nodes: 9 5 | Tree size: 6 | 2163 words 7 | 17304 bytes 8 | Please, insert a list of trusted functions separated by commas (e.g. m1:f1/a1, m2:f2/a2 ...): 9 | 10 | roman:to_roman(89) = "LLXXIX"? [y/n/t/v/d/i/s/u/a]: n 11 | roman:to_roman(9) = "IX"? [y/n/t/v/d/i/s/u/a]: y 12 | roman:digit(8, 88, 76, 67) = "LLXX"? [y/n/t/v/d/i/s/u/a]: n 13 | Call to a function that contains an error: 14 | roman:digit(8, 88, 76, 67) = "LLXX" 15 | Please, revise the 8th clause: 16 | digit(8, X, Y, _) -> [Y, Y, X, X]. 17 | 18 | 19 | 20 | USING TESTS 21 | ============= 22 | > edd:dd("roman:main()", [tree]). 23 | Total number of tree nodes: 9 24 | Tree size: 25 | 2163 words 26 | 17304 bytes 27 | Please, insert a list of trusted functions separated by commas (e.g. m1:f1/a1, m2:f2/a2 ...): 28 | 29 | Call to a function that contains an error: 30 | roman:digit(8, 88, 76, 67) = "LLXX" 31 | Please, revise the 8th clause: 32 | digit(8, X, Y, _) -> [Y, Y, X, X]. 33 | 34 | -------------------------------------------------------------------------------- /examples/Unified_Framework/roman/tests/colors.dot: -------------------------------------------------------------------------------- 1 | digraph PDG { 2 | 8 [shape=ellipse, label="8 .- roman:main() = \"MMCDLLXXIX\""]; 3 | 1 [shape=ellipse, label="1 .- roman:digit(8, 88, 76, 67) = \"LLXX\""]; 4 | 7 [shape=ellipse, label="7 .- roman:to_roman(2489) = \"MMCDLLXXIX\""]; 5 | 3 [shape=ellipse, label="3 .- roman:to_roman(9) = \"IX\""]; 6 | 4 [shape=ellipse, label="4 .- roman:to_roman(89) = \"LLXXIX\""]; 7 | 0 [shape=ellipse, label="0 .- roman:digit(4, 67, 68, 77) = \"CD\""]; 8 | 6 [shape=ellipse, label="6 .- roman:to_roman(1489) = \"MCDLLXXIX\""]; 9 | 2 [shape=ellipse, label="2 .- roman:digit(9, 73, 86, 88) = \"IX\""]; 10 | 5 [shape=ellipse, label="5 .- roman:to_roman(489) = \"CDLLXXIX\""]; 11 | 8 -> 7 [color=black, penwidth=3]; 12 | 7 -> 6 [color=black, penwidth=3]; 13 | 3 -> 2 [color=black, penwidth=3]; 14 | 4 -> 3 [color=black, penwidth=3]; 15 | 4 -> 1 [color=black, penwidth=3]; 16 | 6 -> 5 [color=black, penwidth=3]; 17 | 5 -> 4 [color=black, penwidth=3]; 18 | 5 -> 0 [color=black, penwidth=3]; 19 | } -------------------------------------------------------------------------------- /examples/Unified_Framework/roman/tests/dbg.dot: -------------------------------------------------------------------------------- 1 | digraph PDG { 2 | 8 [shape=ellipse, label="8 .- roman:main() = \"MMCDLLXXIX\""]; 3 | 1 [shape=ellipse, label="1 .- roman:digit(8, 88, 76, 67) = \"LLXX\""]; 4 | 7 [shape=ellipse, label="7 .- roman:to_roman(2489) = \"MMCDLLXXIX\""]; 5 | 3 [shape=ellipse, label="3 .- roman:to_roman(9) = \"IX\""]; 6 | 4 [shape=ellipse, label="4 .- roman:to_roman(89) = \"LLXXIX\""]; 7 | 0 [shape=ellipse, label="0 .- roman:digit(4, 67, 68, 77) = \"CD\""]; 8 | 6 [shape=ellipse, label="6 .- roman:to_roman(1489) = \"MCDLLXXIX\""]; 9 | 2 [shape=ellipse, label="2 .- roman:digit(9, 73, 86, 88) = \"IX\""]; 10 | 5 [shape=ellipse, label="5 .- roman:to_roman(489) = \"CDLLXXIX\""]; 11 | 8 -> 7 [color=black, penwidth=3]; 12 | 7 -> 6 [color=black, penwidth=3]; 13 | 3 -> 2 [color=black, penwidth=3]; 14 | 4 -> 3 [color=black, penwidth=3]; 15 | 4 -> 1 [color=black, penwidth=3]; 16 | 6 -> 5 [color=black, penwidth=3]; 17 | 5 -> 4 [color=black, penwidth=3]; 18 | 5 -> 0 [color=black, penwidth=3]; 19 | } -------------------------------------------------------------------------------- /examples/Unified_Framework/roman/tests/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Unified_Framework/roman/tests/dbg.pdf -------------------------------------------------------------------------------- /examples/Unified_Framework/roman/tests/roman.erl: -------------------------------------------------------------------------------- 1 | -module(roman). 2 | -compile(export_all). 3 | 4 | -include_lib("proper/include/proper.hrl"). 5 | -include_lib("eunit/include/eunit.hrl"). 6 | 7 | to_roman(0) -> []; 8 | to_roman(X) when X >= 1000 -> [$M | to_roman(X - 1000)]; 9 | to_roman(X) when X >= 100 -> 10 | digit(X div 100, $C, $D, $M) ++ to_roman(X rem 100); 11 | to_roman(X) when X >= 10 -> 12 | digit(X div 10, $X, $L, $C) ++ to_roman(X rem 10); 13 | to_roman(X) when X >= 1 -> digit(X, $I, $V, $X). 14 | 15 | digit(1, X, _, _) -> [X]; 16 | digit(2, X, _, _) -> [X, X]; 17 | digit(3, X, _, _) -> [X, X, X]; 18 | digit(4, X, Y, _) -> [X, Y]; 19 | digit(5, _, Y, _) -> [Y]; 20 | digit(6, X, Y, _) -> [Y, X]; 21 | digit(7, X, Y, _) -> [Y, X, X]; 22 | %digit(8, X, Y, _) -> [Y, X, X, X]; %RIGHT 23 | digit(8, X, Y, _) -> [Y, Y, X, X]; %WRONG 24 | digit(9, X, _, Z) -> [X, Z]. 25 | 26 | main() -> 27 | to_roman(2489). 28 | 29 | 30 | %% Tests %% 31 | digit_8_test() -> 32 | ?assertEqual(to_roman(8), [86, 73, 73, 73]), 33 | ?assertEqual(digit(8, 88, 76, 67), [76, 88, 88, 88]). 34 | 35 | -------------------------------------------------------------------------------- /examples/Unified_Framework/sieve/README.md: -------------------------------------------------------------------------------- 1 | # Sieve of Eratosthenes 2 | http://rosettacode.org/wiki/Sieve_of_Eratosthenes 3 | -------------------------------------------------------------------------------- /examples/Unified_Framework/sieve/no_tests/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Unified_Framework/sieve/no_tests/dbg.pdf -------------------------------------------------------------------------------- /examples/Unified_Framework/sieve/no_tests/sieve.erl: -------------------------------------------------------------------------------- 1 | -module(sieve). 2 | -export([find_primes_below/1]). 3 | 4 | -include_lib("eunit/include/eunit.hrl"). 5 | 6 | 7 | find_primes_below(N) -> 8 | NumList = lists:seq(1, N), 9 | determine_primes(NumList, 1, []). 10 | 11 | %% Sieve of Eratosthenes algorithm 12 | determine_primes(NumList, Index, Primes) -> 13 | case next_prime(NumList, Index+1, length(NumList)) of 14 | {Prime, PrimeIndex, NewNumList} -> 15 | NewPrimes = lists:append(Primes, [Prime]), 16 | determine_primes(NewNumList, PrimeIndex, NewPrimes); 17 | _ -> 18 | %% All prime numbers have been calculated 19 | Primes 20 | end. 21 | 22 | next_prime(_, Index, Length) when Index > Length -> 23 | false; 24 | next_prime(NumList, Index, Length) -> 25 | case lists:nth(Index, NumList) of 26 | 0 -> 27 | %next_prime(NumList, Index+1, Length); % RIGHT 28 | next_prime(NumList, Index+2, Length); % WRONG 29 | Prime -> 30 | NewNumList = lists:map(fun(A) -> 31 | if A > Index andalso A rem Index == 0 -> 0; 32 | true -> A 33 | end 34 | end, NumList), 35 | {Prime, Index, NewNumList} 36 | end. 37 | 38 | -------------------------------------------------------------------------------- /examples/Unified_Framework/sieve/sieve_ok.erl: -------------------------------------------------------------------------------- 1 | %% Task: Implementation of Sieve of Eratosthenes 2 | %% Author: Abhay Jain 3 | -module(sieve_ok). 4 | -compile([export_all]). 5 | 6 | 7 | find_primes_below(N) -> 8 | NumList = lists:seq(1, N), 9 | determine_primes(NumList, 1, []). 10 | 11 | 12 | %% Sieve of Eratosthenes algorithm 13 | determine_primes(NumList, Index, Primes) -> 14 | case next_prime(NumList, Index+1, length(NumList)) of 15 | {Prime, PrimeIndex, NewNumList} -> 16 | NewPrimes = lists:append(Primes, [Prime]), 17 | determine_primes(NewNumList, PrimeIndex, NewPrimes); 18 | _ -> 19 | %% All prime numbers have been calculated 20 | Primes 21 | end. 22 | 23 | 24 | next_prime(_, Index, Length) when Index > Length -> 25 | false; 26 | next_prime(NumList, Index, Length) -> 27 | case lists:nth(Index, NumList) of 28 | 0 -> 29 | next_prime(NumList, Index+1, Length); 30 | Prime -> 31 | NewNumList = lists:map(fun(A) -> 32 | if A > Index andalso A rem Index == 0 -> 0; 33 | true -> A 34 | end 35 | end, NumList), 36 | {Prime, Index, NewNumList} 37 | end. 38 | -------------------------------------------------------------------------------- /examples/Unified_Framework/sieve/tests/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Unified_Framework/sieve/tests/dbg.pdf -------------------------------------------------------------------------------- /examples/Unified_Framework/sieve/tests/sieve.erl: -------------------------------------------------------------------------------- 1 | -module(sieve). 2 | -export([find_primes_below/1]). 3 | 4 | -include_lib("eunit/include/eunit.hrl"). 5 | 6 | 7 | find_primes_below(N) -> 8 | NumList = lists:seq(1, N), 9 | determine_primes(NumList, 1, []). 10 | 11 | %% Sieve of Eratosthenes algorithm 12 | determine_primes(NumList, Index, Primes) -> 13 | case next_prime(NumList, Index+1, length(NumList)) of 14 | {Prime, PrimeIndex, NewNumList} -> 15 | NewPrimes = lists:append(Primes, [Prime]), 16 | determine_primes(NewNumList, PrimeIndex, NewPrimes); 17 | _ -> 18 | %% All prime numbers have been calculated 19 | Primes 20 | end. 21 | 22 | next_prime(_, Index, Length) when Index > Length -> 23 | false; 24 | next_prime(NumList, Index, Length) -> 25 | case lists:nth(Index, NumList) of 26 | 0 -> 27 | %next_prime(NumList, Index+1, Length); % RIGHT 28 | next_prime(NumList, Index+2, Length); % WRONG 29 | Prime -> 30 | NewNumList = lists:map(fun(A) -> 31 | if A > Index andalso A rem Index == 0 -> 0; 32 | true -> A 33 | end 34 | end, NumList), 35 | {Prime, Index, NewNumList} 36 | end. 37 | 38 | 39 | %% Tests %% 40 | prime_test() -> 41 | ?assertEqual(find_primes_below(20), [2,3,5,7,11,13,17,19]), 42 | ?assertEqual(next_prime([1,2,3,0,5,0,7,0,0,0,11,0,13,0,0,0,17,0,19,0], 18, 20), 19), 43 | ?assertEqual(next_prime([1,2,3,0,5,0,7,0,0,0,11,0,13,0,0,0,17,0,19,0], 20, 20), false). 44 | 45 | -------------------------------------------------------------------------------- /examples/Unified_Framework/stock/README.md: -------------------------------------------------------------------------------- 1 | # Stock Management 2 | Enrique Martin-Martin (emartinm@ucm.es) 3 | -------------------------------------------------------------------------------- /examples/Unified_Framework/stock/no_tests/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Unified_Framework/stock/no_tests/dbg.pdf -------------------------------------------------------------------------------- /examples/Unified_Framework/stock/session.txt: -------------------------------------------------------------------------------- 1 | WITHOUT TESTS 2 | ============= 3 | > edd:dd( "stock:test()", tree ). 4 | Total number of tree nodes: 14 5 | Tree size: 6 | 4184 words 7 | 33472 bytes 8 | Please, insert a list of trusted functions separated by commas (e.g. m1:f1/a1, m2:f2/a2 ...): 9 | 10 | stock:unify_orders([{item, water, 3}, {item, rice, 3}, {item, rice, 4}]) = [{item, water, 3}, {item, rice, 7}]? [y/n/t/v/d/i/s/u/a]: y 11 | stock:check_order([{item, water, 3}, {item, rice, 7}], [{item, rice, 5}, {item, bajoqueta, 8}]) = [{item, water, 3}, {item, rice, 7}]? [y/n/t/v/d/i/s/u/a]: n 12 | fun (X) -> check_item(X, [{item, rice, 5}, {item, bajoqueta, 8}]) end({item, rice, 7}) = {true, {item, rice, 7}} 13 | fun location: (stock.erl, line 28)? [y/n/t/v/d/i/s/u/a]: n 14 | stock:check_item({item, rice, 7}, [{item, rice, 5}, {item, bajoqueta, 8}]) = {true, {item, rice, 7}}? [y/n/t/v/d/i/s/u/a]: n 15 | Call to a function that contains an error: 16 | stock:check_item({item, rice, 7}, [{item, rice, 5}, {item, bajoqueta, 8}]) = {true, {item, rice, 7}} 17 | Please, revise the first clause: 18 | check_item(Needed = {item, Name, Q1}, Stock) -> 19 | ItemStock = lists:keyfind(Name, 1, Stock), 20 | case ItemStock of 21 | {item, Name, Q2} -> 22 | if Q1 > Q2 -> {true, {item, Name, Q1 - Q2}}; 23 | true -> false 24 | end; 25 | false -> {true, Needed} 26 | end. 27 | 28 | 29 | USING TESTS 30 | =========== 31 | > edd:dd( "stock:test()", [] ). 32 | Total number of tree nodes: 14 33 | Tree size: 34 | 4184 words 35 | 33472 bytes 36 | Please, insert a list of trusted functions separated by commas (e.g. m1:f1/a1, m2:f2/a2 ...): 37 | 38 | Call to a function that contains an error: 39 | stock:check_item({item, rice, 7}, [{item, rice, 5}, {item, bajoqueta, 8}]) = {true, {item, rice, 7}} 40 | Please, revise the first clause: 41 | check_item(Needed = {item, Name, Q1}, Stock) -> 42 | ItemStock = lists:keyfind(Name, 1, Stock), 43 | case ItemStock of 44 | {item, Name, Q2} -> 45 | if Q1 > Q2 -> {true, {item, Name, Q1 - Q2}}; 46 | true -> false 47 | end; 48 | false -> {true, Needed} 49 | end. 50 | 51 | 52 | -------------------------------------------------------------------------------- /examples/Unified_Framework/stock/stock_ok.erl: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%% 2 | % Enrique Martin-Martin % 3 | % emartinm@fdi.ucm.es % 4 | %%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | % Stock Management 7 | % 8 | % The representation of the items in the stock are tuples 9 | % {iten, Item_Name, Quantity} 10 | % The stock is represented as a list of items without repetitions of the same item 11 | % Orders are also represented as lists of items 12 | 13 | -module(stock_ok). 14 | -compile([export_all]). 15 | 16 | % It should return that we need to buy 2 packs of rice and 3 bottles of water 17 | % (i.e., [{item, rice, 2},{item,water,3}]), however it incorrectly returns 18 | % [{item,water,3},{item,rice,7}] 19 | test() -> 20 | check_orders( [[{item, water, 3},{item, rice, 3}],[{item, rice, 4}]], 21 | [{item, rice, 5}, {item, bajoqueta, 8}]). 22 | 23 | 24 | % Given one Order and a Stock, returns the list of items we have to buy to 25 | % answer the order 26 | % If we have enough items in the stock, returns [] 27 | check_order( Order, Stock ) -> 28 | lists:zf( fun(X) -> check_item(X,Stock) end, Order ). 29 | 30 | 31 | % Function to use with lists:zf/2 to map and filter that checks the state of an 32 | % item in the stock 33 | % If there are enough items in the stock, returns false 34 | % If there aren't enough items in the stock (or there are no items of that kind 35 | % at all) returns {true, Item}, where item contains the quantity needed 36 | check_item( Needed = {item, Name, Q1}, Stock ) -> 37 | ItemStock = lists:keyfind(Name, 2, Stock), %RIGHT 38 | case ItemStock of 39 | {item, Name, Q2} -> 40 | if Q1 > Q2 -> {true, {item, Name, Q1 - Q2}}; 41 | true -> false 42 | end; 43 | false -> {true, Needed} 44 | end. 45 | 46 | 47 | % Similar to check_order/2 but considering a list of orders 48 | check_orders( List_of_orders, Stock ) -> 49 | Flat_orders = lists:flatten( List_of_orders ), 50 | Unique_orders = unify_orders( Flat_orders ), 51 | check_order( Unique_orders, Stock ). 52 | 53 | 54 | % Unify a list of orders in one order, adding the needed quantities 55 | unify_orders( [] ) -> []; 56 | unify_orders( [{item,Name,Quantity}|R] ) -> 57 | {Item_orders, Other_orders} = lists:partition( fun({item, ItemName, _}) -> ItemName == Name end, R ), 58 | Total_quantity = lists:foldr( fun({item,_,N}, Acc) -> N + Acc end, 0, Item_orders), 59 | Unif_rest = unify_orders( Other_orders ), 60 | [ {item, Name, Total_quantity + Quantity} | Unif_rest ]. 61 | -------------------------------------------------------------------------------- /examples/Unified_Framework/stock/tests/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Unified_Framework/stock/tests/dbg.pdf -------------------------------------------------------------------------------- /examples/Unified_Framework/sum_digits/README.md: -------------------------------------------------------------------------------- 1 | # Sum digits of an integer 2 | http://rosettacode.org/wiki/Sum_digits_of_an_integer 3 | -------------------------------------------------------------------------------- /examples/Unified_Framework/sum_digits/no_tests/colors.dot: -------------------------------------------------------------------------------- 1 | digraph PDG { 2 | 1 [shape=ellipse, label="1 .- sum_digits:sum_digits(13, 10, 15) = 18"]; 3 | 3 [shape=ellipse, label="3 .- sum_digits:sum_digits(1345, 10, 6) = 18"]; 4 | 4 [shape=ellipse, label="4 .- sum_digits:sum_digits(13456, 10, 0) = 18"]; 5 | 0 [shape=ellipse, label="0 .- sum_digits:sum_digits(1, 10, 18) = 18"]; 6 | 6 [shape=ellipse, label="6 .- sum_digits:sum_digits(13456) = 18"]; 7 | 2 [shape=ellipse, label="2 .- sum_digits:sum_digits(134, 10, 11) = 18"]; 8 | 5 [shape=ellipse, label="5 .- sum_digits:sum_digits(13456, 10) = 18"]; 9 | 1 -> 0 [color=black, penwidth=3]; 10 | 3 -> 2 [color=black, penwidth=3]; 11 | 4 -> 3 [color=black, penwidth=3]; 12 | 6 -> 5 [color=black, penwidth=3]; 13 | 2 -> 1 [color=black, penwidth=3]; 14 | 5 -> 4 [color=black, penwidth=3]; 15 | } -------------------------------------------------------------------------------- /examples/Unified_Framework/sum_digits/no_tests/dbg.dot: -------------------------------------------------------------------------------- 1 | digraph PDG { 2 | 1 [shape=ellipse, label="1 .- sum_digits:sum_digits(13, 10, 15) = 18"]; 3 | 3 [shape=ellipse, label="3 .- sum_digits:sum_digits(1345, 10, 6) = 18"]; 4 | 4 [shape=ellipse, label="4 .- sum_digits:sum_digits(13456, 10, 0) = 18"]; 5 | 0 [shape=ellipse, label="0 .- sum_digits:sum_digits(1, 10, 18) = 18"]; 6 | 6 [shape=ellipse, label="6 .- sum_digits:sum_digits(13456) = 18"]; 7 | 2 [shape=ellipse, label="2 .- sum_digits:sum_digits(134, 10, 11) = 18"]; 8 | 5 [shape=ellipse, label="5 .- sum_digits:sum_digits(13456, 10) = 18"]; 9 | 1 -> 0 [color=black, penwidth=3]; 10 | 3 -> 2 [color=black, penwidth=3]; 11 | 4 -> 3 [color=black, penwidth=3]; 12 | 6 -> 5 [color=black, penwidth=3]; 13 | 2 -> 1 [color=black, penwidth=3]; 14 | 5 -> 4 [color=black, penwidth=3]; 15 | } -------------------------------------------------------------------------------- /examples/Unified_Framework/sum_digits/no_tests/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Unified_Framework/sum_digits/no_tests/dbg.pdf -------------------------------------------------------------------------------- /examples/Unified_Framework/sum_digits/no_tests/sum_digits.erl: -------------------------------------------------------------------------------- 1 | -module(sum_digits). 2 | -compile(export_all). 3 | 4 | -include_lib("proper/include/proper.hrl"). 5 | -include_lib("eunit/include/eunit.hrl"). 6 | 7 | 8 | sum_digits(N) -> 9 | sum_digits(N,10). 10 | 11 | sum_digits(N,B) -> 12 | sum_digits(N,B,0). 13 | 14 | sum_digits(0,_,Acc) -> 15 | Acc; 16 | sum_digits(N,B,Acc) when N < B -> 17 | %Acc+N; %RIGHT 18 | Acc; %WRONG 19 | sum_digits(N,B,Acc) -> 20 | sum_digits(N div B, B, Acc + (N rem B)). 21 | 22 | -------------------------------------------------------------------------------- /examples/Unified_Framework/sum_digits/session.txt: -------------------------------------------------------------------------------- 1 | WITHOUT TESTS 2 | ============= 3 | > edd:dd("sum_digits:sum_digits(13456)", [tree]). 4 | Total number of tree nodes: 7 5 | Tree size: 6 | 1749 words 7 | 13992 bytes 8 | Please, insert a list of trusted functions separated by commas (e.g. m1:f1/a1, m2:f2/a2 ...): 9 | 10 | sum_digits:sum_digits(1345, 10, 6) = 18? [y/n/t/v/d/i/s/u/a]: n 11 | sum_digits:sum_digits(13, 10, 15) = 18? [y/n/t/v/d/i/s/u/a]: n 12 | sum_digits:sum_digits(1, 10, 18) = 18? [y/n/t/v/d/i/s/u/a]: n 13 | Call to a function that contains an error: 14 | sum_digits:sum_digits(1, 10, 18) = 18 15 | Please, revise the second clause: 16 | sum_digits(N, B, Acc) when N < B -> Acc. 17 | 18 | 19 | 20 | USING TESTS 21 | =========== 22 | > edd:dd("sum_digits:sum_digits(13456)"). 23 | Total number of tree nodes: 7 24 | Tree size: 25 | 1749 words 26 | 13992 bytes 27 | Please, insert a list of trusted functions separated by commas (e.g. m1:f1/a1, m2:f2/a2 ...): 28 | 29 | Call to a function that contains an error: 30 | sum_digits:sum_digits(1, 10, 18) = 18 31 | Please, revise the second clause: 32 | sum_digits(N, B, Acc) when N < B -> Acc. 33 | 34 | -------------------------------------------------------------------------------- /examples/Unified_Framework/sum_digits/sum_digits_ok.erl: -------------------------------------------------------------------------------- 1 | -module(sum_digits_ok). 2 | -compile([export_all]). 3 | 4 | sum_digits(N) -> 5 | sum_digits(N,10). 6 | 7 | sum_digits(N,B) -> 8 | sum_digits(N,B,0). 9 | 10 | sum_digits(0,_,Acc) -> 11 | Acc; 12 | sum_digits(N,B,Acc) when N < B -> 13 | Acc+N; 14 | sum_digits(N,B,Acc) -> 15 | sum_digits(N div B, B, Acc + (N rem B)). 16 | -------------------------------------------------------------------------------- /examples/Unified_Framework/sum_digits/tests/colors.dot: -------------------------------------------------------------------------------- 1 | digraph PDG { 2 | 1 [shape=ellipse, label="1 .- sum_digits:sum_digits(13, 10, 15) = 18" style=filled color="red" fontcolor="white" fillcolor="red"]; 3 | 3 [shape=ellipse, label="3 .- sum_digits:sum_digits(1345, 10, 6) = 18" style=filled color="red" fontcolor="white" fillcolor="red"]; 4 | 4 [shape=ellipse, label="4 .- sum_digits:sum_digits(13456, 10, 0) = 18" style=filled color="red" fontcolor="white" fillcolor="red"]; 5 | 0 [shape=ellipse, label="0 .- sum_digits:sum_digits(1, 10, 18) = 18" style=filled color="red" fontcolor="white" fillcolor="red"]; 6 | 6 [shape=ellipse, label="6 .- sum_digits:sum_digits(13456) = 18"]; 7 | 2 [shape=ellipse, label="2 .- sum_digits:sum_digits(134, 10, 11) = 18" style=filled color="red" fontcolor="white" fillcolor="red"]; 8 | 5 [shape=ellipse, label="5 .- sum_digits:sum_digits(13456, 10) = 18"]; 9 | 1 -> 0 [color=black, penwidth=3]; 10 | 3 -> 2 [color=black, penwidth=3]; 11 | 4 -> 3 [color=black, penwidth=3]; 12 | 6 -> 5 [color=black, penwidth=3]; 13 | 2 -> 1 [color=black, penwidth=3]; 14 | 5 -> 4 [color=black, penwidth=3]; 15 | } -------------------------------------------------------------------------------- /examples/Unified_Framework/sum_digits/tests/dbg.dot: -------------------------------------------------------------------------------- 1 | digraph PDG { 2 | 1 [shape=ellipse, label="1 .- sum_digits:sum_digits(13, 10, 15) = 18"]; 3 | 3 [shape=ellipse, label="3 .- sum_digits:sum_digits(1345, 10, 6) = 18"]; 4 | 4 [shape=ellipse, label="4 .- sum_digits:sum_digits(13456, 10, 0) = 18"]; 5 | 0 [shape=ellipse, label="0 .- sum_digits:sum_digits(1, 10, 18) = 18"]; 6 | 6 [shape=ellipse, label="6 .- sum_digits:sum_digits(13456) = 18"]; 7 | 2 [shape=ellipse, label="2 .- sum_digits:sum_digits(134, 10, 11) = 18"]; 8 | 5 [shape=ellipse, label="5 .- sum_digits:sum_digits(13456, 10) = 18"]; 9 | 1 -> 0 [color=black, penwidth=3]; 10 | 3 -> 2 [color=black, penwidth=3]; 11 | 4 -> 3 [color=black, penwidth=3]; 12 | 6 -> 5 [color=black, penwidth=3]; 13 | 2 -> 1 [color=black, penwidth=3]; 14 | 5 -> 4 [color=black, penwidth=3]; 15 | } -------------------------------------------------------------------------------- /examples/Unified_Framework/sum_digits/tests/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Unified_Framework/sum_digits/tests/dbg.pdf -------------------------------------------------------------------------------- /examples/Unified_Framework/sum_digits/tests/sum_digits.erl: -------------------------------------------------------------------------------- 1 | -module(sum_digits). 2 | -compile(export_all). 3 | 4 | -include_lib("proper/include/proper.hrl"). 5 | -include_lib("eunit/include/eunit.hrl"). 6 | 7 | 8 | sum_digits(N) -> 9 | sum_digits(N,10). 10 | 11 | sum_digits(N,B) -> 12 | sum_digits(N,B,0). 13 | 14 | sum_digits(0,_,Acc) -> 15 | Acc; 16 | sum_digits(N,B,Acc) when N < B -> 17 | %Acc+N; %RIGHT 18 | Acc; %WRONG 19 | sum_digits(N,B,Acc) -> 20 | sum_digits(N div B, B, Acc + (N rem B)). 21 | 22 | 23 | %% Tests %% 24 | sum_digits_property_complete() -> 25 | ?FORALL({N, Acc}, 26 | {integer(0,9), non_neg_integer()}, 27 | sum_digits(N, 10, Acc) =:= N + Acc). 28 | 29 | -------------------------------------------------------------------------------- /examples/Unified_Framework/ternary/README.md: -------------------------------------------------------------------------------- 1 | # Balanced ternary 2 | http://rosettacode.org/wiki/Balanced_ternary 3 | -------------------------------------------------------------------------------- /examples/Unified_Framework/ternary/no_tests/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Unified_Framework/ternary/no_tests/dbg.pdf -------------------------------------------------------------------------------- /examples/Unified_Framework/ternary/no_tests/ternary.erl: -------------------------------------------------------------------------------- 1 | -module(ternary). 2 | -compile(export_all). 3 | 4 | -include_lib("proper/include/proper.hrl"). 5 | -include_lib("eunit/include/eunit.hrl"). 6 | 7 | test() -> 8 | AS = "+-0++0+", 9 | AT = from_string(AS), 10 | A = from_ternary(AT), 11 | B = 985412, 12 | BT = to_ternary(B), 13 | BS = to_string(BT), 14 | [{AS,A},{BS,B}]. 15 | 16 | 17 | to_string(T) -> [to_char(X) || X <- T]. 18 | 19 | from_string(S) -> [from_char(X) || X <- S]. 20 | 21 | to_char(-1) -> $-; 22 | to_char(0) -> $0; 23 | to_char(1) -> $+. 24 | 25 | from_char($-) -> -1; 26 | from_char($0) -> 0; 27 | from_char($+) -> 1. 28 | 29 | to_ternary(N) when N > 0 -> 30 | to_ternary(N,[]); 31 | to_ternary(N) -> 32 | neg(to_ternary(-N)). 33 | 34 | to_ternary(0,Acc) -> 35 | Acc; 36 | to_ternary(N,Acc) when N rem 3 == 0 -> 37 | to_ternary(N div 3, [0|Acc]); 38 | to_ternary(N,Acc) when N rem 3 == 1 -> 39 | to_ternary(N div 3, [1|Acc]); 40 | to_ternary(N,Acc) -> 41 | %to_ternary((N+1) div 3, [-1|Acc]).%RIGHT 42 | to_ternary((N+1) div 3, [1|Acc]).%WRONG 43 | 44 | from_ternary(T) -> from_ternary(T,0). 45 | 46 | from_ternary([],Acc) -> 47 | Acc; 48 | from_ternary([H|T],Acc) -> 49 | from_ternary(T,Acc*3 + H). 50 | 51 | mul(A,B) -> mul(B,A,[]). 52 | 53 | mul(_,[],Acc) -> 54 | Acc; 55 | mul(B,[A|As],Acc) -> 56 | BP = case A of 57 | -1 -> neg(B); 58 | 0 -> [0]; 59 | 1 -> B 60 | end, 61 | A1 = Acc++[0], 62 | A2=add(BP,A1), 63 | mul(B,As,A2). 64 | 65 | 66 | neg(T) -> [ -H || H <- T]. 67 | 68 | sub(A,B) -> add(A,neg(B)). 69 | 70 | add(A,B) when length(A) < length(B) -> 71 | add(lists:duplicate(length(B)-length(A),0)++A,B); 72 | add(A,B) when length(A) > length(B) -> 73 | add(B,A); 74 | add(A,B) -> 75 | add(lists:reverse(A),lists:reverse(B),0,[]). 76 | 77 | add([],[],0,Acc) -> 78 | Acc; 79 | add([],[],C,Acc) -> 80 | [C|Acc]; 81 | add([A|As],[B|Bs],C,Acc) -> 82 | [C1,D] = add_util(A+B+C), 83 | add(As,Bs,C1,[D|Acc]). 84 | 85 | add_util(-3) -> [-1,0]; 86 | add_util(-2) -> [-1,1]; 87 | add_util(-1) -> [0,-1]; 88 | add_util(3) -> [1,0]; 89 | add_util(2) -> [1,-1]; 90 | add_util(1) -> [0,1]; 91 | add_util(0) -> [0,0]. 92 | 93 | -------------------------------------------------------------------------------- /examples/Unified_Framework/ternary/session.txt: -------------------------------------------------------------------------------- 1 | WITHOUT TESTS 2 | ============= 3 | > edd:dd("ternary:test()", [tree]). 4 | Total number of tree nodes: 49 5 | Tree size: 6 | 8495 words 7 | 67960 bytes 8 | Please, insert a list of trusted functions separated by commas (e.g. m1:f1/a1, m2:f2/a2 ...): 9 | 10 | ternary:to_ternary(985412) = [1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1]? [y/n/t/v/d/i/s/u/a]: n 11 | ternary:to_ternary(451, [1, 1, 1, 1, 1, 1, 1]) = [1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1]? [y/n/t/v/d/i/s/u/a]: n 12 | ternary:to_ternary(6, [1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1]) = [1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1]? [y/n/t/v/d/i/s/u/a]: n 13 | ternary:to_ternary(1, [1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1]) = [1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1]? [y/n/t/v/d/i/s/u/a]: y 14 | ternary:to_ternary(2, [0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1]) = [1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1]? [y/n/t/v/d/i/s/u/a]: n 15 | Call to a function that contains an error: 16 | ternary:to_ternary(2, [0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1]) = [1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1] 17 | Please, revise the fourth clause: 18 | to_ternary(N, Acc) -> 19 | to_ternary((N + 1) div 3, [1 | Acc]). 20 | 21 | 22 | 23 | USING TESTS 24 | =========== 25 | > edd:dd("ternary:test()", [tree]). 26 | Total number of tree nodes: 49 27 | Tree size: 28 | 8495 words 29 | 67960 bytes 30 | Please, insert a list of trusted functions separated by commas (e.g. m1:f1/a1, m2:f2/a2 ...): 31 | 32 | Call to a function that contains an error: 33 | ternary:to_ternary(2, [0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1]) = [1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1] 34 | Please, revise the fourth clause: 35 | to_ternary(N, Acc) -> 36 | to_ternary((N + 1) div 3, [1 | Acc]). 37 | 38 | 39 | -------------------------------------------------------------------------------- /examples/Unified_Framework/ternary/ternary_ok.erl: -------------------------------------------------------------------------------- 1 | %edd:dd("ternary:test()"). 2 | -module(ternary_ok). 3 | -compile(export_all). 4 | 5 | -include_lib("eunit/include/eunit.hrl"). 6 | 7 | test() -> 8 | AS = "+-0++0+", AT = from_string(AS), A = from_ternary(AT), 9 | B = -436, BT = to_ternary(B), BS = to_string(BT), 10 | [{AS,A},{BS,B}]. 11 | 12 | 13 | to_string(T) -> [to_char(X) || X <- T]. 14 | 15 | from_string(S) -> [from_char(X) || X <- S]. 16 | 17 | to_char(-1) -> $-; 18 | to_char(0) -> $0; 19 | to_char(1) -> $+. 20 | 21 | from_char($-) -> -1; 22 | from_char($0) -> 0; 23 | from_char($+) -> 1. 24 | 25 | to_ternary(N) when N > 0 -> 26 | to_ternary(N,[]); 27 | to_ternary(N) -> 28 | neg(to_ternary(-N)). 29 | 30 | to_ternary(0,Acc) -> 31 | Acc; 32 | to_ternary(N,Acc) when N rem 3 == 0 -> 33 | to_ternary(N div 3, [0|Acc]); 34 | to_ternary(N,Acc) when N rem 3 == 1 -> 35 | to_ternary(N div 3, [1|Acc]); 36 | to_ternary(N,Acc) -> 37 | to_ternary((N+1) div 3, [-1|Acc]). 38 | 39 | from_ternary(T) -> from_ternary(T,0). 40 | 41 | from_ternary([],Acc) -> 42 | Acc; 43 | from_ternary([H|T],Acc) -> 44 | from_ternary(T,Acc*3 + H). 45 | 46 | mul(A,B) -> mul(B,A,[]). 47 | 48 | mul(_,[],Acc) -> 49 | Acc; 50 | mul(B,[A|As],Acc) -> 51 | BP = case A of 52 | -1 -> neg(B); 53 | 0 -> [0]; 54 | 1 -> B 55 | end, 56 | A1 = Acc++[0], 57 | A2=add(BP,A1), 58 | mul(B,As,A2). 59 | 60 | 61 | neg(T) -> [ -H || H <- T]. 62 | 63 | sub(A,B) -> add(A,neg(B)). 64 | 65 | add(A,B) when length(A) < length(B) -> 66 | add(lists:duplicate(length(B)-length(A),0)++A,B); 67 | add(A,B) when length(A) > length(B) -> 68 | add(B,A); 69 | add(A,B) -> 70 | add(lists:reverse(A),lists:reverse(B),0,[]). 71 | 72 | add([],[],0,Acc) -> 73 | Acc; 74 | add([],[],C,Acc) -> 75 | [C|Acc]; 76 | add([A|As],[B|Bs],C,Acc) -> 77 | [C1,D] = add_util(A+B+C), 78 | add(As,Bs,C1,[D|Acc]). 79 | 80 | add_util(-3) -> [-1,0]; 81 | add_util(-2) -> [-1,1]; 82 | add_util(-1) -> [0,-1]; 83 | add_util(3) -> [1,0]; 84 | add_util(2) -> [1,-1]; 85 | add_util(1) -> [0,1]; 86 | add_util(0) -> [0,0]. 87 | 88 | 89 | %% Tests 90 | to_ternary_test() -> 91 | ?assertEqual(to_ternary(2, [1, 1, 0, 1, 1]), [1,-1,1,1,0,1,1]), 92 | ?assertEqual(to_ternary(1, [1, 1, 1, 0, 1, 1]), [1, 1, 1, 1, 0, 1, 1]). 93 | 94 | 95 | -------------------------------------------------------------------------------- /examples/Unified_Framework/ternary/tests/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Unified_Framework/ternary/tests/dbg.pdf -------------------------------------------------------------------------------- /examples/Unified_Framework/turing/README.md: -------------------------------------------------------------------------------- 1 | # Universal Turing machine 2 | http://rosettacode.org/wiki/Universal_Turing_machine 3 | -------------------------------------------------------------------------------- /examples/Unified_Framework/turing/no_tests/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Unified_Framework/turing/no_tests/dbg.pdf -------------------------------------------------------------------------------- /examples/Unified_Framework/turing/tests/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/Unified_Framework/turing/tests/dbg.pdf -------------------------------------------------------------------------------- /examples/Unified_Framework/turing/turing_ok.erl: -------------------------------------------------------------------------------- 1 | -module(turing_ok). 2 | -compile([export_all]). 3 | 4 | % Incrementer definition: 5 | % States: a | halt 6 | % Initial state: a 7 | % Halting states: halt 8 | % Symbols: b | '1' 9 | % Blank symbol: b 10 | incrementer_config() -> {a, [halt], b}. 11 | incrementer(a, '1') -> {'1', right, a}; 12 | incrementer(a, b) -> {'1', stay, halt}. 13 | 14 | % Busy beaver definition: 15 | % States: a | b | c | halt 16 | % Initial state: a 17 | % Halting states: halt 18 | % Symbols: '0' | '1' 19 | % Blank symbol: '0' 20 | busy_beaver_config() -> {a, [halt], '0'}. 21 | busy_beaver(a, '0') -> {'1', right, b}; 22 | busy_beaver(a, '1') -> {'1', left, c}; 23 | busy_beaver(b, '0') -> {'1', left, a}; 24 | busy_beaver(b, '1') -> {'1', right, b}; 25 | busy_beaver(c, '0') -> {'1', left, b}; 26 | busy_beaver(c, '1') -> {'1', stay, halt}. 27 | 28 | % Mainline code. 29 | main() -> 30 | %io:format("==============================~n"), 31 | %io:format("Turing machine simulator test.~n"), 32 | %io:format("==============================~n"), 33 | 34 | Tape1 = turing(fun incrementer_config/0, fun incrementer/2, ['1','1','1']), 35 | % io:format("~w~n", [Tape1]), 36 | 37 | Tape2 = turing(fun busy_beaver_config/0, fun busy_beaver/2, []), 38 | %io:format("~w~n", [Tape2]). 39 | {Tape1, Tape2}. 40 | 41 | % Universal Turing machine simulator. 42 | turing(Config, Rules, Input) -> 43 | {Start, _, _} = Config(), 44 | {Left, Right} = perform(Config, Rules, Start, {[], Input}), 45 | lists:reverse(Left) ++ Right. 46 | 47 | perform(Config, Rules, State, Input = {LeftInput, RightInput}) -> 48 | {_, Halts, Blank} = Config(), 49 | case lists:member(State, Halts) of 50 | true -> Input; 51 | false -> 52 | {NewRight, Symbol} = symbol(RightInput, Blank), 53 | {NewSymbol, Action, NewState} = Rules(State, Symbol), 54 | NewInput = action(Action, Blank, {LeftInput, [NewSymbol| NewRight]}), 55 | perform(Config, Rules, NewState, NewInput) 56 | end. 57 | 58 | symbol([], Blank) -> {[], Blank}; 59 | symbol([S|R], _) -> {R, S}. 60 | 61 | action(left, Blank, {[], Right}) -> 62 | {[], [Blank|Right]}; 63 | action(left, _, {[L|Ls], Right}) -> {Ls, [L|Right]}; 64 | action(stay, _, Tape) -> Tape; 65 | action(right, Blank, {Left, []}) -> {[Blank|Left], []}; 66 | action(right, _, {Left, [R|Rs]}) -> {[R|Left], Rs}. 67 | -------------------------------------------------------------------------------- /examples/Unified_Framework/vigenere/README.md: -------------------------------------------------------------------------------- 1 | # Vigenère cipher 2 | http://rosettacode.org/wiki/Vigen%C3%A8re_cipher 3 | 4 | -------------------------------------------------------------------------------- /examples/Unified_Framework/vigenere/no_tests/vigenere.erl: -------------------------------------------------------------------------------- 1 | -module(vigenere). 2 | -compile(export_all). 3 | 4 | -include_lib("proper/include/proper.hrl"). 5 | -include_lib("eunit/include/eunit.hrl"). 6 | 7 | % Utility functions for character tests and conversions 8 | isupper([C|_]) -> isupper(C); 9 | isupper(C) -> (C >= $A) and (C =< $Z). 10 | 11 | islower([C|_]) -> islower(C); 12 | islower(C) -> (C >= $a) and (C =< $z). 13 | 14 | isalpha([C|_]) -> isalpha(C); 15 | isalpha(C) -> isupper(C) or islower(C). 16 | 17 | toupper(S) when is_list(S) -> lists:map(fun toupper/1, S); 18 | toupper(C) when (C >= $a) and (C =< $z) -> C - $a + $A; 19 | toupper(C) -> C. 20 | 21 | % modulo function that normalizes into positive range for positive divisor 22 | mod(X,Y) -> (X rem Y + Y) rem Y. 23 | 24 | % convert letter to position in alphabet (A=0,B=1,...,Y=24,Z=25). 25 | to_pos(L) when L >= $A, L =< $Z -> L - $A. 26 | 27 | % convert position in alphabet back to letter 28 | from_pos(N) -> mod(N, 26) + $A. 29 | 30 | % encode the given letter given the single-letter key 31 | encipher(P, K) -> from_pos(to_pos(P) + to_pos(K)). 32 | 33 | % decode the given letter given the single-letter key 34 | decipher(C, K) -> from_pos(to_pos(C) - to_pos(K)). 35 | 36 | % extend a list by repeating it until it has exactly N elements 37 | cycle_to(N, List) when length(List) >= N -> List; 38 | cycle_to(N, List) -> lists:append(List, cycle_to(N-length(List), List)). 39 | % The bug is that cycle_to does not trim the remaining length of the list in the 40 | % base case. The first rule should be: 41 | % cycle_to(N, List) when length(List) >= N -> 42 | % {Take,_} = lists:split(N,List), 43 | % Take; 44 | 45 | % Encryption prep: reduce string to only its letters, in uppercase 46 | normalize(Str) -> toupper(lists:filter(fun isalpha/1, Str)). 47 | 48 | crypt(RawText, RawKey, Func) -> 49 | PlainText = normalize(RawText), 50 | lists:zipwith(Func, PlainText, cycle_to(length(PlainText), normalize(RawKey))). 51 | 52 | encrypt(Text, Key) -> crypt(Text, Key, fun encipher/2). 53 | decrypt(Text, Key) -> crypt(Text, Key, fun decipher/2). 54 | 55 | -------------------------------------------------------------------------------- /examples/Unified_Framework/vigenere/session.txt: -------------------------------------------------------------------------------- 1 | > edd:dd("vigenere:encrypt(\"Attack tomorrow dawn\", \"lemon\")", [tree]). 2 | Total number of tree nodes: 198 3 | Tree size: 4 | 24990 words 5 | 199920 bytes 6 | Please, insert a list of trusted functions separated by commas (e.g. m1:f1/a1, m2:f2/a2 ...): 7 | 8 | vigenere:normalize("Attack tomorrow dawn") = "ATTACKTOMORROWDAWN"? [y/n/t/v/d/i/s/u/a]: y 9 | vigenere:normalize("lemon") = "LEMON"? [y/n/t/v/d/i/s/u/a]: y 10 | vigenere:encipher(78, 77) = 90? [y/n/t/v/d/i/s/u/a]: y 11 | vigenere:encipher(87, 69) = 65? [y/n/t/v/d/i/s/u/a]: y 12 | vigenere:encipher(65, 76) = 76? [y/n/t/v/d/i/s/u/a]: y 13 | vigenere:encipher(68, 78) = 81? [y/n/t/v/d/i/s/u/a]: y 14 | vigenere:encipher(87, 79) = 75? [y/n/t/v/d/i/s/u/a]: y 15 | vigenere:encipher(79, 77) = 65? [y/n/t/v/d/i/s/u/a]: y 16 | vigenere:encipher(82, 69) = 86? [y/n/t/v/d/i/s/u/a]: y 17 | vigenere:encipher(82, 76) = 67? [y/n/t/v/d/i/s/u/a]: y 18 | vigenere:encipher(79, 78) = 66? [y/n/t/v/d/i/s/u/a]: y 19 | vigenere:encipher(77, 79) = 65? [y/n/t/v/d/i/s/u/a]: y 20 | vigenere:encipher(84, 69) = 88? [y/n/t/v/d/i/s/u/a]: y 21 | vigenere:encipher(75, 76) = 86? [y/n/t/v/d/i/s/u/a]: y 22 | vigenere:encipher(67, 78) = 80? [y/n/t/v/d/i/s/u/a]: y 23 | vigenere:encipher(65, 79) = 79? [y/n/t/v/d/i/s/u/a]: y 24 | vigenere:encipher(84, 77) = 70? [y/n/t/v/d/i/s/u/a]: y 25 | vigenere:cycle_to(13, "LEMON") = "LEMONLEMONLEMON"? [y/n/t/v/d/i/s/u/a]: n 26 | vigenere:cycle_to(8, "LEMON") = "LEMONLEMON"? [y/n/t/v/d/i/s/u/a]: n 27 | vigenere:cycle_to(3, "LEMON") = "LEMON"? [y/n/t/v/d/i/s/u/a]: n 28 | Call to a function that contains an error: 29 | vigenere:cycle_to(3, "LEMON") = "LEMON" 30 | Please, revise the first clause: 31 | cycle_to(N, List) when length(List) >= N -> List. 32 | 33 | 34 | 35 | 36 | USING TESTS 37 | ----------- 38 | > edd:dd("vigenere:encrypt(\"Attack tomorrow dawn\", \"lemon\")", [tree]). Total number of tree nodes: 198 39 | Tree size: 40 | 24990 words 41 | 199920 bytes 42 | Please, insert a list of trusted functions separated by commas (e.g. m1:f1/a1, m2:f2/a2 ...): 43 | 44 | Call to a function that contains an error: 45 | vigenere:cycle_to(3, "LEMON") = "LEMON" 46 | Please, revise the first clause: 47 | cycle_to(N, List) when length(List) >= N -> List. 48 | 49 | -------------------------------------------------------------------------------- /examples/Unified_Framework/vigenere/tests/vigenere.erl: -------------------------------------------------------------------------------- 1 | -module(vigenere). 2 | -compile(export_all). 3 | 4 | -include_lib("proper/include/proper.hrl"). 5 | -include_lib("eunit/include/eunit.hrl"). 6 | 7 | % Utility functions for character tests and conversions 8 | isupper([C|_]) -> isupper(C); 9 | isupper(C) -> (C >= $A) and (C =< $Z). 10 | 11 | islower([C|_]) -> islower(C); 12 | islower(C) -> (C >= $a) and (C =< $z). 13 | 14 | isalpha([C|_]) -> isalpha(C); 15 | isalpha(C) -> isupper(C) or islower(C). 16 | 17 | toupper(S) when is_list(S) -> lists:map(fun toupper/1, S); 18 | toupper(C) when (C >= $a) and (C =< $z) -> C - $a + $A; 19 | toupper(C) -> C. 20 | 21 | % modulo function that normalizes into positive range for positive divisor 22 | mod(X,Y) -> (X rem Y + Y) rem Y. 23 | 24 | % convert letter to position in alphabet (A=0,B=1,...,Y=24,Z=25). 25 | to_pos(L) when L >= $A, L =< $Z -> L - $A. 26 | 27 | % convert position in alphabet back to letter 28 | from_pos(N) -> mod(N, 26) + $A. 29 | 30 | % encode the given letter given the single-letter key 31 | encipher(P, K) -> from_pos(to_pos(P) + to_pos(K)). 32 | 33 | % decode the given letter given the single-letter key 34 | decipher(C, K) -> from_pos(to_pos(C) - to_pos(K)). 35 | 36 | % extend a list by repeating it until it has exactly N elements 37 | cycle_to(N, List) when length(List) >= N -> List; 38 | cycle_to(N, List) -> lists:append(List, cycle_to(N-length(List), List)). 39 | % The bug is that cycle_to does not trim the remaining length of the list in the 40 | % base case. The first rule should be: 41 | % cycle_to(N, List) when length(List) >= N -> 42 | % {Take,_} = lists:split(N,List), 43 | % Take; 44 | 45 | % Encryption prep: reduce string to only its letters, in uppercase 46 | normalize(Str) -> toupper(lists:filter(fun isalpha/1, Str)). 47 | 48 | crypt(RawText, RawKey, Func) -> 49 | PlainText = normalize(RawText), 50 | lists:zipwith(Func, PlainText, cycle_to(length(PlainText), normalize(RawKey))). 51 | 52 | encrypt(Text, Key) -> crypt(Text, Key, fun encipher/2). 53 | decrypt(Text, Key) -> crypt(Text, Key, fun decipher/2). 54 | 55 | 56 | %% Tests %% 57 | prop_cycle_property_subset() -> 58 | ?FORALL( 59 | {N, S}, 60 | {integer(1, 100), nonempty_string()}, 61 | length(cycle_to(N, S)) =:= N 62 | ). 63 | 64 | -------------------------------------------------------------------------------- /examples/Unified_Framework/vigenere/vigenere_ok.erl: -------------------------------------------------------------------------------- 1 | % Erlang implementation of Vigenère cipher 2 | % Code from Rosetta Code 3 | % http://rosettacode.org/wiki/Vigen%C3%A8re_cipher#Erlang 4 | 5 | -module(vigenere_ok). 6 | -export([encrypt/2, decrypt/2, from_pos/1, to_pos/1, encrypt/2]). 7 | -import(lists, [append/2, filter/2, map/2, zipwith/3]). 8 | 9 | % Utility functions for character tests and conversions 10 | isupper([C|_]) -> isupper(C); 11 | isupper(C) -> (C >= $A) and (C =< $Z). 12 | 13 | islower([C|_]) -> islower(C); 14 | islower(C) -> (C >= $a) and (C =< $z). 15 | 16 | isalpha([C|_]) -> isalpha(C); 17 | isalpha(C) -> isupper(C) or islower(C). 18 | 19 | toupper(S) when is_list(S) -> lists:map(fun toupper/1, S); 20 | toupper(C) when (C >= $a) and (C =< $z) -> C - $a + $A; 21 | toupper(C) -> C. 22 | 23 | % modulo function that normalizes into positive range for positive divisor 24 | mod(X,Y) -> (X rem Y + Y) rem Y. 25 | 26 | % convert letter to position in alphabet (A=0,B=1,...,Y=24,Z=25). 27 | to_pos(L) when L >= $A, L =< $Z -> L - $A. 28 | 29 | % convert position in alphabet back to letter 30 | from_pos(N) -> mod(N, 26) + $A. 31 | 32 | % encode the given letter given the single-letter key 33 | encipher(P, K) -> from_pos(to_pos(P) + to_pos(K)). 34 | 35 | % decode the given letter given the single-letter key 36 | decipher(C, K) -> from_pos(to_pos(C) - to_pos(K)). 37 | 38 | % extend a list by repeating it until it is at least N elements long 39 | %cycle_to(N, List) when length(List) >= N -> List; 40 | cycle_to(N, List) when length(List) >= N -> 41 | {Take,_} = lists:split(N,List), 42 | Take; 43 | cycle_to(N, List) -> append(List, cycle_to(N-length(List), List)). 44 | % The bug is that cycle_to does not trim the remaining length of the list in the 45 | % base case. The first rule should be: 46 | 47 | 48 | % Encryption prep: reduce string to only its letters, in uppercase 49 | normalize(Str) -> toupper(filter(fun isalpha/1, Str)). 50 | 51 | crypt(RawText, RawKey, Func) -> 52 | PlainText = normalize(RawText), 53 | zipwith(Func, PlainText, cycle_to(length(PlainText), normalize(RawKey))). 54 | 55 | encrypt(Text, Key) -> crypt(Text, Key, fun encipher/2). 56 | decrypt(Text, Key) -> crypt(Text, Key, fun decipher/2). 57 | -------------------------------------------------------------------------------- /examples/ackermann/Readme: -------------------------------------------------------------------------------- 1 | Ackermann function 2 | http://rosettacode.org/wiki/Ackermann_function 3 | -------------------------------------------------------------------------------- /examples/ackermann/ackermann.erl: -------------------------------------------------------------------------------- 1 | %edd:dd("ackerman:main([3,4])"). 2 | -module(ackerman). 3 | -export([main/1]). 4 | 5 | main( [A, B] ) -> 6 | % io:fwrite("~p~n",[ack(A,B)]). 7 | ack(A,B). 8 | 9 | %toi(E) -> element(1,string:to_integer(E)). 10 | 11 | ack(0,N) -> N + 1; 12 | ack(M,0) -> %ack(M-1, 1); %RIGHT 13 | ack(M-1, 0); %WRONG 14 | ack(M,N) -> ack(M-1,ack(M,N-1)). 15 | -------------------------------------------------------------------------------- /examples/ackermann/ackermann_ok.erl: -------------------------------------------------------------------------------- 1 | -module(ack_ok). 2 | -export([ack/2]). 3 | 4 | ack(0,N) -> N + 1; 5 | ack(M,0) -> ack(M-1, 1); 6 | ack(M,N) -> ack(M-1,ack(M,N-1)). 7 | -------------------------------------------------------------------------------- /examples/ackermann/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/ackermann/dbg.pdf -------------------------------------------------------------------------------- /examples/align_columns/Readme: -------------------------------------------------------------------------------- 1 | Align columns 2 | http://rosettacode.org/wiki/Align_columns 3 | -------------------------------------------------------------------------------- /examples/align_columns/align_columns.erl: -------------------------------------------------------------------------------- 1 | %edd:dd("align_columns:align_left()"). 2 | -module (align_columns). 3 | -export([align_left/0, align_right/0, align_center/0, prepare_line/3]). 4 | 5 | align_left()-> align_columns(left). 6 | align_right()-> align_columns(right). 7 | align_center()-> align_columns(centre). 8 | align_columns(Alignment) -> 9 | Lines = 10 | ["Given\$a\$text\$file\$of\$many\$lines\$where\$fields\$within\$a\$line\$", 11 | "are\$delineated\$by\$a\$single\$'dollar'\$character,\$write\$a\$program", 12 | "that\$aligns\$each\$column\$of\$fields\$by\$ensuring\$that\$words\$in\$each\$", 13 | "column\$are\$separated\$by\$at\$least\$one\$space.", 14 | "Further,\$allow\$for\$each\$word\$in\$a\$column\$to\$be\$either\$left\$", 15 | "justified,\$right\$justified,\$or\$center\$justified\$within\$its\$column."], 16 | Words = [ string:tokens(Line, "\$") || Line <- Lines ], 17 | Words_length = lists:foldl( fun max_length/2, [], Words), 18 | Result = [prepare_line(Words_line, Words_length, Alignment) || Words_line <- Words], 19 | %[ io:fwrite("~s~n", [lists:flatten(Line)]) || Line <- Result], 20 | %ok. 21 | Result. 22 | 23 | max_length(Words_of_a_line, Acc_maxlength) -> 24 | Line_lengths = [length(W) || W <- Words_of_a_line ], 25 | Max_nb_of_length = lists:max([length(Acc_maxlength), length(Line_lengths)]), 26 | Line_lengths_prepared = adjust_list (Line_lengths, Max_nb_of_length, 0), 27 | Acc_maxlength_prepared = adjust_list(Acc_maxlength, Max_nb_of_length, 0), 28 | Two_lengths =lists:zip(Line_lengths_prepared, Acc_maxlength_prepared), 29 | [ lists:max([A, B]) || {A, B} <- Two_lengths]. 30 | 31 | adjust_list(L, Desired_length, Elem) -> 32 | L++lists:duplicate(Desired_length - length(L), Elem). 33 | 34 | prepare_line(Words_line, Words_length, Alignment) -> 35 | All_words = adjust_list(Words_line, length(Words_length), ""), 36 | Zipped = lists:zip (All_words, Words_length), 37 | [ apply(string, Alignment, [Word, Length-1, $\s]) %WRONG 38 | %[ apply(string, Alignment, [Word, Length + 1, $\s]) %RIGHT 39 | || {Word, Length} <- Zipped]. 40 | -------------------------------------------------------------------------------- /examples/align_columns/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/align_columns/dbg.pdf -------------------------------------------------------------------------------- /examples/align_columns/dbg_zoom.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/align_columns/dbg_zoom.pdf -------------------------------------------------------------------------------- /examples/caesar/Readme: -------------------------------------------------------------------------------- 1 | Caesar cipher 2 | http://rosettacode.org/wiki/Caesar_cipher 3 | -------------------------------------------------------------------------------- /examples/caesar/caesar.erl: -------------------------------------------------------------------------------- 1 | %edd:dd("caesar:test()"). 2 | %% Caesar cypher in Erlang for the rosetta code wiki. 3 | %% Implemented by J.W. Luiten 4 | 5 | -module(caesar). 6 | -export([main/2,test/0]). 7 | 8 | %% rot: rotate Char by Key places 9 | rot(Char,Key) when (Char >= $A) and (Char =< $Z) or 10 | (Char >= $a) and (Char =< $z) -> 11 | Offset = $A + Char band 32, 12 | N = Char - Offset, 13 | %Offset + (N + Key) rem 26; %RIGHT 14 | Offset + (N - Key) rem 26; %WRONG 15 | rot(Char, _Key) -> 16 | Char. 17 | 18 | %% key: normalize key. 19 | key(Key) when Key < 0 -> 20 | 26 + Key rem 26; 21 | key(Key) when Key > 25 -> 22 | Key rem 26; 23 | key(Key) -> 24 | Key. 25 | 26 | main(PlainText, Key) -> 27 | Encode = key(Key), 28 | Decode = key(-Key), 29 | 30 | io:format("Plaintext ----> ~s~n", [PlainText]), 31 | 32 | CypherText = lists:map(fun(Char) -> rot(Char, Encode) end, PlainText), 33 | io:format("Cyphertext ---> ~s~n", [CypherText]), 34 | 35 | PlainText = lists:map(fun(Char) -> rot(Char, Decode) end, CypherText). 36 | 37 | test() -> 38 | main("The five boxing wizards jump quickly", 3). -------------------------------------------------------------------------------- /examples/caesar/caesar_ok.erl: -------------------------------------------------------------------------------- 1 | %edd:dd("caesar:test()"). 2 | %% Caesar cypher in Erlang for the rosetta code wiki. 3 | %% Implemented by J.W. Luiten 4 | 5 | -module(caesar_ok). 6 | -export([main/2,test/0, rot/2]). 7 | 8 | %% rot: rotate Char by Key places 9 | rot(Char,Key) when (Char >= $A) and (Char =< $Z) or 10 | (Char >= $a) and (Char =< $z) -> 11 | Offset = $A + Char band 32, 12 | N = Char - Offset, 13 | Offset + (N + Key) rem 26; %RIGHT 14 | rot(Char, _Key) -> 15 | Char. 16 | 17 | %% key: normalize key. 18 | key(Key) when Key < 0 -> 19 | 26 + Key rem 26; 20 | key(Key) when Key > 25 -> 21 | Key rem 26; 22 | key(Key) -> 23 | Key. 24 | 25 | main(PlainText, Key) -> 26 | Encode = key(Key), 27 | Decode = key(-Key), 28 | 29 | io:format("Plaintext ----> ~s~n", [PlainText]), 30 | 31 | CypherText = lists:map(fun(Char) -> rot(Char, Encode) end, PlainText), 32 | io:format("Cyphertext ---> ~s~n", [CypherText]), 33 | 34 | PlainText = lists:map(fun(Char) -> rot(Char, Decode) end, CypherText). 35 | 36 | test() -> 37 | main("The five boxing wizards jump quickly", 3). 38 | -------------------------------------------------------------------------------- /examples/caesar/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/caesar/dbg.pdf -------------------------------------------------------------------------------- /examples/caesar/dbg_zoom.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/caesar/dbg_zoom.pdf -------------------------------------------------------------------------------- /examples/complex_number/Readme: -------------------------------------------------------------------------------- 1 | Arithmetic/Complex 2 | http://rosettacode.org/wiki/Arithmetic/Complex 3 | -------------------------------------------------------------------------------- /examples/complex_number/complex_number.erl: -------------------------------------------------------------------------------- 1 | %edd:dd("complex_number:calculate()"). 2 | %% Task: Complex Arithmetic 3 | %% Author: Abhay Jain 4 | 5 | -module(complex_number). 6 | -export([calculate/0, inverse/1]). 7 | 8 | -record(complex, {real, img}). 9 | 10 | calculate() -> 11 | A = #complex{real=1, img=3}, 12 | B = #complex{real=5, img=2}, 13 | 14 | Sum = add (A, B), 15 | %print (Sum), 16 | 17 | Product = multiply (A, B), 18 | %print (Product), 19 | 20 | Negation = negation (A), 21 | %print (Negation), 22 | 23 | Inversion = inverse (A), 24 | %print (Inversion), 25 | 26 | Conjugate = conjugate (A), 27 | %print (Conjugate). 28 | 29 | {Sum, Product, Negation, Inversion, Conjugate}. 30 | 31 | add (A, B) -> 32 | RealPart = A#complex.real + B#complex.real, 33 | ImgPart = A#complex.img + B#complex.img, 34 | #complex{real=RealPart, img=ImgPart}. 35 | 36 | multiply (A, B) -> 37 | RealPart = (A#complex.real * B#complex.real) - (A#complex.img * B#complex.img), 38 | ImgPart = (A#complex.real * B#complex.img) + (B#complex.real * A#complex.img), 39 | #complex{real=RealPart, img=ImgPart}. 40 | 41 | negation (A) -> 42 | #complex{real=-A#complex.real, img=-A#complex.img}. 43 | 44 | inverse (A) -> 45 | C = conjugate (A), 46 | %Mod = (A#complex.real * A#complex.real) + (A#complex.img * A#complex.img), %RIGHT 47 | Mod = (A#complex.real * A#complex.img) + (A#complex.img * A#complex.img), %WRONG 48 | RealPart = C#complex.real / Mod, 49 | ImgPart = C#complex.img / Mod, 50 | #complex{real=RealPart, img=ImgPart}. 51 | 52 | conjugate (A) -> 53 | RealPart = A#complex.real, 54 | ImgPart = -A#complex.img, 55 | #complex{real=RealPart, img=ImgPart}. 56 | 57 | print (A) -> 58 | if A#complex.img < 0 -> 59 | io:format("Ans = ~p~pi~n", [A#complex.real, A#complex.img]); 60 | true -> 61 | io:format("Ans = ~p+~pi~n", [A#complex.real, A#complex.img]) 62 | end. 63 | -------------------------------------------------------------------------------- /examples/complex_number/complex_number_ok.erl: -------------------------------------------------------------------------------- 1 | %edd:dd("complex_number:calculate()"). 2 | %% Task: Complex Arithmetic 3 | %% Author: Abhay Jain 4 | 5 | -module(complex_number_ok). 6 | -compile([export_all]). 7 | 8 | -record(complex, {real, img}). 9 | 10 | calculate() -> 11 | A = #complex{real=1, img=3}, 12 | B = #complex{real=5, img=2}, 13 | 14 | Sum = add (A, B), 15 | %print (Sum), 16 | 17 | Product = multiply (A, B), 18 | %print (Product), 19 | 20 | Negation = negation (A), 21 | %print (Negation), 22 | 23 | Inversion = inverse (A), 24 | %print (Inversion), 25 | 26 | Conjugate = conjugate (A), 27 | %print (Conjugate). 28 | 29 | {Sum, Product, Negation, Inversion, Conjugate}. 30 | 31 | add (A, B) -> 32 | RealPart = A#complex.real + B#complex.real, 33 | ImgPart = A#complex.img + B#complex.img, 34 | #complex{real=RealPart, img=ImgPart}. 35 | 36 | multiply (A, B) -> 37 | RealPart = (A#complex.real * B#complex.real) - (A#complex.img * B#complex.img), 38 | ImgPart = (A#complex.real * B#complex.img) + (B#complex.real * A#complex.img), 39 | #complex{real=RealPart, img=ImgPart}. 40 | 41 | negation (A) -> 42 | #complex{real=-A#complex.real, img=-A#complex.img}. 43 | 44 | inverse (A) -> 45 | C = conjugate (A), 46 | Mod = (A#complex.real * A#complex.real) + (A#complex.img * A#complex.img), 47 | RealPart = C#complex.real / Mod, 48 | ImgPart = C#complex.img / Mod, 49 | #complex{real=RealPart, img=ImgPart}. 50 | 51 | conjugate (A) -> 52 | RealPart = A#complex.real, 53 | ImgPart = -A#complex.img, 54 | #complex{real=RealPart, img=ImgPart}. 55 | 56 | print (A) -> 57 | if A#complex.img < 0 -> 58 | io:format("Ans = ~p~pi~n", [A#complex.real, A#complex.img]); 59 | true -> 60 | io:format("Ans = ~p+~pi~n", [A#complex.real, A#complex.img]) 61 | end. 62 | -------------------------------------------------------------------------------- /examples/complex_number/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/complex_number/dbg.pdf -------------------------------------------------------------------------------- /examples/complex_number/dbg_zoom.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/complex_number/dbg_zoom.pdf -------------------------------------------------------------------------------- /examples/complex_number/session_zoom.txt: -------------------------------------------------------------------------------- 1 | TOP DOWN: 3 2 | =========== 3 | 4> edd_zoom:zoom_graph("complex_number:inverse({complex, 1, 3})"). 4 | Total number of tree nodes: 6 5 | Tree size: 6 | 1741 words 7 | 13928 bytes 8 | Given the context: 9 | C = {complex,1,-3} 10 | Mod = 12, 11 | the following variable is asigned: 12 | ImgPart = -0.25? [y/n/d/i/s/u/a]: y 13 | 14 | Complexity: 4 (data structures) + 3 (bindings) + 1 (base) = 8 15 | 16 | Given the context: 17 | C = {complex,1,-3} 18 | Mod = 12, 19 | the following variable is asigned: 20 | RealPart = 0.08333333333333333? [y/n/d/i/s/u/a]: y 21 | 22 | Complexity: 3 (data structures) + 3 (bindings) + 1 (base) = 7 23 | 24 | Given the context: 25 | A = {complex,1,3}, 26 | the following variable is asigned: 27 | Mod = 12? [y/n/d/i/s/u/a]: n 28 | 29 | Complexity: 4 (data structures) + 2 (bindings) + 1 (base) = 7 30 | Total complexity: 22 31 | Max complexity: 8 32 | 33 | This is the reason for the error: 34 | Variable Mod is badly assigned 12 in the expression: 35 | Mod = A#complex.real * A#complex.img + 36 | A#complex.img * A#complex.img (Line 47). 37 | ok 38 | 39 | 40 | DIVIDE & QUERY: 2 41 | ================= 42 | 5> edd_zoom:zoom_graph("complex_number:inverse({complex, 1, 3})"). 43 | Total number of tree nodes: 6 44 | Given the context: 45 | C = {complex,1,-3} 46 | Mod = 12, 47 | the following variable is asigned: 48 | ImgPart = -0.25? [y/n/d/i/s/u/a]: s 49 | Select a strategy (Didide & Query or Top Down): [d/t] d 50 | Given the context: 51 | A = {complex,1,3}, 52 | the following variable is asigned: 53 | C = {complex,1,-3}? [y/n/d/i/s/u/a]: y 54 | 55 | Complexity: 8 (data structures) + 2 (bindings) + 1 (base) = 11 56 | 57 | Given the context: 58 | A = {complex,1,3}, 59 | the following variable is asigned: 60 | Mod = 12? [y/n/d/i/s/u/a]: n 61 | 62 | Complexity: 4 (data structures) + 2 (bindings) + 1 (base) = 7 63 | Total complexity: 18 64 | Max complexity: 11 65 | 66 | This is the reason for the error: 67 | Variable Mod is badly assigned 12 in the expression: 68 | Mod = A#complex.real * A#complex.img + 69 | A#complex.img * A#complex.img (Line 47). 70 | ok 71 | 72 | 73 | -------------------------------------------------------------------------------- /examples/dns/Readme: -------------------------------------------------------------------------------- 1 | dns_erlang 2 | ========== 3 | Bug: https://github.com/aetrion/dns_erlang/commit/938d65b264b798170d8657e45fd7e0719f43a995 4 | Fix: https://github.com/aetrion/dns_erlang/commit/6a05f3c4d937c695acafdcf965acf541dbdd5e0c 5 | 6 | Involved files: 7 | 1710 dns.erl 8 | -------------------------------------------------------------------------------- /examples/dutch/Readme: -------------------------------------------------------------------------------- 1 | Dutch national flag problem 2 | http://rosettacode.org/wiki/Dutch_national_flag_proble 3 | -------------------------------------------------------------------------------- /examples/dutch/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/dutch/dbg.pdf -------------------------------------------------------------------------------- /examples/dutch/dutch.erl: -------------------------------------------------------------------------------- 1 | -module(dutch). 2 | -export([main/1, main/0]). 3 | 4 | ball(red) -> 1; 5 | ball(white) -> 2; 6 | ball(blue) -> 3. 7 | 8 | random_ball() -> lists:nth(random:uniform(3), [red, white, blue]). 9 | 10 | random_balls(N) -> random_balls(N,[]). 11 | random_balls(0,L) -> L; 12 | random_balls(N,L) when N > 0 -> 13 | B = random_ball(), 14 | random_balls(N-1, [B|L]). 15 | 16 | is_dutch([]) -> true; 17 | is_dutch([_]) -> true; 18 | is_dutch([B|[H|L]]) -> (ball(B) < ball(H)) and is_dutch([H|L]); 19 | is_dutch(_) -> false. 20 | 21 | dutch(L) -> dutch([],[],[],L). 22 | 23 | dutch(R, W, B, []) -> R ++ W ++ B; 24 | dutch(R, W, B, [red | L]) -> dutch([red|R], W, B, L); 25 | dutch(R, W, B, [white | L]) -> dutch(R, [white|W], B, L); 26 | %dutch(R, W, B, [blue | L]) -> dutch(R, W, [blue|B], L). %RIGHT 27 | dutch(R, W, B, [blue | L]) -> dutch(R, W, [white|B], L). %WRONG 28 | 29 | main(N) -> 30 | L = random_balls(N), 31 | case is_dutch(L) of 32 | true -> io:format("The random sequence ~p is already in the order of the Dutch flag!~n", [L]); 33 | false -> io:format("The starting random sequence is ~p;~nThe ordered sequence is ~p.~n", [L, dutch(L)]) 34 | end. 35 | 36 | main() -> 37 | L = [white,red,white,white,red,white,red,blue,red,red,white,white,blue,blue,white,red,white,blue,blue,white], 38 | case is_dutch(L) of 39 | true -> L; 40 | false -> OrderedL = dutch(L), 41 | OrderedL 42 | end. 43 | -------------------------------------------------------------------------------- /examples/dutch/dutch_ok.erl: -------------------------------------------------------------------------------- 1 | -module(dutch_ok). 2 | -compile([export_all]). 3 | 4 | ball(red) -> 1; 5 | ball(white) -> 2; 6 | ball(blue) -> 3. 7 | 8 | random_ball() -> lists:nth(random:uniform(3), [red, white, blue]). 9 | 10 | random_balls(N) -> random_balls(N,[]). 11 | random_balls(0,L) -> L; 12 | random_balls(N,L) when N > 0 -> 13 | B = random_ball(), 14 | random_balls(N-1, [B|L]). 15 | 16 | is_dutch([]) -> true; 17 | is_dutch([_]) -> true; 18 | is_dutch([B|[H|L]]) -> (ball(B) < ball(H)) and is_dutch([H|L]); 19 | is_dutch(_) -> false. 20 | 21 | dutch(L) -> dutch([],[],[],L). 22 | 23 | dutch(R, W, B, []) -> R ++ W ++ B; 24 | dutch(R, W, B, [red | L]) -> dutch([red|R], W, B, L); 25 | dutch(R, W, B, [white | L]) -> dutch(R, [white|W], B, L); 26 | dutch(R, W, B, [blue | L]) -> dutch(R, W, [blue|B], L). %RIGHT 27 | 28 | main() -> 29 | L = [white,red,white,white,red,white,red,blue,red,red,white,white,blue,blue,white,red,white,blue,blue,white], 30 | case is_dutch(L) of 31 | true -> L; 32 | false -> OrderedL = dutch(L), 33 | OrderedL 34 | end. 35 | -------------------------------------------------------------------------------- /examples/erlson_1/Readme: -------------------------------------------------------------------------------- 1 | Erlson - Erlang Simple Object Notation 2 | ====================================== 3 | Bug: https://github.com/ewanmellor/erlson/commit/cae2a1e987bf6c96b8bff8693d2c15d154198164 4 | Fix: https://github.com/ewanmellor/erlson/commit/d0927ac7963cc9807290487460c310ada68d2a3f 5 | 6 | Files involved: 7 | 376 erlson.erl 8 | 782 mochijson2.erl 9 | 1158 total 10 | 11 | -------------------------------------------------------------------------------- /examples/erlson_2/Readme: -------------------------------------------------------------------------------- 1 | Erlson - Erlang Simple Object Notation 2 | ====================================== 3 | Bug: https://github.com/ewanmellor/erlson/commit/cae2a1e987bf6c96b8bff8693d2c15d154198164 4 | Fix: https://github.com/ewanmellor/erlson/commit/11115054b9f379c91e2bb998533dc7abd806be3b 5 | 6 | Files involved: 7 | 377 erlson.erl 8 | 9 | -------------------------------------------------------------------------------- /examples/etorrent/Readme: -------------------------------------------------------------------------------- 1 | ETORRENT 2 | ======== 3 | Bug: https://github.com/edwardw/etorrent/commit/2e17a39126aec85211dbb49e7e32429997916a3b 4 | Fix: https://github.com/edwardw/etorrent/commit/d9d8cc13bab2eaa1ce282971901b7a29bf9bc942 5 | 6 | Files involved: 7 | 219 etorrent_bcoding.erl 8 | 886 etorrent_dht_net.erl 9 | 11 log.hrl 10 | 44 types.hrl 11 | 1160 total 12 | -------------------------------------------------------------------------------- /examples/io_lib_format/Readme: -------------------------------------------------------------------------------- 1 | io_lib_format (from OTP/Erlang) 2 | Real bug extracted from the commit that solved it. 3 | 4 | Bug: https://github.com/erlang/otp/commit/84adefa331c4159d432d22840663c38f155cd4c1 5 | Fix: https://github.com/erlang/otp/commit/a10a7979887403ea61c30155cef18aa7324420a6 6 | 7 | Files involved: 8 | 720 io_lib_format_old.erl 9 | 720 total 10 | 11 | Example of buggy call: 12 | lists:flatten(io_lib_format_old:fwrite("~6.7w\n",[11111])) 13 | 14 | Thanks to Anthony Ramine for provide it. 15 | -------------------------------------------------------------------------------- /examples/io_lib_format/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/io_lib_format/dbg.pdf -------------------------------------------------------------------------------- /examples/io_lib_format/dbg_zoom.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/io_lib_format/dbg_zoom.pdf -------------------------------------------------------------------------------- /examples/luerl_1/Readme: -------------------------------------------------------------------------------- 1 | Luerl - an implementation of Lua in Erlang 2 | ========================================== 3 | Bug: https://github.com/rvirding/luerl/commit/70a7efc8f2106a00f4d4c98dc9a7b3921bf7d3a9 4 | Fix: https://github.com/rvirding/luerl/commit/457111b45b143aaa4aeafbce0aa522a00384679e 5 | 6 | Files involved: 7 | 428 luerl_lib_basic.erl 8 | 774 ttdict.erl 9 | 133 luerl.hrl 10 | 1335 total 11 | -------------------------------------------------------------------------------- /examples/luerl_2/Readme: -------------------------------------------------------------------------------- 1 | Luerl - an implementation of Lua in Erlang 2 | ========================================== 3 | Bug: https://github.com/rvirding/luerl/commit/9d1004be293b64b409b1e809e7d40f6c923da148 4 | Fix: https://github.com/rvirding/luerl/commit/46e9269cf473308ef82a9db46f0f0ea2b8f89d95 5 | 6 | Files involved: 7 | 287 luerl_lib.erl 8 | 262 luerl_lib_math.erl 9 | 133 luerl.hrl 10 | 682 total 11 | -------------------------------------------------------------------------------- /examples/luerl_3/Readme: -------------------------------------------------------------------------------- 1 | Luerl - an implementation of Lua in Erlang 2 | ========================================== 3 | Bug: https://github.com/rvirding/luerl/commit/9d1004be293b64b409b1e809e7d40f6c923da148 4 | Fix: https://github.com/rvirding/luerl/commit/46e9269cf473308ef82a9db46f0f0ea2b8f89d95 5 | 6 | Files involved: 7 | 287 luerl_lib.erl 8 | 262 luerl_lib_math.erl 9 | 1198 luerl_scan.erl 10 | 133 luerl.hrl 11 | 1880 total 12 | -------------------------------------------------------------------------------- /examples/mergesort/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/mergesort/dbg.pdf -------------------------------------------------------------------------------- /examples/mergesort/dbg_zoom.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/mergesort/dbg_zoom.pdf -------------------------------------------------------------------------------- /examples/mergesort/merge.erl: -------------------------------------------------------------------------------- 1 | -module(merge). 2 | -export([mergesort/2, comp/2]). 3 | 4 | % Calls to the declarative debugger: 5 | % > edd:dd("merge:mergesort([b,a], fun merge:comp/2)"). 6 | % > edd:dd("merge:mergesort([o,h,i,o], fun merge:comp/2)"). 7 | 8 | mergesort([], _Comp) -> []; 9 | mergesort([X], _Comp) -> [X]; 10 | mergesort(L, Comp) -> 11 | Half = length(L) div 2, 12 | L1 = take(Half, L), 13 | L2 = last(length(L) - Half, L), 14 | LOrd1 = mergesort(L1, Comp), 15 | LOrd2 = mergesort(L2, Comp), 16 | merge(LOrd1, LOrd2, Comp). 17 | 18 | merge([], [], _Comp) -> 19 | []; 20 | merge([], S2, _Comp) -> 21 | S2; 22 | merge(S1, [], _Comp) -> 23 | S1; 24 | merge([H1 | T1], [H2 | T2], Comp) -> 25 | case Comp(H1,H2) of 26 | % false -> [H2 | merge([H1 | T1], T2, Comp)]; % Correct 27 | false -> [H1 | merge([H2 | T1], T2, Comp)]; % Incorrect 28 | true -> [H1 | merge(T1, [H2 | T2], Comp)] 29 | end. 30 | 31 | 32 | comp(X,Y) when is_atom(X) and is_atom(Y) -> X < Y. 33 | 34 | 35 | take(0,_) -> []; 36 | take(1,[H|_])->[H]; 37 | take(_,[])->[]; 38 | % take(N,[H|T])->[H | take(N-1, T)]. % Correct 39 | take(N,[_|T])->[N | take(N-1, T)]. % Incorrect 40 | 41 | last(N, List) -> 42 | lists:reverse(take(N, lists:reverse(List))). 43 | -------------------------------------------------------------------------------- /examples/mergesort/merge_ok.erl: -------------------------------------------------------------------------------- 1 | -module(merge_ok). 2 | -export([mergesort/2, comp/2]). 3 | 4 | % Calls to the declarative debugger: 5 | % > edd:dd("merge:mergesort([b,a], fun merge:comp/2)"). 6 | % > edd:dd("merge:mergesort([o,h,i,o], fun merge:comp/2)"). 7 | 8 | mergesort([], _Comp) -> []; 9 | mergesort([X], _Comp) -> [X]; 10 | mergesort(L, Comp) -> 11 | Half = length(L) div 2, 12 | L1 = take(Half, L), 13 | L2 = last(length(L) - Half, L), 14 | LOrd1 = mergesort(L1, Comp), 15 | LOrd2 = mergesort(L2, Comp), 16 | merge(LOrd1, LOrd2, Comp). 17 | 18 | merge([], [], _Comp) -> 19 | []; 20 | merge([], S2, _Comp) -> 21 | S2; 22 | merge(S1, [], _Comp) -> 23 | S1; 24 | merge([H1 | T1], [H2 | T2], Comp) -> 25 | case Comp(H1,H2) of 26 | false -> [H2 | merge([H1 | T1], T2, Comp)]; % Correct 27 | true -> [H1 | merge(T1, [H2 | T2], Comp)] 28 | end. 29 | 30 | 31 | comp(X,Y) when is_atom(X) and is_atom(Y) -> X < Y. 32 | 33 | 34 | take(0,_) -> []; 35 | take(1,[H|_])->[H]; 36 | take(_,[])->[]; 37 | take(N,[H|T])->[H | take(N-1, T)]. % Correct 38 | 39 | last(N, List) -> 40 | lists:reverse(take(N, lists:reverse(List))). 41 | -------------------------------------------------------------------------------- /examples/miller_rabin/Readme: -------------------------------------------------------------------------------- 1 | Miller-Rabin primality test 2 | http://rosettacode.org/wiki/Miller-Rabin_primality_test 3 | -------------------------------------------------------------------------------- /examples/miller_rabin/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/miller_rabin/dbg.pdf -------------------------------------------------------------------------------- /examples/miller_rabin/dbg_zoom.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/miller_rabin/dbg_zoom.pdf -------------------------------------------------------------------------------- /examples/miller_rabin/miller_rabin.erl: -------------------------------------------------------------------------------- 1 | -module(miller_rabin). 2 | 3 | -compile([export_all]). 4 | 5 | basis(N) when N>2 -> 6 | 1 + random:uniform(N-2). 7 | 8 | find_ds(D, S) -> 9 | case D rem 2 == 0 of 10 | true -> 11 | find_ds(trunc(D/2), S+1); 12 | false -> 13 | {D, S} 14 | end. 15 | 16 | find_ds(N) -> 17 | find_ds(N-1, 0). 18 | 19 | pow_mod(_B, 0, _M) -> 20 | 1; 21 | pow_mod(B, E, M) -> 22 | case trunc(E) rem 2 == 0 of 23 | true -> trunc(math:pow(pow_mod(B, trunc(E/2), M), 2)) rem M; 24 | false -> %trunc(B*pow_mod(B, E-1, M)) rem M % RIGHT 25 | trunc(pow_mod(B, E-1, M)) rem M % WRONG 26 | end. 27 | 28 | mr_series(N, A, D, S) when N rem 2 == 1 -> 29 | Js = lists:seq(0, S), 30 | lists:map(fun(J) -> pow_mod(A, math:pow(2, J)*D, N) end, Js). 31 | 32 | is_mr_prime(N, As) when N>2, N rem 2 == 1 -> 33 | {D, S} = find_ds(N), 34 | not lists:any(fun(A) -> 35 | case mr_series(N, A, D, S) of 36 | [1|_] -> false; 37 | L -> not lists:member(N-1, L) 38 | end 39 | end, 40 | As). 41 | 42 | proving_bases(N) when N < 1373653 -> 43 | [2, 3]; 44 | proving_bases(N) when N < 25326001 -> 45 | [2, 3, 5]; 46 | proving_bases(N) when N < 25000000000 -> 47 | [2, 3, 5, 7]; 48 | proving_bases(N) when N < 2152302898747-> 49 | [2, 3, 5, 7, 11]; 50 | proving_bases(N) when N < 341550071728321 -> 51 | [2, 3, 5, 7, 11, 13]; 52 | proving_bases(N) when N < 341550071728321 -> 53 | [2, 3, 5, 7, 11, 13, 17]. 54 | 55 | random_bases(N, K) -> 56 | [basis(N) || _ <- lists:seq(1, K)]. 57 | 58 | is_prime(1) -> false; 59 | is_prime(2) -> true; 60 | is_prime(N) when N rem 2 == 0 -> false; 61 | is_prime(N) when N < 341550071728321 -> 62 | is_mr_prime(N, proving_bases(N)). 63 | 64 | is_probable_prime(N) -> 65 | is_mr_prime(N, random_bases(N, 20)). 66 | 67 | first_10() -> 68 | lists:filter( fun is_prime/1, lists:seq(1,10) ). 69 | %first_10() -> 70 | % L = lists:seq(1,10), 71 | % lists:map(fun(X) -> 72 | % case is_prime(X) of 73 | % true -> 74 | % io:format("~w~n", [X]); 75 | % false -> 76 | % false 77 | % end 78 | % end, 79 | % L), 80 | % ok. 81 | -------------------------------------------------------------------------------- /examples/miller_rabin/miller_rabin_ok.erl: -------------------------------------------------------------------------------- 1 | -module(miller_rabin_ok). 2 | 3 | -compile([export_all]). 4 | 5 | basis(N) when N>2 -> 6 | 1 + random:uniform(N-2). 7 | 8 | find_ds(D, S) -> 9 | case D rem 2 == 0 of 10 | true -> 11 | find_ds(trunc(D/2), S+1); 12 | false -> 13 | {D, S} 14 | end. 15 | 16 | find_ds(N) -> 17 | find_ds(N-1, 0). 18 | 19 | pow_mod(_B, 0, _M) -> 20 | 1; 21 | pow_mod(B, E, M) -> 22 | case trunc(E) rem 2 == 0 of 23 | true -> trunc(math:pow(pow_mod(B, trunc(E/2), M), 2)) rem M; 24 | false -> trunc(B*pow_mod(B, E-1, M)) rem M % RIGHT 25 | end. 26 | 27 | mr_series(N, A, D, S) when N rem 2 == 1 -> 28 | Js = lists:seq(0, S), 29 | lists:map(fun(J) -> pow_mod(A, math:pow(2, J)*D, N) end, Js). 30 | 31 | is_mr_prime(N, As) when N>2, N rem 2 == 1 -> 32 | {D, S} = find_ds(N), 33 | not lists:any(fun(A) -> 34 | case mr_series(N, A, D, S) of 35 | [1|_] -> false; 36 | L -> not lists:member(N-1, L) 37 | end 38 | end, 39 | As). 40 | 41 | proving_bases(N) when N < 1373653 -> 42 | [2, 3]; 43 | proving_bases(N) when N < 25326001 -> 44 | [2, 3, 5]; 45 | proving_bases(N) when N < 25000000000 -> 46 | [2, 3, 5, 7]; 47 | proving_bases(N) when N < 2152302898747-> 48 | [2, 3, 5, 7, 11]; 49 | proving_bases(N) when N < 341550071728321 -> 50 | [2, 3, 5, 7, 11, 13]; 51 | proving_bases(N) when N < 341550071728321 -> 52 | [2, 3, 5, 7, 11, 13, 17]. 53 | 54 | random_bases(N, K) -> 55 | [basis(N) || _ <- lists:seq(1, K)]. 56 | 57 | is_prime(1) -> false; 58 | is_prime(2) -> true; 59 | is_prime(N) when N rem 2 == 0 -> false; 60 | is_prime(N) when N < 341550071728321 -> 61 | is_mr_prime(N, proving_bases(N)). 62 | 63 | is_probable_prime(N) -> 64 | is_mr_prime(N, random_bases(N, 20)). 65 | 66 | first_10() -> 67 | lists:filter( fun is_prime/1, lists:seq(1,10) ). 68 | %first_10() -> 69 | % L = lists:seq(1,10), 70 | % lists:map(fun(X) -> 71 | % case is_prime(X) of 72 | % true -> 73 | % io:format("~w~n", [X]); 74 | % false -> 75 | % false 76 | % end 77 | % end, 78 | % L), 79 | % ok. 80 | -------------------------------------------------------------------------------- /examples/queue/Readme: -------------------------------------------------------------------------------- 1 | queue (from OTP/Erlang) 2 | ======================= 3 | Bug: https://github.com/erlang/otp/commit/1cbd897c43f0dab1275392a3736e4629c1f80243 4 | Fix: https://github.com/erlang/otp/commit/f4916887e09a2bc9b0301ce0751e2e5b057cb592 5 | 6 | Files involved: 7 | 487 queue.erl 8 | -------------------------------------------------------------------------------- /examples/queue/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/queue/dbg.pdf -------------------------------------------------------------------------------- /examples/queue/dbg_zoom.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/queue/dbg_zoom.pdf -------------------------------------------------------------------------------- /examples/quicksort/Readme: -------------------------------------------------------------------------------- 1 | Quicksort algorithm 2 | 3 | Enrique Martin-Martin (emartinm@ucm.es) 4 | -------------------------------------------------------------------------------- /examples/quicksort/bug1_tree.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/quicksort/bug1_tree.pdf -------------------------------------------------------------------------------- /examples/quicksort/bug2_tree.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/quicksort/bug2_tree.pdf -------------------------------------------------------------------------------- /examples/quicksort/dbg.dot: -------------------------------------------------------------------------------- 1 | digraph PDG { 2 | 8 [shape=ellipse, label="8 .- quicksort:qs(fun quicksort:leq/2, [1]) = [1]"]; 3 | 1 [shape=ellipse, label="1 .- quicksort:leq(1, 7) = true"]; 4 | 7 [shape=ellipse, label="7 .- quicksort:qs(fun quicksort:leq/2, []) = []"]; 5 | 3 [shape=ellipse, label="3 .- quicksort:leq(8, 7) = false"]; 6 | 10 [shape=ellipse, label="10 .- quicksort:qs(fun quicksort:leq/2, [7, 8, 1]) = [1, 7]"]; 7 | 9 [shape=ellipse, label="9 .- quicksort:qs(fun quicksort:leq/2, []) = []"]; 8 | 4 [shape=ellipse, label="4 .- quicksort:partition(fun quicksort:leq/2, 7, [8, 1]) = {[1], []}"]; 9 | 0 [shape=ellipse, label="0 .- quicksort:partition(fun quicksort:leq/2, 7, []) = {[], []}"]; 10 | 6 [shape=ellipse, label="6 .- quicksort:qs(fun quicksort:leq/2, []) = []"]; 11 | 2 [shape=ellipse, label="2 .- quicksort:partition(fun quicksort:leq/2, 7, [1]) = {[1], []}"]; 12 | 5 [shape=ellipse, label="5 .- quicksort:partition(fun quicksort:leq/2, 1, []) = {[], []}"]; 13 | 8 -> 7 [color=black, penwidth=3]; 14 | 8 -> 6 [color=black, penwidth=3]; 15 | 8 -> 5 [color=black, penwidth=3]; 16 | 10 -> 9 [color=black, penwidth=3]; 17 | 10 -> 8 [color=black, penwidth=3]; 18 | 10 -> 4 [color=black, penwidth=3]; 19 | 4 -> 3 [color=black, penwidth=3]; 20 | 4 -> 2 [color=black, penwidth=3]; 21 | 2 -> 1 [color=black, penwidth=3]; 22 | 2 -> 0 [color=black, penwidth=3]; 23 | } -------------------------------------------------------------------------------- /examples/quicksort/quicksort.erl: -------------------------------------------------------------------------------- 1 | -module(quicksort). 2 | -include_lib("eunit/include/eunit.hrl"). 3 | -export([qs/2, leq/2]). 4 | 5 | 6 | qs(_, []) -> []; 7 | qs(F, [E|R]) -> 8 | {A, B} = partition(F,E,R), 9 | %%%% Bug 1 %%%% 10 | qs(F,B) ++ [E] ++ qs(F,A). % Bug 11 | % qs(F,A) ++ [E] ++ qs(F,B). % OK 12 | %%%%%%%%%%%%%%% 13 | 14 | 15 | partition(_, _, []) -> {[],[]}; 16 | partition(F, E, [H|T]) -> 17 | {A,B} = partition( F, E, T ), 18 | case F(H,E) of 19 | true -> {[H|A],B}; 20 | %%%% BUG 2 %%%% 21 | % false -> {A, [H|B]} % OK 22 | false -> {A,B} % Bug 23 | %%%%%%%%%%%%%%% 24 | end. 25 | 26 | 27 | leq( A, B ) -> 28 | A =< B. 29 | 30 | 31 | quicksort_test() -> 32 | ?assert( [] == qs( fun leq/2, [] ) ), 33 | ?assert( [1] == qs( fun leq/2, [1] ) ), 34 | ?assert( [1,7] == qs( fun leq/2, [7,1] ) ), 35 | ?assert( [1,7,8] == qs( fun leq/2, [7,8,1] ) ). 36 | -------------------------------------------------------------------------------- /examples/random/Readme: -------------------------------------------------------------------------------- 1 | random (from OTP/Erlang) 2 | ======================== 3 | Bug: https://github.com/erlang/otp/commit/9f78db422a8facfaad909a656ffabeb27f8fe2fd 4 | Fix: https://github.com/erlang/otp/commit/c50f179a15ad8c8bcbc7a71101a9ca23f19f6e8f 5 | 6 | Files involved: 7 | 115 random.erl 8 | -------------------------------------------------------------------------------- /examples/redbug_msc/Readme: -------------------------------------------------------------------------------- 1 | eper: loose collection of Erlang Performance related tools 2 | ========================================================== 3 | Bug: https://github.com/massemanet/eper/commit/38c1f00143aaedac5db0d234452640d432754a33 4 | Fix: https://github.com/massemanet/eper/commit/a5629fe60b2cdae1573b399aaae3cfef1e1b65a6 5 | 6 | Files involved: 7 | 368 redbug_msc.erl 8 | -------------------------------------------------------------------------------- /examples/rfib/Readme: -------------------------------------------------------------------------------- 1 | Adaptation from the faulty nofib library for Haskell 2 | -------------------------------------------------------------------------------- /examples/rfib/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/rfib/dbg.pdf -------------------------------------------------------------------------------- /examples/rfib/rfib_ok.erl: -------------------------------------------------------------------------------- 1 | %edd:dd("rfib:main(10)"). 2 | -module(rfib_ok). 3 | -compile([export_all]). 4 | 5 | %--------------------------------------------------------- 6 | %-- WARNING: THIS PROGRAM CONTAINS A BUG!!! -- 7 | %-- -- 8 | %-- This program belongs to the faulty nofib library -- 9 | %-- and contains a bug to benchmark debuggers -- 10 | %-- -- 11 | %--------------------------------------------------------- 12 | %-- -- 13 | %-- "The faulty nofib library" is a collection of -- 14 | %-- Haskell programs from the 'nofib' benchmark suite -- 15 | %-- -- 16 | %-- Faults are always marked with a comment: "BUG" -- 17 | %-- The commented correct line appears after the -- 18 | %-- faulty line marked with "CORRECT" -- 19 | %-- -- 20 | %-- We welcome any comment or improvement about -- 21 | %-- bugs. You can send them to: -- 22 | %-- Josep Silva (jsilva@dsic.upv.es) -- 23 | %-- -- 24 | %--------------------------------------------------------- 25 | %-- -- 26 | %-- There are three kinds of bugs depending on their -- 27 | %-- consequences: -- 28 | %-- 1) Bugs that produce an incorrect result -- 29 | %-- 2) Bugs that produce non-termination -- 30 | %-- 3) Bugs that produce an exception (e.g. div by 0) -- 31 | %-- -- 32 | %-- This program contains a bug of tipe 1 -- 33 | %--------------------------------------------------------- 34 | % 35 | %-- !!! the ultra-notorious "nfib 30" does w/ Floats 36 | %-- 37 | %module Main (main) where 38 | %import System 39 | % 40 | %main = do 41 | % [arg] <- getArgs 42 | % print $ nfib $ read arg 43 | % 44 | 45 | main(N) -> 46 | nfib(N). 47 | 48 | %nfib :: Double -> Double 49 | %-- BUG: The following line contains a bug: 50 | %nfib n = if n < 1 then 1 else nfib (n-1) + nfib (n-2) 51 | %-- CORRECT -- nfib n = if n <= 1 then 1 else nfib (n-1) + nfib (n-2) 52 | % 53 | 54 | nfib(N) when N =< 1 -> 1; %RIGHT 55 | nfib(N) when N >= 1 -> nfib(N-1) + nfib(N-2). 56 | -------------------------------------------------------------------------------- /examples/rle/Readme: -------------------------------------------------------------------------------- 1 | Run-length encoding 2 | http://rosettacode.org/wiki/Run-length_encoding 3 | -------------------------------------------------------------------------------- /examples/rle/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/rle/dbg.pdf -------------------------------------------------------------------------------- /examples/rle/dbg_zoom.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/rle/dbg_zoom.pdf -------------------------------------------------------------------------------- /examples/rle/rle.erl: -------------------------------------------------------------------------------- 1 | -module(rle). 2 | -compile([export_all]). 3 | 4 | 5 | encode(S) -> 6 | doEncode(string:substr(S, 2), string:substr(S, 1, 1), 1, []). 7 | 8 | doEncode([], CurrChar, Count, R) -> 9 | R ++ integer_to_list(Count) ++ CurrChar; 10 | doEncode(S, CurrChar, Count, R) -> 11 | NextChar = string:substr(S, 1, 1), 12 | if 13 | NextChar == CurrChar -> 14 | %doEncode(string:substr(S, 2), CurrChar, Count + 1, R); % RIGHT 15 | doEncode(string:substr(S, 3), CurrChar, Count + 1, R); % WRONG 16 | true -> 17 | doEncode(string:substr(S, 2), NextChar, 1, 18 | R ++ integer_to_list(Count) ++ CurrChar) 19 | end. 20 | 21 | decode(S) -> 22 | doDecode(string:substr(S, 2), string:substr(S, 1, 1), []). 23 | 24 | doDecode([], _, R) -> 25 | R; 26 | doDecode(S, CurrString, R) -> 27 | NextChar = string:substr(S, 1, 1), 28 | IsInt = erlang:is_integer(catch(erlang:list_to_integer(NextChar))), 29 | if 30 | IsInt -> 31 | doDecode(string:substr(S, 2), CurrString ++ NextChar, R); 32 | true -> 33 | doDecode(string:substr(S, 2), [], 34 | R ++ string:copies(NextChar, list_to_integer(CurrString))) 35 | end. 36 | 37 | test() -> 38 | PreEncoded = 39 | "WWWWWWWBWWWWWBBBWWWWWWWBWWWWW", 40 | Expected = "7W1B5W3B7W1B5W", 41 | (encode(PreEncoded) =:= Expected) 42 | and (decode(Expected) =:= PreEncoded) 43 | and(decode(encode(PreEncoded)) =:= PreEncoded). 44 | %encode(PreEncoded). 45 | -------------------------------------------------------------------------------- /examples/rle/rle_ok.erl: -------------------------------------------------------------------------------- 1 | -module(rle_ok). 2 | -compile([export_all]). 3 | 4 | 5 | encode(S) -> 6 | doEncode(string:substr(S, 2), string:substr(S, 1, 1), 1, []). 7 | 8 | doEncode([], CurrChar, Count, R) -> 9 | R ++ integer_to_list(Count) ++ CurrChar; 10 | doEncode(S, CurrChar, Count, R) -> 11 | NextChar = string:substr(S, 1, 1), 12 | if 13 | NextChar == CurrChar -> 14 | doEncode(string:substr(S, 2), CurrChar, Count + 1, R); % RIGHT 15 | %doEncode(string:substr(S, 3), CurrChar, Count + 1, R); % WRONG 16 | true -> 17 | doEncode(string:substr(S, 2), NextChar, 1, 18 | R ++ integer_to_list(Count) ++ CurrChar) 19 | end. 20 | 21 | decode(S) -> 22 | doDecode(string:substr(S, 2), string:substr(S, 1, 1), []). 23 | 24 | doDecode([], _, R) -> 25 | R; 26 | doDecode(S, CurrString, R) -> 27 | NextChar = string:substr(S, 1, 1), 28 | IsInt = erlang:is_integer(catch(erlang:list_to_integer(NextChar))), 29 | if 30 | IsInt -> 31 | doDecode(string:substr(S, 2), CurrString ++ NextChar, R); 32 | true -> 33 | doDecode(string:substr(S, 2), [], 34 | R ++ string:copies(NextChar, list_to_integer(CurrString))) 35 | end. 36 | 37 | test() -> 38 | PreEncoded = 39 | "WWWWWWWBWWWWWBBBWWWWWWWBWWWWW", 40 | Expected = "7W1B5W3B7W1B5W", 41 | (encode(PreEncoded) =:= Expected) 42 | and (decode(Expected) =:= PreEncoded) 43 | and(decode(encode(PreEncoded)) =:= PreEncoded). 44 | %encode(PreEncoded). 45 | -------------------------------------------------------------------------------- /examples/roman/Readme: -------------------------------------------------------------------------------- 1 | Roman numerals/Encode 2 | http://rosettacode.org/wiki/Roman_numerals/Encode 3 | -------------------------------------------------------------------------------- /examples/roman/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/roman/dbg.pdf -------------------------------------------------------------------------------- /examples/roman/dbg_zoom.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/roman/dbg_zoom.pdf -------------------------------------------------------------------------------- /examples/roman/roman.erl: -------------------------------------------------------------------------------- 1 | -module(roman). 2 | -export([main/0]). 3 | 4 | to_roman(0) -> []; 5 | to_roman(X) when X >= 1000 -> [$M | to_roman(X - 1000)]; 6 | to_roman(X) when X >= 100 -> 7 | digit(X div 100, $C, $D, $M) ++ to_roman(X rem 100); 8 | to_roman(X) when X >= 10 -> 9 | digit(X div 10, $X, $L, $C) ++ to_roman(X rem 10); 10 | to_roman(X) when X >= 1 -> digit(X, $I, $V, $X). 11 | 12 | digit(1, X, _, _) -> [X]; 13 | digit(2, X, _, _) -> [X, X]; 14 | digit(3, X, _, _) -> [X, X, X]; 15 | digit(4, X, Y, _) -> [X, Y]; 16 | digit(5, _, Y, _) -> [Y]; 17 | digit(6, X, Y, _) -> [Y, X]; 18 | digit(7, X, Y, _) -> [Y, X, X]; 19 | %digit(8, X, Y, _) -> [Y, X, X, X]; %RIGHT 20 | digit(8, X, Y, _) -> [Y, Y, X, X]; %WRONG 21 | digit(9, X, _, Z) -> [X, Z]. 22 | 23 | main() -> 24 | to_roman(2489). -------------------------------------------------------------------------------- /examples/roman/roman_ok.erl: -------------------------------------------------------------------------------- 1 | -module(roman_ok). 2 | -compile([export_all]). 3 | 4 | to_roman(0) -> []; 5 | to_roman(X) when X >= 1000 -> [$M | to_roman(X - 1000)]; 6 | to_roman(X) when X >= 100 -> 7 | digit(X div 100, $C, $D, $M) ++ to_roman(X rem 100); 8 | to_roman(X) when X >= 10 -> 9 | digit(X div 10, $X, $L, $C) ++ to_roman(X rem 10); 10 | to_roman(X) when X >= 1 -> digit(X, $I, $V, $X). 11 | 12 | digit(1, X, _, _) -> [X]; 13 | digit(2, X, _, _) -> [X, X]; 14 | digit(3, X, _, _) -> [X, X, X]; 15 | digit(4, X, Y, _) -> [X, Y]; 16 | digit(5, _, Y, _) -> [Y]; 17 | digit(6, X, Y, _) -> [Y, X]; 18 | digit(7, X, Y, _) -> [Y, X, X]; 19 | digit(8, X, Y, _) -> [Y, X, X, X]; 20 | digit(9, X, _, Z) -> [X, Z]. 21 | 22 | main() -> 23 | to_roman(2489). 24 | -------------------------------------------------------------------------------- /examples/roman/session.txt: -------------------------------------------------------------------------------- 1 | > edd:dd("roman:main()"). 2 | Tree size: 3 | 2145 words 4 | 17160 bytes 5 | 6 | Please, insert a list of trusted functions [m1:f1/a1, m2:f2/a2 ...]: 7 | roman:to_roman(89) = "LLXXIX"? [y/n/t/d/i/s/u/a]: n 8 | roman:to_roman(9) = "IX"? [y/n/t/d/i/s/u/a]: y 9 | roman:digit(8, 88, 76, 67) = "LLXX"? [y/n/t/d/i/s/u/a]: n 10 | Call to a function that contains an error: 11 | roman:digit(8, 88, 76, 67) = "LLXX" 12 | Please, revise the 8th clause: 13 | digit(8, X, Y, _) -> [Y, Y, X, X]. 14 | 15 | 16 | 17 | 18 | 19 | 20 | DIVIDE & QUERY: 3 21 | ========================== 22 | 4> edd:dd("roman:main()", tree). 23 | Please, insert a list of trusted functions [m1:f1/a1, m2:f2/a2 ...]: 24 | roman:to_roman(89) = "LLXXIX"? [y/n/t/d/i/s/u/a]: n 25 | 26 | Complexity: 1 (base) 27 | 28 | roman:to_roman(9) = "IX"? [y/n/t/d/i/s/u/a]: y 29 | 30 | Complexity: 1 (base) 31 | 32 | roman:digit(8, 88, 76, 67) = "LLXX"? [y/n/t/d/i/s/u/a]: n 33 | 34 | Complexity: 1 (base) 35 | Total complexity: 3 36 | Max complexity: 1 37 | 38 | 39 | Call to a function that contains an error: 40 | roman:digit(8, 88, 76, 67) = "LLXX" 41 | Please, revise the 8th clause: 42 | digit(8, X, Y, _) -> [Y, Y, X, X]. 43 | ok 44 | 45 | 46 | TOP-DOWN: 6 47 | ============================================ 48 | 5> edd:dd("roman:main()", tree, top_down). 49 | Please, insert a list of trusted functions [m1:f1/a1, m2:f2/a2 ...]: 50 | roman:to_roman(2489) = "MMCDLLXXIX"? [y/n/t/d/i/s/u/a]: n 51 | 52 | Complexity: 1 (base) 53 | 54 | roman:to_roman(1489) = "MCDLLXXIX"? [y/n/t/d/i/s/u/a]: n 55 | 56 | Complexity: 1 (base) 57 | 58 | roman:to_roman(489) = "CDLLXXIX"? [y/n/t/d/i/s/u/a]: n 59 | 60 | Complexity: 1 (base) 61 | 62 | roman:to_roman(89) = "LLXXIX"? [y/n/t/d/i/s/u/a]: n 63 | 64 | Complexity: 1 (base) 65 | 66 | roman:to_roman(9) = "IX"? [y/n/t/d/i/s/u/a]: y 67 | 68 | Complexity: 1 (base) 69 | 70 | roman:digit(8, 88, 76, 67) = "LLXX"? [y/n/t/d/i/s/u/a]: n 71 | 72 | Complexity: 1 (base) 73 | Total complexity: 6 74 | Max complexity: 1 75 | 76 | Call to a function that contains an error: 77 | roman:digit(8, 88, 76, 67) = "LLXX" 78 | Please, revise the 8th clause: 79 | digit(8, X, Y, _) -> [Y, Y, X, X]. 80 | ok 81 | 82 | -------------------------------------------------------------------------------- /examples/sieve_module/Readme: -------------------------------------------------------------------------------- 1 | Sieve of Eratosthenes 2 | http://rosettacode.org/wiki/Sieve_of_Eratosthenes 3 | -------------------------------------------------------------------------------- /examples/sieve_module/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/sieve_module/dbg.pdf -------------------------------------------------------------------------------- /examples/sieve_module/dbg_zoom.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/sieve_module/dbg_zoom.pdf -------------------------------------------------------------------------------- /examples/sieve_module/sieve_module.erl: -------------------------------------------------------------------------------- 1 | %% Author: Abhay Jain 2 | 3 | -module(sieve_module). 4 | -export([find_primes_below/1]). 5 | 6 | 7 | find_primes_below(N) -> 8 | NumList = lists:seq(1, N), 9 | determine_primes(NumList, 1, []). 10 | 11 | %% Sieve of Eratosthenes algorithm 12 | determine_primes(NumList, Index, Primes) -> 13 | case next_prime(NumList, Index+1, length(NumList)) of 14 | {Prime, PrimeIndex, NewNumList} -> 15 | NewPrimes = lists:append(Primes, [Prime]), 16 | determine_primes(NewNumList, PrimeIndex, NewPrimes); 17 | _ -> 18 | %% All prime numbers have been calculated 19 | Primes 20 | end. 21 | 22 | next_prime(_, Index, Length) when Index > Length -> 23 | false; 24 | next_prime(NumList, Index, Length) -> 25 | case lists:nth(Index, NumList) of 26 | 0 -> 27 | %next_prime(NumList, Index+1, Length); %RIGHT 28 | next_prime(NumList, Index+2, Length); %WRONG 29 | Prime -> 30 | NewNumList = lists:map(fun(A) -> 31 | if A > Index andalso A rem Index == 0 -> 0; 32 | true -> A 33 | end 34 | end, NumList), 35 | {Prime, Index, NewNumList} 36 | end. 37 | -------------------------------------------------------------------------------- /examples/sieve_module/sieve_module_ok.erl: -------------------------------------------------------------------------------- 1 | %% Task: Implementation of Sieve of Eratosthenes 2 | %% Author: Abhay Jain 3 | -module(sieve_module_ok). 4 | -compile([export_all]). 5 | 6 | 7 | find_primes_below(N) -> 8 | NumList = lists:seq(1, N), 9 | determine_primes(NumList, 1, []). 10 | 11 | 12 | %% Sieve of Eratosthenes algorithm 13 | determine_primes(NumList, Index, Primes) -> 14 | case next_prime(NumList, Index+1, length(NumList)) of 15 | {Prime, PrimeIndex, NewNumList} -> 16 | NewPrimes = lists:append(Primes, [Prime]), 17 | determine_primes(NewNumList, PrimeIndex, NewPrimes); 18 | _ -> 19 | %% All prime numbers have been calculated 20 | Primes 21 | end. 22 | 23 | 24 | next_prime(_, Index, Length) when Index > Length -> 25 | false; 26 | next_prime(NumList, Index, Length) -> 27 | case lists:nth(Index, NumList) of 28 | 0 -> 29 | next_prime(NumList, Index+1, Length); 30 | Prime -> 31 | NewNumList = lists:map(fun(A) -> 32 | if A > Index andalso A rem Index == 0 -> 0; 33 | true -> A 34 | end 35 | end, NumList), 36 | {Prime, Index, NewNumList} 37 | end. 38 | -------------------------------------------------------------------------------- /examples/stock/Readme: -------------------------------------------------------------------------------- 1 | Stock Management 2 | Enrique Martin-Martin (emartinm@fdi.ucm.es) 3 | -------------------------------------------------------------------------------- /examples/stock/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/stock/dbg.pdf -------------------------------------------------------------------------------- /examples/stock/dbg_zoom.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/stock/dbg_zoom.pdf -------------------------------------------------------------------------------- /examples/stock/stock.erl: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%% 2 | % Enrique Martin-Martin % 3 | % emartinm@fdi.ucm.es % 4 | %%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | % Stock Management 7 | % 8 | % The representation of the items in the stock are tuples 9 | % {iten, Item_Name, Quantity} 10 | % The stock is represented as a list of items without repetitions of the same item 11 | % Orders are also represented as lists of items 12 | 13 | -module(stock). 14 | -compile([export_all]). 15 | 16 | % It should return that we need to buy 2 packs of rice and 3 bottles of water 17 | % (i.e., [{item, rice, 2},{item,water,3}]), however it incorrectly returns 18 | % [{item,water,3},{item,rice,7}] 19 | test() -> 20 | check_orders( [[{item, water, 3},{item, rice, 3}],[{item, rice, 4}]], 21 | [{item, rice, 5}, {item, bajoqueta, 8}]). 22 | 23 | 24 | % Given one Order and a Stock, returns the list of items we have to buy to 25 | % answer the order 26 | % If we have enough items in the stock, returns [] 27 | check_order( Order, Stock ) -> 28 | lists:zf( fun(X) -> check_item(X,Stock) end, Order ). 29 | 30 | 31 | % Function to use with lists:zf/2 to map and filter that checks the state of an 32 | % item in the stock 33 | % If there are enough items in the stock, returns false 34 | % If there aren't enough items in the stock (or there are no items of that kind 35 | % at all) returns {true, Item}, where item contains the quantity needed 36 | check_item( Needed = {item, Name, Q1}, Stock ) -> 37 | %ItemStock = lists:keyfind(Name, 2, Stock), %RIGHT 38 | ItemStock = lists:keyfind(Name, 1, Stock), %WRONG 39 | case ItemStock of 40 | {item, Name, Q2} -> 41 | if Q1 > Q2 -> {true, {item, Name, Q1 - Q2}}; 42 | true -> false 43 | end; 44 | false -> {true, Needed} 45 | end. 46 | 47 | 48 | % Similar to check_order/2 but considering a list of orders 49 | check_orders( List_of_orders, Stock ) -> 50 | Flat_orders = lists:flatten( List_of_orders ), 51 | Unique_orders = unify_orders( Flat_orders ), 52 | check_order( Unique_orders, Stock ). 53 | 54 | 55 | % Unify a list of orders in one order, adding the needed quantities 56 | unify_orders( [] ) -> []; 57 | unify_orders( [{item,Name,Quantity}|R] ) -> 58 | {Item_orders, Other_orders} = lists:partition( fun({item, ItemName, _}) -> ItemName == Name end, R ), 59 | Total_quantity = lists:foldr( fun({item,_,N}, Acc) -> N + Acc end, 0, Item_orders), 60 | Unif_rest = unify_orders( Other_orders ), 61 | [ {item, Name, Total_quantity + Quantity} | Unif_rest ]. 62 | -------------------------------------------------------------------------------- /examples/stock/stock_ok.erl: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%% 2 | % Enrique Martin-Martin % 3 | % emartinm@fdi.ucm.es % 4 | %%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | % Stock Management 7 | % 8 | % The representation of the items in the stock are tuples 9 | % {iten, Item_Name, Quantity} 10 | % The stock is represented as a list of items without repetitions of the same item 11 | % Orders are also represented as lists of items 12 | 13 | -module(stock_ok). 14 | -compile([export_all]). 15 | 16 | % It should return that we need to buy 2 packs of rice and 3 bottles of water 17 | % (i.e., [{item, rice, 2},{item,water,3}]), however it incorrectly returns 18 | % [{item,water,3},{item,rice,7}] 19 | test() -> 20 | check_orders( [[{item, water, 3},{item, rice, 3}],[{item, rice, 4}]], 21 | [{item, rice, 5}, {item, bajoqueta, 8}]). 22 | 23 | 24 | % Given one Order and a Stock, returns the list of items we have to buy to 25 | % answer the order 26 | % If we have enough items in the stock, returns [] 27 | check_order( Order, Stock ) -> 28 | lists:zf( fun(X) -> check_item(X,Stock) end, Order ). 29 | 30 | 31 | % Function to use with lists:zf/2 to map and filter that checks the state of an 32 | % item in the stock 33 | % If there are enough items in the stock, returns false 34 | % If there aren't enough items in the stock (or there are no items of that kind 35 | % at all) returns {true, Item}, where item contains the quantity needed 36 | check_item( Needed = {item, Name, Q1}, Stock ) -> 37 | ItemStock = lists:keyfind(Name, 2, Stock), %RIGHT 38 | case ItemStock of 39 | {item, Name, Q2} -> 40 | if Q1 > Q2 -> {true, {item, Name, Q1 - Q2}}; 41 | true -> false 42 | end; 43 | false -> {true, Needed} 44 | end. 45 | 46 | 47 | % Similar to check_order/2 but considering a list of orders 48 | check_orders( List_of_orders, Stock ) -> 49 | Flat_orders = lists:flatten( List_of_orders ), 50 | Unique_orders = unify_orders( Flat_orders ), 51 | check_order( Unique_orders, Stock ). 52 | 53 | 54 | % Unify a list of orders in one order, adding the needed quantities 55 | unify_orders( [] ) -> []; 56 | unify_orders( [{item,Name,Quantity}|R] ) -> 57 | {Item_orders, Other_orders} = lists:partition( fun({item, ItemName, _}) -> ItemName == Name end, R ), 58 | Total_quantity = lists:foldr( fun({item,_,N}, Acc) -> N + Acc end, 0, Item_orders), 59 | Unif_rest = unify_orders( Other_orders ), 60 | [ {item, Name, Total_quantity + Quantity} | Unif_rest ]. 61 | -------------------------------------------------------------------------------- /examples/sum_digits/Readme: -------------------------------------------------------------------------------- 1 | Sum digits of an integer 2 | http://rosettacode.org/wiki/Sum_digits_of_an_integer 3 | -------------------------------------------------------------------------------- /examples/sum_digits/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/sum_digits/dbg.pdf -------------------------------------------------------------------------------- /examples/sum_digits/dbg_zoom.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/sum_digits/dbg_zoom.pdf -------------------------------------------------------------------------------- /examples/sum_digits/session.txt: -------------------------------------------------------------------------------- 1 | > edd:dd("sum_digits:sum_digits(13456)"). 2 | Please, insert a list of trusted functions [m1:f1/a1, m2:f2/a2 ...]: 3 | sum_digits:sum_digits(134, 10, 11) = 18? [y/n/t/d/i/s/u/a]: n 4 | sum_digits:sum_digits(1, 10, 18) = 18? [y/n/t/d/i/s/u/a]: n 5 | Call to a function that contains an error: 6 | sum_digits:sum_digits(1, 10, 18) = 18 7 | Please, revise the second clause: 8 | sum_digits(N, B, Acc) when N < B -> Acc. 9 | 10 | 11 | 12 | DIVIDE & QUERY: 2 13 | ================= 14 | 5> edd:dd("sum_digits:sum_digits(13456)", tree). 15 | Total number of tree nodes: 7 16 | Tree size: 17 | 1731 words 18 | 13848 bytes 19 | 20 | Please, insert a list of trusted functions [m1:f1/a1, m2:f2/a2 ...]: 21 | sum_digits:sum_digits(134, 10, 11) = 18? [y/n/t/d/i/s/u/a]: n 22 | 23 | Complexity: 1 (base) 24 | 25 | sum_digits:sum_digits(1, 10, 18) = 18? [y/n/t/d/i/s/u/a]: n 26 | 27 | Complexity: 1 (base) 28 | Total complexity: 2 29 | Max complexity: 1 30 | 31 | Call to a function that contains an error: 32 | sum_digits:sum_digits(1, 10, 18) = 18 33 | Please, revise the second clause: 34 | sum_digits(N, B, Acc) when N < B -> Acc. 35 | ok 36 | 37 | 38 | 39 | 40 | TOP-DOWN: 6 41 | ============= 42 | 6> edd:dd("sum_digits:sum_digits(13456)", tree, top_down). 43 | Please, insert a list of trusted functions [m1:f1/a1, m2:f2/a2 ...]: 44 | sum_digits:sum_digits(13456, 10) = 18? [y/n/t/d/i/s/u/a]: n 45 | 46 | Complexity: 1 (base) 47 | 48 | sum_digits:sum_digits(13456, 10, 0) = 18? [y/n/t/d/i/s/u/a]: n 49 | 50 | Complexity: 1 (base) 51 | 52 | sum_digits:sum_digits(1345, 10, 6) = 18? [y/n/t/d/i/s/u/a]: n 53 | 54 | Complexity: 1 (base) 55 | 56 | sum_digits:sum_digits(134, 10, 11) = 18? [y/n/t/d/i/s/u/a]: n 57 | 58 | Complexity: 1 (base) 59 | 60 | sum_digits:sum_digits(13, 10, 15) = 18? [y/n/t/d/i/s/u/a]: n 61 | 62 | Complexity: 1 (base) 63 | 64 | sum_digits:sum_digits(1, 10, 18) = 18? [y/n/t/d/i/s/u/a]: n 65 | 66 | Complexity: 1 (base) 67 | Total complexity: 6 68 | Max complexity: 1 69 | 70 | Call to a function that contains an error: 71 | sum_digits:sum_digits(1, 10, 18) = 18 72 | Please, revise the second clause: 73 | sum_digits(N, B, Acc) when N < B -> Acc. 74 | ok 75 | 76 | -------------------------------------------------------------------------------- /examples/sum_digits/session_zoom.txt: -------------------------------------------------------------------------------- 1 | TOP_DOWN: 2 2 | =========== 3 | 3> edd_zoom:zoom_graph("sum_digits:sum_digits(1, 10, 18)"). 4 | Total number of tree nodes: 4 5 | Tree size: 6 | 1644 words 7 | 13152 bytes 8 | In the function: 9 | sum_digits(N, B, Acc) when N < B -> Acc. 10 | pattern of second clause succeed. 11 | Is this correct? [y/n/d/i/s/u/a]: y 12 | 13 | Complexity: 2 (clauses) + 1 (base) = 3 14 | 15 | In the function: 16 | sum_digits(0, _, Acc) -> Acc. 17 | pattern of first clause failed. 18 | Is this correct? [y/n/d/i/s/u/a]: y 19 | 20 | Complexity: 1 (clauses) + 1 (base) = 2 21 | Total complexity: 5 22 | Max complexity: 3 23 | 24 | This is the reason for the error: 25 | Value 18 for the final expression Acc (Line 14) is not correct. 26 | ok 27 | 28 | 29 | DIVIDE & QUERY: 2 30 | ================= 31 | 4> edd_zoom:zoom_graph("sum_digits:sum_digits(1, 10, 18)"). 32 | Total number of tree nodes: 4 33 | In the function: 34 | sum_digits(N, B, Acc) when N < B -> Acc. 35 | pattern of second clause succeed. 36 | Is this correct? [y/n/d/i/s/u/a]: s 37 | Select a strategy (Didide & Query or Top Down): [d/t] d 38 | In the function: 39 | sum_digits(N, B, Acc) when N < B -> Acc. 40 | pattern of second clause succeed. 41 | Is this correct? [y/n/d/i/s/u/a]: y 42 | 43 | Complexity: 2 (clauses) + 1 (base) = 3 44 | 45 | In the function: 46 | sum_digits(0, _, Acc) -> Acc. 47 | pattern of first clause failed. 48 | Is this correct? [y/n/d/i/s/u/a]: y 49 | 50 | Complexity: 1 (clauses) + 1 (base) = 2 51 | Total complexity: 5 52 | Max complexity: 3 53 | 54 | This is the reason for the error: 55 | Value 18 for the final expression Acc (Line 14) is not correct. 56 | ok 57 | 58 | -------------------------------------------------------------------------------- /examples/sum_digits/sum_digits.erl: -------------------------------------------------------------------------------- 1 | -module(sum_digits). 2 | -export([sum_digits/2, sum_digits/1]). 3 | 4 | sum_digits(N) -> 5 | sum_digits(N,10). 6 | 7 | sum_digits(N,B) -> 8 | sum_digits(N,B,0). 9 | 10 | sum_digits(0,_,Acc) -> 11 | Acc; 12 | sum_digits(N,B,Acc) when N < B -> 13 | %Acc+N; %RIGHT 14 | Acc; %WRONG 15 | sum_digits(N,B,Acc) -> 16 | sum_digits(N div B, B, Acc + (N rem B)). 17 | -------------------------------------------------------------------------------- /examples/sum_digits/sum_digits_ok.erl: -------------------------------------------------------------------------------- 1 | -module(sum_digits_ok). 2 | -compile([export_all]). 3 | 4 | sum_digits(N) -> 5 | sum_digits(N,10). 6 | 7 | sum_digits(N,B) -> 8 | sum_digits(N,B,0). 9 | 10 | sum_digits(0,_,Acc) -> 11 | Acc; 12 | sum_digits(N,B,Acc) when N < B -> 13 | Acc+N; 14 | sum_digits(N,B,Acc) -> 15 | sum_digits(N div B, B, Acc + (N rem B)). 16 | -------------------------------------------------------------------------------- /examples/ternary/Readme: -------------------------------------------------------------------------------- 1 | Balanced ternary 2 | http://rosettacode.org/wiki/Balanced_ternary 3 | -------------------------------------------------------------------------------- /examples/ternary/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/ternary/dbg.pdf -------------------------------------------------------------------------------- /examples/ternary/dbg_zoom.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/ternary/dbg_zoom.pdf -------------------------------------------------------------------------------- /examples/ternary/ternary_ok.erl: -------------------------------------------------------------------------------- 1 | %edd:dd("ternary:test()"). 2 | -module(ternary_ok). 3 | -compile(export_all). 4 | 5 | test() -> 6 | AS = "+-0++0+", AT = from_string(AS), A = from_ternary(AT), 7 | B = -436, BT = to_ternary(B), BS = to_string(BT), 8 | CS = "+-++-", CT = from_string(CS), C = from_ternary(CT), 9 | RT = mul(AT,sub(BT,CT)), 10 | R = from_ternary(RT), 11 | RS = to_string(RT), 12 | [{AS,A},{BS,B},{CS,C},{RS,R}]. 13 | %io:fwrite("A = ~s -> ~b~n",[AS, A]), 14 | %io:fwrite("B = ~s -> ~b~n",[BS, B]), 15 | %io:fwrite("C = ~s -> ~b~n",[CS, C]), 16 | %io:fwrite("A x (B - C) = ~s -> ~b~n", [RS, R]). 17 | 18 | to_string(T) -> [to_char(X) || X <- T]. 19 | 20 | from_string(S) -> [from_char(X) || X <- S]. 21 | 22 | to_char(-1) -> $-; 23 | to_char(0) -> $0; 24 | to_char(1) -> $+. 25 | 26 | from_char($-) -> -1; 27 | from_char($0) -> 0; 28 | from_char($+) -> 1. 29 | 30 | to_ternary(N) when N > 0 -> 31 | to_ternary(N,[]); 32 | to_ternary(N) -> 33 | neg(to_ternary(-N)). 34 | 35 | to_ternary(0,Acc) -> 36 | Acc; 37 | to_ternary(N,Acc) when N rem 3 == 0 -> 38 | to_ternary(N div 3, [0|Acc]); 39 | to_ternary(N,Acc) when N rem 3 == 1 -> 40 | to_ternary(N div 3, [1|Acc]); 41 | to_ternary(N,Acc) -> 42 | to_ternary((N+1) div 3, [-1|Acc]). 43 | 44 | from_ternary(T) -> from_ternary(T,0). 45 | 46 | from_ternary([],Acc) -> 47 | Acc; 48 | from_ternary([H|T],Acc) -> 49 | from_ternary(T,Acc*3 + H). 50 | 51 | mul(A,B) -> mul(B,A,[]). 52 | 53 | mul(_,[],Acc) -> 54 | Acc; 55 | mul(B,[A|As],Acc) -> 56 | BP = case A of 57 | -1 -> neg(B); 58 | 0 -> [0]; 59 | 1 -> B 60 | end, 61 | A1 = Acc++[0], 62 | A2=add(BP,A1), 63 | mul(B,As,A2). 64 | 65 | 66 | neg(T) -> [ -H || H <- T]. 67 | 68 | sub(A,B) -> add(A,neg(B)). 69 | 70 | add(A,B) when length(A) < length(B) -> 71 | add(lists:duplicate(length(B)-length(A),0)++A,B); 72 | add(A,B) when length(A) > length(B) -> 73 | add(B,A); 74 | add(A,B) -> 75 | add(lists:reverse(A),lists:reverse(B),0,[]). 76 | 77 | add([],[],0,Acc) -> 78 | Acc; 79 | add([],[],C,Acc) -> 80 | [C|Acc]; 81 | add([A|As],[B|Bs],C,Acc) -> 82 | [C1,D] = add_util(A+B+C), 83 | add(As,Bs,C1,[D|Acc]). 84 | 85 | add_util(-3) -> [-1,0]; 86 | add_util(-2) -> [-1,1]; 87 | add_util(-1) -> [0,-1]; 88 | add_util(3) -> [1,0]; 89 | add_util(2) -> [1,-1]; 90 | add_util(1) -> [0,1]; 91 | add_util(0) -> [0,0]. 92 | -------------------------------------------------------------------------------- /examples/turing/Readme: -------------------------------------------------------------------------------- 1 | Universal Turing machine 2 | http://rosettacode.org/wiki/Universal_Turing_machine 3 | -------------------------------------------------------------------------------- /examples/turing/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/turing/dbg.pdf -------------------------------------------------------------------------------- /examples/turing/dbg_zoom.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/turing/dbg_zoom.pdf -------------------------------------------------------------------------------- /examples/turing/turing_ok.erl: -------------------------------------------------------------------------------- 1 | -module(turing_ok). 2 | -compile([export_all]). 3 | 4 | % Incrementer definition: 5 | % States: a | halt 6 | % Initial state: a 7 | % Halting states: halt 8 | % Symbols: b | '1' 9 | % Blank symbol: b 10 | incrementer_config() -> {a, [halt], b}. 11 | incrementer(a, '1') -> {'1', right, a}; 12 | incrementer(a, b) -> {'1', stay, halt}. 13 | 14 | % Busy beaver definition: 15 | % States: a | b | c | halt 16 | % Initial state: a 17 | % Halting states: halt 18 | % Symbols: '0' | '1' 19 | % Blank symbol: '0' 20 | busy_beaver_config() -> {a, [halt], '0'}. 21 | busy_beaver(a, '0') -> {'1', right, b}; 22 | busy_beaver(a, '1') -> {'1', left, c}; 23 | busy_beaver(b, '0') -> {'1', left, a}; 24 | busy_beaver(b, '1') -> {'1', right, b}; 25 | busy_beaver(c, '0') -> {'1', left, b}; 26 | busy_beaver(c, '1') -> {'1', stay, halt}. 27 | 28 | % Mainline code. 29 | main() -> 30 | %io:format("==============================~n"), 31 | %io:format("Turing machine simulator test.~n"), 32 | %io:format("==============================~n"), 33 | 34 | Tape1 = turing(fun incrementer_config/0, fun incrementer/2, ['1','1','1']), 35 | % io:format("~w~n", [Tape1]), 36 | 37 | Tape2 = turing(fun busy_beaver_config/0, fun busy_beaver/2, []), 38 | %io:format("~w~n", [Tape2]). 39 | {Tape1, Tape2}. 40 | 41 | % Universal Turing machine simulator. 42 | turing(Config, Rules, Input) -> 43 | {Start, _, _} = Config(), 44 | {Left, Right} = perform(Config, Rules, Start, {[], Input}), 45 | lists:reverse(Left) ++ Right. 46 | 47 | perform(Config, Rules, State, Input = {LeftInput, RightInput}) -> 48 | {_, Halts, Blank} = Config(), 49 | case lists:member(State, Halts) of 50 | true -> Input; 51 | false -> 52 | {NewRight, Symbol} = symbol(RightInput, Blank), 53 | {NewSymbol, Action, NewState} = Rules(State, Symbol), 54 | NewInput = action(Action, Blank, {LeftInput, [NewSymbol| NewRight]}), 55 | perform(Config, Rules, NewState, NewInput) 56 | end. 57 | 58 | symbol([], Blank) -> {[], Blank}; 59 | symbol([S|R], _) -> {R, S}. 60 | 61 | action(left, Blank, {[], Right}) -> 62 | {[], [Blank|Right]}; 63 | action(left, _, {[L|Ls], Right}) -> {Ls, [L|Right]}; 64 | action(stay, _, Tape) -> Tape; 65 | action(right, Blank, {Left, []}) -> {[Blank|Left], []}; 66 | action(right, _, {Left, [R|Rs]}) -> {[R|Left], Rs}. 67 | -------------------------------------------------------------------------------- /examples/vigenere/Readme: -------------------------------------------------------------------------------- 1 | Vigenère cipher 2 | http://rosettacode.org/wiki/Vigen%C3%A8re_cipher 3 | -------------------------------------------------------------------------------- /examples/vigenere/dbg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tamarit/edd/867f287efe951bec6a8213743a218b86e4f5bbf7/examples/vigenere/dbg.pdf -------------------------------------------------------------------------------- /examples/vigenere/vigenere.erl: -------------------------------------------------------------------------------- 1 | % Erlang implementation of Vigenère cipher 2 | % Code from Rosetta Code 3 | % http://rosettacode.org/wiki/Vigen%C3%A8re_cipher#Erlang 4 | 5 | -module(vigenere). 6 | -export([encrypt/2, decrypt/2]). 7 | -import(lists, [append/2, filter/2, map/2, zipwith/3]). 8 | 9 | % Utility functions for character tests and conversions 10 | isupper([C|_]) -> isupper(C); 11 | isupper(C) -> (C >= $A) and (C =< $Z). 12 | 13 | islower([C|_]) -> islower(C); 14 | islower(C) -> (C >= $a) and (C =< $z). 15 | 16 | isalpha([C|_]) -> isalpha(C); 17 | isalpha(C) -> isupper(C) or islower(C). 18 | 19 | toupper(S) when is_list(S) -> lists:map(fun toupper/1, S); 20 | toupper(C) when (C >= $a) and (C =< $z) -> C - $a + $A; 21 | toupper(C) -> C. 22 | 23 | % modulo function that normalizes into positive range for positive divisor 24 | mod(X,Y) -> (X rem Y + Y) rem Y. 25 | 26 | % convert letter to position in alphabet (A=0,B=1,...,Y=24,Z=25). 27 | to_pos(L) when L >= $A, L =< $Z -> L - $A. 28 | 29 | % convert position in alphabet back to letter 30 | from_pos(N) -> mod(N, 26) + $A. 31 | 32 | % encode the given letter given the single-letter key 33 | encipher(P, K) -> from_pos(to_pos(P) + to_pos(K)). 34 | 35 | % decode the given letter given the single-letter key 36 | decipher(C, K) -> from_pos(to_pos(C) - to_pos(K)). 37 | 38 | % extend a list by repeating it until it is at least N elements long 39 | cycle_to(N, List) when length(List) >= N -> List; 40 | cycle_to(N, List) -> append(List, cycle_to(N-length(List), List)). 41 | % The bug is that cycle_to does not trim the remaining length of the list in the 42 | % base case. The first rule should be: 43 | % cycle_to(N, List) when length(List) >= N -> 44 | % {Take,_} = lists:split(N,List), 45 | % Take; 46 | 47 | % Encryption prep: reduce string to only its letters, in uppercase 48 | normalize(Str) -> toupper(filter(fun isalpha/1, Str)). 49 | 50 | crypt(RawText, RawKey, Func) -> 51 | PlainText = normalize(RawText), 52 | zipwith(Func, PlainText, cycle_to(length(PlainText), normalize(RawKey))). 53 | 54 | encrypt(Text, Key) -> crypt(Text, Key, fun encipher/2). 55 | decrypt(Text, Key) -> crypt(Text, Key, fun decipher/2). 56 | -------------------------------------------------------------------------------- /examples/vigenere/vigenere_ok.erl: -------------------------------------------------------------------------------- 1 | % Erlang implementation of Vigenère cipher 2 | % Code from Rosetta Code 3 | % http://rosettacode.org/wiki/Vigen%C3%A8re_cipher#Erlang 4 | 5 | -module(vigenere_ok). 6 | -export([encrypt/2, decrypt/2, from_pos/1, to_pos/1, encrypt/2]). 7 | -import(lists, [append/2, filter/2, map/2, zipwith/3]). 8 | 9 | % Utility functions for character tests and conversions 10 | isupper([C|_]) -> isupper(C); 11 | isupper(C) -> (C >= $A) and (C =< $Z). 12 | 13 | islower([C|_]) -> islower(C); 14 | islower(C) -> (C >= $a) and (C =< $z). 15 | 16 | isalpha([C|_]) -> isalpha(C); 17 | isalpha(C) -> isupper(C) or islower(C). 18 | 19 | toupper(S) when is_list(S) -> lists:map(fun toupper/1, S); 20 | toupper(C) when (C >= $a) and (C =< $z) -> C - $a + $A; 21 | toupper(C) -> C. 22 | 23 | % modulo function that normalizes into positive range for positive divisor 24 | mod(X,Y) -> (X rem Y + Y) rem Y. 25 | 26 | % convert letter to position in alphabet (A=0,B=1,...,Y=24,Z=25). 27 | to_pos(L) when L >= $A, L =< $Z -> L - $A. 28 | 29 | % convert position in alphabet back to letter 30 | from_pos(N) -> mod(N, 26) + $A. 31 | 32 | % encode the given letter given the single-letter key 33 | encipher(P, K) -> from_pos(to_pos(P) + to_pos(K)). 34 | 35 | % decode the given letter given the single-letter key 36 | decipher(C, K) -> from_pos(to_pos(C) - to_pos(K)). 37 | 38 | % extend a list by repeating it until it is at least N elements long 39 | %cycle_to(N, List) when length(List) >= N -> List; 40 | cycle_to(N, List) when length(List) >= N -> 41 | {Take,_} = lists:split(N,List), 42 | Take; 43 | cycle_to(N, List) -> append(List, cycle_to(N-length(List), List)). 44 | % The bug is that cycle_to does not trim the remaining length of the list in the 45 | % base case. The first rule should be: 46 | 47 | 48 | % Encryption prep: reduce string to only its letters, in uppercase 49 | normalize(Str) -> toupper(filter(fun isalpha/1, Str)). 50 | 51 | crypt(RawText, RawKey, Func) -> 52 | PlainText = normalize(RawText), 53 | zipwith(Func, PlainText, cycle_to(length(PlainText), normalize(RawKey))). 54 | 55 | encrypt(Text, Key) -> crypt(Text, Key, fun encipher/2). 56 | decrypt(Text, Key) -> crypt(Text, Key, fun decipher/2). 57 | -------------------------------------------------------------------------------- /java/README.md: -------------------------------------------------------------------------------- 1 | Java interface for EDD 2 | ====================== 3 | 4 | Usage: 5 | 6 | java EDDJInterface "ackermann:main([3,4])" "../examples/ackermann/" 7 | -------------------------------------------------------------------------------- /java/load_erlang_server.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd ../ebin 4 | erl -sname edderlang@localhost -run edd_jserver start -noshell -s erlang halt -------------------------------------------------------------------------------- /src/edd_client.erl: -------------------------------------------------------------------------------- 1 | -module(edd_client). 2 | 3 | -export([client/3, start/2]). 4 | 5 | -define(DEF_PORT, 6667). 6 | 7 | start(Dir, Call) -> 8 | client(?DEF_PORT, Dir, Call). 9 | 10 | 11 | client(Port, Dir, Call) -> 12 | {ok, Sock} = gen_tcp:connect("localhost", Port, 13 | [binary, {packet, 0}, {active, false}]), 14 | client_control(Sock, Dir, Call). 15 | 16 | client_control(Sock, Dir, Call) -> 17 | case gen_tcp:send(Sock,Dir) of 18 | ok -> 19 | ok; 20 | {error,Reason} -> 21 | io:format("Error: ~p\n",[Reason]), 22 | erlang:error(error) 23 | end, 24 | client_receive(Sock), 25 | case gen_tcp:send(Sock,Call) of 26 | ok -> 27 | ok; 28 | {error,Reason2} -> 29 | io:format("Error: ~p\n",[Reason2]), 30 | erlang:error(error) 31 | end, 32 | client_receive(Sock). 33 | % client_receive(Sock). 34 | 35 | client_receive(Sock) -> 36 | case gen_tcp:recv(Sock, 0) of 37 | {ok, Data} -> 38 | io:format("Answer: ~s\n", [binary_to_list(Data)]); 39 | {error, Reason} -> 40 | io:format("Error: ~p\n",[Reason]), 41 | erlang:error(error) 42 | end. 43 | -------------------------------------------------------------------------------- /src/edd_con.hrl: -------------------------------------------------------------------------------- 1 | -record(question, 2 | { 3 | text = none, 4 | answers = [], 5 | str_callrec = none 6 | }). 7 | 8 | -record(answer, 9 | { 10 | text = none, 11 | when_chosen = none, 12 | complexity = 1 13 | }). 14 | 15 | -record(callrec_stack_item, 16 | { 17 | origin_callrec = none, 18 | reached_rec_val = none, 19 | context = [], 20 | spawned = [], 21 | sent =[], 22 | received = [], 23 | consumed = [], 24 | % children_nodes = [], 25 | result = none, 26 | trace = none 27 | }). 28 | 29 | -record(call_info, 30 | { 31 | call = none, 32 | pos_pp = none 33 | }). 34 | 35 | -record(receive_info, 36 | { 37 | pos_pp = none, 38 | context = [], 39 | bindings = [], 40 | clause = none 41 | }). 42 | 43 | % -record(debugger_state, 44 | % {graph, strategy, priority, 45 | % vertices = [], correct = [], 46 | % not_correct = [], unknown = [], 47 | % previous_state = [], 48 | % preselected = none, 49 | % pids = []}). 50 | 51 | -record(edd_con_state, 52 | {graph, dict_questions, strategy, priority, 53 | vertices = [], correct = [], 54 | not_correct = [], unknown = [], 55 | previous_state = none, 56 | pids = [], 57 | preselected = none, 58 | summary_pids = [], 59 | dicts_trace = [], 60 | fun_ask_question, 61 | comms = []}). 62 | --------------------------------------------------------------------------------