Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored and prepared erlog for production use #13

Open
wants to merge 265 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
265 commits
Select commit Hold shift + click to select a range
082cdc2
fix rte
comtihon Jun 17, 2014
8e1c119
partly refactored db module, add callback interface
comtihon Jun 17, 2014
d247128
refactored erlog_int, added callback and implementation for ets and dict
comtihon Jun 19, 2014
0a10905
refactor in asserta-z
comtihon Jun 19, 2014
fac660d
refactoring and fixes in implementation
comtihon Jun 19, 2014
b58d2d1
fix errors and update docs
comtihon Jun 20, 2014
7f711a6
improve docs, fix erlang-erlang commands
comtihon Jun 20, 2014
fce86b5
made selecting result
comtihon Jun 21, 2014
3423945
fix solution selecting
comtihon Jun 21, 2014
500b3ec
added params passing to erlog_storage impl, update readme
comtihon Jun 24, 2014
2dc1346
fix interfase return new
comtihon Jun 25, 2014
540b144
made consulter function passing
comtihon Jun 25, 2014
db7fcc5
fix mass reconsult
comtihon Jun 25, 2014
d0f2350
fix error with unexported functions
comtihon Jul 1, 2014
c741698
fix one function clause in preprocess_command when loading a file
comtihon Jul 1, 2014
36513e2
Merge remote-tracking branch 'origin/master' into develop
comtihon Jul 1, 2014
9ab113d
fix consulting file error
comtihon Jul 2, 2014
b0e4bef
update readme
comtihon Jul 2, 2014
ef11ef1
fix files consilting, remove db passing from reconsulting
comtihon Jul 2, 2014
dffe6ad
fix errors, pass 1 test
comtihon Jul 4, 2014
f507cdb
fix cte
comtihon Jul 4, 2014
5a62008
add consult and reconsult
comtihon Jul 5, 2014
b13291b
added todo question
comtihon Jul 5, 2014
5492d48
added test
comtihon Jul 8, 2014
356c62b
big core refactoring, added writeln/1
comtihon Jul 11, 2014
e87a641
return shell
comtihon Jul 11, 2014
60f1609
maked erlang return format instead binary
comtihon Jul 11, 2014
7e33a0e
updated readme
comtihon Jul 11, 2014
814e9c8
split execute into select and normal. Move method selection to realis…
comtihon Jul 13, 2014
0580973
fix remote shell & update readme
comtihon Jul 13, 2014
ba552a5
findall added
comtihon Jul 13, 2014
6c28d55
made bagof
comtihon Jul 15, 2014
f43b806
added localtime
comtihon Jul 15, 2014
6911d0a
fix datediff
comtihon Jul 15, 2014
5fcc1aa
refactoring -> improve code quality
comtihon Jul 15, 2014
128f0d6
partly fix test file
comtihon Jul 15, 2014
3e83889
add date_add predicate
comtihon Jul 16, 2014
47ae0ab
added parse, add and print in data library
comtihon Jul 16, 2014
061e028
add some more data predicates
comtihon Jul 17, 2014
96ad003
partly added db module
comtihon Jul 17, 2014
9b27362
fix loading
comtihon Jul 17, 2014
3235c3f
fix mistake in export
comtihon Jul 17, 2014
6ef8c66
add load predicate, fix halt erlog_local_shell
comtihon Jul 17, 2014
b6abf30
fix time names
comtihon Jul 17, 2014
a13e08b
fix vars binding
comtihon Jul 17, 2014
2f69841
remove debug
comtihon Jul 17, 2014
0e14286
change io:fread to getline, fix seconds to date
comtihon Jul 17, 2014
ad9d74a
renamed add time and remove round
comtihon Jul 17, 2014
5a6f73e
made proper output in erlog_local_shell
comtihon Jul 18, 2014
7a14ddb
fix ec_term export
comtihon Jul 18, 2014
3eb718d
update time test
comtihon Jul 18, 2014
9b63e3a
fix time for integers < 0
comtihon Jul 18, 2014
bb2f20e
fix erlog_db names
comtihon Jul 18, 2014
2e47efd
fix negative tied values
comtihon Jul 18, 2014
a8257ae
removed debug
comtihon Jul 18, 2014
f9339fa
fix functions aritty
comtihon Jul 18, 2014
e3b9651
made proper error return
comtihon Jul 21, 2014
739369e
fix database module
comtihon Jul 22, 2014
c11727e
made retractall
comtihon Jul 22, 2014
bd8bc45
made db_retractall
comtihon Jul 22, 2014
7f45708
change data format
comtihon Jul 22, 2014
33d637d
updated readme
comtihon Jul 22, 2014
81e1355
take findall from @rviding develop branch
comtihon Jul 23, 2014
5429934
made db_call
comtihon Jul 24, 2014
75a9bbf
changed db_call
comtihon Jul 24, 2014
19aa72c
got rid of reverse in raw fetch -> move it to custom implementation
comtihon Jul 24, 2014
b437345
fix concatination in case of string results
comtihon Jul 24, 2014
5d58087
added erlog currency server
comtihon Jul 25, 2014
23419ea
make db_call return false if no facts
comtihon Jul 25, 2014
43e237a
change dict:dict() to atom dict to support r17-
comtihon Jul 25, 2014
7f16f0e
add exchange command
comtihon Jul 28, 2014
1e072d0
fix error with var
comtihon Jul 28, 2014
0ba3a66
check one more var
comtihon Jul 28, 2014
71418a8
fix retract
comtihon Jul 30, 2014
828c883
fix db_retract
comtihon Jul 30, 2014
6f0592d
improve writeln
comtihon Jul 31, 2014
015b649
improved writeln once again
comtihon Jul 31, 2014
9ddbb7c
fix consulting through var & little improvements in time
comtihon Aug 1, 2014
1acd9a1
revert time changing, remove flattering of result in writeln
comtihon Aug 1, 2014
44b3516
added list length
comtihon Aug 5, 2014
1e487d7
added lising command
comtihon Aug 11, 2014
72a95e5
change lising logic
comtihon Aug 11, 2014
e4ac88e
made stdlib
comtihon Aug 12, 2014
4b63bbb
added to_string and to_intege
comtihon Aug 12, 2014
ab7ce3a
add uuid (temporary)
comtihon Aug 12, 2014
10a8875
fix db_call
comtihon Aug 13, 2014
644e508
fix eval
comtihon Aug 13, 2014
e92c614
fix findall
comtihon Aug 14, 2014
f4e95e1
add spikes for support fuctions
comtihon Aug 14, 2014
d94ff46
Revert "add spikes for support fuctions"
comtihon Aug 14, 2014
3a64007
revert commit and change support functions mechanics
comtihon Aug 14, 2014
3dc2c13
removed external lib from erlog
comtihon Aug 15, 2014
0a0b810
added listing/2 listing/3
comtihon Aug 15, 2014
1ab185c
added db_listing/2 db_listing/3
comtihon Aug 15, 2014
6ac7e31
make assert filter duplicates
comtihon Aug 16, 2014
afc7b3a
change version to 1
comtihon Aug 18, 2014
49a69fd
add doc for libraries
comtihon Aug 18, 2014
163e9a9
added cache lib
comtihon Aug 19, 2014
901fe93
fix db_call
comtihon Aug 19, 2014
b335d41
improve db_call
comtihon Aug 19, 2014
489569c
fix erlog_db clauses
comtihon Aug 19, 2014
feb7ffe
fix mistake when terminating
comtihon Aug 20, 2014
9644699
speed improvements, move library and kernel space to local ets
comtihon Aug 20, 2014
9cd10dc
fix abolish
comtihon Aug 20, 2014
758a1db
fix db_findall
comtihon Aug 20, 2014
766b38b
improved cache
comtihon Aug 20, 2014
2ad67b6
fix findall
comtihon Aug 20, 2014
af9347c
moved raw_functions for findall to erlog_memory's ets
comtihon Aug 25, 2014
abbc867
findall fixes
comtihon Aug 25, 2014
c4c1bf7
make exlib onstart loading
comtihon Aug 25, 2014
473c5d8
add profiling
comtihon Sep 1, 2014
03c65da
fix debug
comtihon Sep 1, 2014
83bd21b
move everything to dict. Made dict - default impl
comtihon Sep 8, 2014
a834687
test added
comtihon Sep 8, 2014
e0d31ff
revert ets
comtihon Sep 9, 2014
d07d516
Revert "revert ets"
comtihon Sep 11, 2014
eeb3133
fix r16 compatibility
comtihon Sep 11, 2014
bf49572
added possibility to call execute with custom timeout
comtihon Sep 11, 2014
feb9845
fix db_storage & make errlog_local_shell execute without timeouts
comtihon Sep 12, 2014
c6374e2
Merge branch 'master' into develop
comtihon Sep 12, 2014
a14efc8
fix storage
comtihon Sep 12, 2014
02fcb04
fix get_dbs
comtihon Sep 12, 2014
8fa4efb
fix possible crashes
comtihon Sep 16, 2014
c3df84e
remove profiling
comtihon Sep 16, 2014
25660e8
fix db_call
comtihon Sep 16, 2014
9b07c39
added simple debugger - just listing
comtihon Sep 19, 2014
2b17e10
fix default debugger fun
comtihon Sep 23, 2014
69a29e8
add stopping by counter
comtihon Sep 23, 2014
7463707
update docs, improve debugger
comtihon Sep 23, 2014
f2c0792
Merge branch 'master' into develop
comtihon Sep 23, 2014
7634da7
change erlog_memory for cursor usage
comtihon Sep 23, 2014
ed83499
refactoring of ec_core
comtihon Sep 23, 2014
9e4621d
fix debugger empty vars
comtihon Sep 23, 2014
0096e00
made cursor logic
comtihon Sep 24, 2014
9208726
made db_lib working
comtihon Sep 24, 2014
f84cbf7
fix cutpoint ending
comtihon Sep 24, 2014
beff4f5
made db_call working with multiple clauses
comtihon Sep 24, 2014
660e3c8
make r16b03 compatible
comtihon Sep 25, 2014
151630c
fix clauses with body issue
comtihon Sep 26, 2014
0b873f0
fix permission denied errors
comtihon Sep 26, 2014
b32ed97
erlog memory refactoring
comtihon Sep 30, 2014
1035f51
fix closing cursor issue
comtihon Sep 30, 2014
ca50626
fix complex variant selecting, break hand variants selecting
comtihon Oct 1, 2014
1cc5965
fix clause and empty cursor next
comtihon Oct 2, 2014
86e261e
fix retractall & db_retractall & db_call
comtihon Oct 2, 2014
d11e4f8
add spy to debugger
comtihon Oct 3, 2014
ded718a
fix mistake with cursor passing
comtihon Oct 3, 2014
ad302e6
fix ets next
comtihon Oct 3, 2014
1d2d41d
fix multiple clauses issue
comtihon Oct 3, 2014
55ec1fe
add memory documentation
comtihon Oct 6, 2014
1d359b6
improve debugger and documentation
comtihon Oct 6, 2014
364abff
fix debugger fall on support functions
comtihon Oct 7, 2014
89d0c3e
fix db_retract
comtihon Oct 7, 2014
2a4c797
fix retractall & db_retractall & unify clauses
comtihon Oct 8, 2014
fde31aa
fix retract clauses
comtihon Oct 8, 2014
98df639
add breakpoint support in debugger
comtihon Oct 8, 2014
fbe5cac
fix readme
comtihon Oct 8, 2014
b382738
add state passing to close & next
comtihon Oct 13, 2014
12c57d0
partly made updating cursors
comtihon Oct 13, 2014
7ec6e7d
fix retract clauses & mistakes in next
comtihon Oct 13, 2014
01aa278
update doc, remove proc dict cursor impl
comtihon Oct 13, 2014
ca23be6
added important todo thought
comtihon Oct 14, 2014
a51589e
rename short named files in case of conflicts with other project's deps
comtihon Oct 17, 2014
8d524fa
add string library
comtihon Oct 22, 2014
d27551e
add prolog library autoload
comtihon Oct 25, 2014
0fe5b99
moved prolog libraries to userspace
comtihon Oct 25, 2014
c057fb5
make loading prolog libraries through standard loading interface
comtihon Oct 28, 2014
2b713ea
update doc
comtihon Oct 28, 2014
3463b52
fix list defererence
comtihon Oct 28, 2014
420d276
fix list defererence
comtihon Oct 28, 2014
931caa5
Revert "fix list defererence"
comtihon Oct 28, 2014
8f292b9
fix string list dderef
comtihon Oct 28, 2014
350122d
Merge branch 'master' into libraries
comtihon Oct 29, 2014
e97631a
remove debug
comtihon Oct 30, 2014
d6b3ba3
improved localtime logic
comtihon Oct 31, 2014
d9a3960
add try_add
comtihon Nov 1, 2014
a6448c7
Merge remote-tracking branch 'origin/master' into libraries
comtihon Nov 3, 2014
a9f6732
partly refactored erlog_memory
comtihon Nov 3, 2014
89e7ec3
fix listing
comtihon Nov 3, 2014
8171d32
move functor deeper from db_call to db_findall
comtihon Nov 4, 2014
75679a0
move functor of get_proc_type deeper
comtihon Nov 4, 2014
00bb4a4
some fixes in db modules
comtihon Nov 4, 2014
38e37c6
fix get procedure
comtihon Nov 4, 2014
611269a
add db_next
comtihon Nov 4, 2014
16b7700
fix apply
comtihon Nov 4, 2014
c50c2c0
fix db_next
comtihon Nov 4, 2014
842c15d
fix spec
comtihon Nov 4, 2014
60667af
add libraries
comtihon Nov 11, 2014
b7a2b83
fix db_next
comtihon Nov 11, 2014
a162b73
refactoring
comtihon Nov 11, 2014
4105a29
move check var to support
comtihon Nov 12, 2014
7dbad31
add legasy branch
comtihon Nov 13, 2014
6a322fa
cherry pick prove_call export
comtihon Nov 13, 2014
55b237a
improve date diff
comtihon Nov 17, 2014
12f7e4b
merge
comtihon Nov 17, 2014
567ae39
fix merge
comtihon Nov 18, 2014
d10ef8c
merge legasy fixes
comtihon Nov 21, 2014
c1086a5
fix loading libs in memory
comtihon Nov 22, 2014
2715dc3
add deconsult
comtihon Nov 22, 2014
cbe76c9
refactored erlog_memory
comtihon Nov 26, 2014
5815502
refactored, but not tested
comtihon Nov 28, 2014
d9cfca7
fix db_iteration
comtihon Nov 29, 2014
bc3f4d5
fix db clause
comtihon Nov 29, 2014
34cf4fe
Merge remote-tracking branch 'origin/master' into develop
comtihon Nov 29, 2014
2675a20
fix pgc on fail
comtihon Nov 29, 2014
10c0ac0
Merge remote-tracking branch 'origin/master' into develop
comtihon Nov 29, 2014
15c3df4
another fixes
comtihon Nov 29, 2014
3650a94
Merge remote-tracking branch 'origin/master' into develop
comtihon Nov 29, 2014
a7d966d
fix writeln
comtihon Dec 1, 2014
f331043
fix deconsult
comtihon Dec 2, 2014
48701da
make prove_call public
comtihon Dec 3, 2014
cf45a15
Merge remote-tracking branch 'origin/master' into develop
comtihon Dec 4, 2014
061e1c9
fix use
comtihon Dec 5, 2014
c58c6be
fix db-next
comtihon Dec 5, 2014
32fcfb6
fix case clause when using db impl
comtihon Dec 6, 2014
c20d258
fix warning
comtihon Dec 6, 2014
c5bf49b
fix db passing when fail in clause
comtihon Dec 9, 2014
92997a8
export debug fun
comtihon Dec 10, 2014
a76309d
export debug fun
comtihon Dec 10, 2014
a4e1a08
add timeout for select
comtihon Dec 10, 2014
f21bc7a
fix float negative numbers
comtihon Dec 11, 2014
9940a87
fix float negative numbers
comtihon Dec 11, 2014
e6653fc
improve concat
comtihon Dec 11, 2014
5fca69f
added math library
comtihon Dec 15, 2014
b01cd4d
Merge remote-tracking branch 'origin/master' into develop
comtihon Dec 15, 2014
7319b9c
add ability to round float to integer
comtihon Dec 15, 2014
259b102
fixed merge with master
comtihon Dec 15, 2014
552eb60
Merge branch 'master' into develop
comtihon Dec 15, 2014
a1a301a
improve string libs
comtihon Dec 21, 2014
03a4fd1
fix substring
comtihon Dec 23, 2014
a753a61
made substring tryadd
comtihon Dec 24, 2014
cc63e63
fix concat
comtihon Dec 24, 2014
541dc66
remove checks from db functions
comtihon Dec 25, 2014
1ab23ea
fix retract
comtihon Dec 25, 2014
8d53c1b
fix findall
comtihon Dec 25, 2014
6923c8a
return split
comtihon Jan 12, 2015
91990d7
fix date diff
comtihon Jan 14, 2015
c21755c
Made local vars appear in debugger
comtihon Jan 19, 2015
051ab37
fix rubish
comtihon Jan 20, 2015
2877d06
change localvars to {int}
comtihon Jan 20, 2015
ba3bd22
rem def
comtihon Jan 20, 2015
08897ff
improve debugger
comtihon Jan 21, 2015
a3e7894
add parallel lib
comtihon Jan 31, 2015
d0b32d9
fix parallel
comtihon Feb 2, 2015
9eb934a
add claust
comtihon Feb 2, 2015
0c0997a
improve parallel interface
comtihon Feb 2, 2015
fa7c9ec
improve erlog_parallel
comtihon Feb 6, 2015
68fd467
remove test as it is not library
comtihon Feb 6, 2015
bdf7f5a
add support for string split and multiple vars
comtihon Feb 18, 2015
d0f74a5
fix lists length when list is [1|{4}]
comtihon Apr 23, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
*~
.DS_Store
*.beam
ebin
.idea
*.iml
erlog_scan.erl
*.dump
rel/erlog
.rebar
.eunit
deps
File renamed without changes.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ compile:
## Compile using erlc
erlc_compile: $(addprefix $(EBINDIR)/, $(EBINS))

rel: compile
rebar generate

docs:

clean:
Expand Down
3 changes: 0 additions & 3 deletions README

This file was deleted.

156 changes: 156 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
Erlog is a Prolog interpreter implemented in Erlang and integrated
with the Erlang runtime system. It is a subset of the Prolog standard.
An erlog shell is also included.

### Usage
Make erlog:

make rel

#### Command line prolog coding:
##### Local shell
To use local shell just run erlang emulator in directory with compiled beam files (`ebin`) and run local shell:

make
cd ebin
erl
erlog_local_shell:start().
##### Remote shell
You can use remote shell and connect to it via telnet.
Run release:

./rel/erlog/bin/erlog start
And connect to it via console:

telnet 127.0.0.1 8080
Port can be set up in `src/erlog.app.src`.

#### Debugger
Debugger can be passed to erlog as a parameter {debugger, Fun}, where `Fun` is your fun of calling debugger:

{ok, Core} = erlog:start_link([{debugger, fun(Status, Functor, Result) -> gen_server:call(Debugger, {Status, Functor, Result}) end}]),
Where __Status__ is a status of command - `ok|failed`, __Functor__ is current working functor, __Result__ is a result
prolog term - complex structure with all data.
As an example you can use `erlog_simple_debugger` with `erlog_local_shell`:

{ok, Pid} = erlog_simple_debugger:start_link().
erlog_local_shell:start(Pid).
More in [docs](https://github.com/comtihon/erlog/blob/master/doc/debugger.md "debugger").

#### Processing prolog code from erlang:
##### Starting
Spawn new logic core:

{ok, Pid} = erlog:start_link().
##### Executing
Process prolog terms, using your core:

erlog:execute(Worker, Command).
Where:
`Command` is a command, ended with dot,
`Worker` is a pid of your prolog logic core.
##### Selecting
When erlog:execute returns `select` in result - you can select for some other result calling `erlog:select/2` instead of execute.

erlog:select(Worker, ";").
Full Example:

([email protected])1> {ok, Pid} = erlog:start_link().
{ok,<0.961.0>}
([email protected])2> erlog:execute(Pid, "assert(father('victor', 'andrey')).").
true
([email protected])3> erlog:execute(Pid, "father('victor', 'andrey').").
true
([email protected])4> erlog:execute(Pid, "father('victor', 'vasya').").
false
([email protected])5> erlog:execute(Pid, "run(S).").
{{true,[{'S',600}]}, select}
([email protected])6> erlog:select(Pid, ";").
false

#### Custom database server:
Erlog now supports using your own database, instead of using ets and dicts. Just implement `erlog_storage` callback interface
and pass your module name with your implementation to `erlog:start_link/1` as __database__ to configuration list.
Example:

ConfList = [{database, mysql_storage_impl_module}],
erlog:start_link(ConfList).
You can pass your parameters to your database implementation:

ConfList = [{database, dbModule}, {arguments, Params}],
erlog:start_link(ConfList).
Where `Params` is a list of your args, need to be passed to `dbModule:new/1` function.

#### Consulting files
To consult files use brakes and filename with path `["/home/prolog_user/prolog_code/examples/family.pl"]`.
Erlog also supports calling `consult/1` and `reconsult/1` from prolog code:

erlog:execute(Pid, "consult(\"/home/prolog_user/prolog_code/examples/family.pl\").").
__Remember!__ For proper consulting files with default consulter, files should end with empty line!

#### Custom file consulter:
File consulter is a module, used to operate with files. It's behaviour is described in `erlog_file_consulter`. It should
implement two functions: `lookup` and `load`. Lookup returns list of all prolog libraries from selected directory and load
reads selected file and parse it to prolog terms.
Default implementation use files and directories for libraries search and loading. If you implement your own file consulter,
f.e. if you use database filesystem or smth else - implement `erlog_file_consulter` behaviour in your module and pass its
name in erlog configuration as __f_consulter__:

ConfList = [{f_consulter, my_hadoop_consulter}],
erlog:start_link(ConfList).

#### Custom debugger handler:
If you wan't to use functions from debug library - you should define your own gen_event handler and pass it to erlog.
All debug events from such debug functions as `writeln/1` will be passed there.
See `erlog_simple_printer` as a default implementation of console printer as an example, or `erlog_remote_eh`, which is
intended to print debug to remote client.
To configure your gen_event module - just pass module and arguments as __event_h__ in configuration:

ConfList = [{event_h, {my_event_handler, Args}}],
erlog:start_link(ConfList).

#### Working with libraries:
Erlog supports two kinds of libraries: native (written in Erlang) and extended (written in Prolog). Native libraries can
be standard and external.
All predicates from standard libraries are loaded to memory when you start erlog core.
All prolog libraries from `lib/autoload` are also loaded to memory when you start erlog core.
##### Manual loading external libraries
But to use predicates from external functions - you should manually load them to memory with the help of `use/1` command:

| ?- db_assert(test,foo(a,b)).
false
| ?- use(erlog_db).
true
| ?- db_assert(test,foo(a,b)).
true
This example demonstrates the loading of external database library.
First call is false, because there is no such function loaded to memory.
Second - library is loaded.
Third - function run successfully.
__Important!__ If you are working with erlog from poolboy or dynamic creating erlog gen_servers through supervisor,
remember, that two execution requests can be processed on different erlog instance.

use(some_lib). %returns true
some_lib_fun(some_val). %returns false
In this example system erlog gen server is created one per one separate command (F.e. http request). Firstly - library
`some_lib` is loaded. Than erlog server with loaded library is destroyed (as request is complete) and for another request
`some_lib_fun(some_val)` another erlog server is created, but, without loaded library.
##### Automatic libraries loading
For convenient libraries usage you can load all libraries you need when creating a core. It will let you not to call `use/1`
everywhere in your code. Just add param `{libraries, [my_first_lib, my second_lib]}` in your params when starting a core:

ConfList = [{libraries, [Lib1, Lib2]}],
erlog:start_link(ConfList).
All libraries from array will be loaded.
More in [docs](https://github.com/comtihon/erlog/blob/master/doc/libraries.md "libraries").
##### Loading Prolog libraries
When configuring erlog you should set default library directory as __libs_dir__:

ConfList = [{libs_dir, "/usr/share/prolog/lib/"}],
erlog:start_link(ConfList).
If you don't set this - erlog will use `../lib` directory, assuming it was run from `ebin`.
For manual loading prolog library - also try `use`, but instead of __atom__ name call it with __string__ library name:

use(erlog_cache). %use extended native library
use("proc/cuda/driver.pl"). %use prolog library, from /usr/share/prolog/lib/proc/cuda/
__Important!__ To avoid `erlog_parse,{operator_expected,'.'}` error - sure, that last character in your prolog file is `\n`.
107 changes: 107 additions & 0 deletions doc/debugger.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
### Using debugger
Debugger is started in `listing` mode by default. Listing just log every goal call and memory after previous call. For
more efficient usage - stop points can be added.

#### Stopping with counter
To stop commands execution after N executed commands - configure debugger with `next N`, where N is a positive integer.
When N goals is skipped - you will be asked again. You can configure the action by hitting C, or skipping next N goals
by pressing `enter`.
Example:

1> {ok, Pid} = erlog_simple_debugger:start_link().
{ok,<0.34.0>}
2> erlog_simple_debugger:configure(Pid).
Select action
| ?- next 5
ok
3> erlog_local_shell:start(Pid).
Erlog Shell V6.1 with debugger (abort with ^G)ert(foo(a,b)), foo(a,b), writeln("world").
Skip {call,{',',{assert,{foo,a,c}},
| ?- assert(foo(a,c)), writeln("hello"), retract(foo(a,c)), ass
{',',{writeln,"hello"},
{',',{retract,{foo,a,c}},
{',',{assert,{foo,a,b}},
{',',{foo,a,b},{writeln,"world"}}}}}}}
Skip {assert,{foo,a,c}}
Skip {writeln,"hello"}
Skip {retract,{foo,a,c}}
Erlog debugger stopped execution on command {assert,{foo,a,b}} with memory: [].
[C_]:C
Select action

#### Stopping with goal
To stop commands execution after special command (breakpoint) - configure debugger with `stop G`, where G is a goal. Goal
can be set direct - with params, f.e. `foo(a,b)` - it will react only on this goal, or indirect - by arity `foo/2` - it
will react on every foo with arity 2. When such goal will be executed - debugger will stop code execution and ask you for
next configuration. If you want to skip all code up to an end - just use `listing`.
Example:

1> {ok, Pid} = erlog_simple_debugger:start_link().
{ok,<0.34.0>}
2> erlog_simple_debugger:configure(Pid).
Select action
| ?- stop assert(foo(a,b))
ok
3> erlog_local_shell:start(Pid).
Erlog Shell V6.1 with debugger (abort with ^G)
| ?- assert(foo(a,c)), writeln("hello"), retract(foo(a,c)), assert(foo(a,b)), foo(a,b), writeln("world").
Skip {call,{',',{assert,{foo,a,c}},
{',',{writeln,"hello"},
{',',{retract,{foo,a,c}},
{',',{assert,{foo,a,b}},
{',',{foo,a,b},{writeln,"world"}}}}}}}
Skip {assert,{foo,a,c}}
Skip {writeln,"hello"}
Skip {retract,{foo,a,c}}
Erlog debugger stopped execution on command {assert,{foo,a,b}} with memory: [].
Select action

#### Spying for goals
To debug only for selected goal - use `spy G`, where G is a goal. Goal can be set by arity or direct, same as in stop
section. When goal matches - debugger will print execution, otherwise it will be silent.

1> {ok, Pid} = erlog_simple_debugger:start_link().
{ok,<0.34.0>}
2> erlog_simple_debugger:configure(Pid).
Select action
| ?- spy foo/2
ok
3> erlog_local_shell:start(Pid).
Erlog Shell V6.1 with debugger (abort with ^G)
| ?- assert(foo(a,b)), assert(foo(a,c)), foo(a,b), assert(foo(a,c)), foo(a,c), assert(foo(a,d)),foo(a,d), assert(foo(a,b)).
Execute {foo,a,b}, memory: []
true

#### Stopping with breakpoint
To stop execution somewhere in your code before specific functor - place breakpoint on this line. To place breakpoint in
code use `'??'` special functor.
Example code with one breakpoint:

test:-
writeln("before breakpoint"),
'??'(writeln("stop me")),
writeln("after breakpoint").
Output:

1> {ok, Pid} = erlog_simple_debugger:start_link().
{ok,<0.34.0>}
2> erlog_local_shell:start(Pid).
Erlog Shell V6.1 with debugger (abort with ^G)
| ?- consult('/home/prolog/test_debug.pl').
Execute {call,{consult,'/home/prolog/test_debug.pl'}}, memory: []
Execute {consult,'/home/prolog/test_debug.pl'}, memory: []
true
| ?- test.
Execute {call,test}, memory: []
Execute test, memory: []
Execute {writeln,"before breakpoint"}, memory: []
erlog_simple_printer: "before breakpoint"
Execute {'??',{writeln,"stop me"}, memory: []
Erlog debugger stopped execution on command {writeln,"stop me"} with memory: [].
Select action
| ?- listing
erlog_simple_printer: "stop me"
Execute {writeln,"after breakpoint"}, memory: []
erlog_simple_printer: "after breakpoint"
true

93 changes: 0 additions & 93 deletions doc/erlog.txt

This file was deleted.

Loading