Skip to content

Commit

Permalink
Improve Logtalk tutorial notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
pmoura committed Dec 4, 2022
1 parent 69b7a75 commit dbcb8ae
Showing 1 changed file with 39 additions and 47 deletions.
86 changes: 39 additions & 47 deletions notebooks/LogtalkTutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"source": [
"# Logtalk tutorial\n",
"\n",
"Logtalk is an object-oriented logic programming language that extends and leverages Prolog with modern code encapsulation and code reuse mechanisms without compromising its declarative programming features. Logtalk is implemented in highly portable code and can use most modern and standards compliant Prolog implementations as a back-end compiler.\n",
"Logtalk is an *object-oriented logic programming language* that extends and leverages Prolog with modern code encapsulation and code reuse mechanisms without compromising its declarative programming features. Logtalk is implemented in highly portable code and can use most modern and standards compliant Prolog implementations as a back-end compiler.\n",
"\n",
"To keep its size reasonable, this tutorial necessarily assumes that the reader have a working knowledge of Prolog and is biased towards describing Logtalk object-oriented features.\n",
"\n",
Expand Down Expand Up @@ -219,6 +219,14 @@
":- end_object."
]
},
{
"cell_type": "markdown",
"id": "23f30929",
"metadata": {},
"source": [
"Sending a message for a declared predicate that is out of scope results in a permission error:"
]
},
{
"cell_type": "code",
"execution_count": 6,
Expand All @@ -243,6 +251,14 @@
"catch(scopes::bar, Error, true)."
]
},
{
"cell_type": "markdown",
"id": "b8c7cfeb",
"metadata": {},
"source": [
"Sending a message for a defined but not non-declared predicate results in a existence error:"
]
},
{
"cell_type": "code",
"execution_count": 7,
Expand Down Expand Up @@ -404,7 +420,7 @@
"@file stack.lgt\n",
"\n",
":- object(stack,\n",
"\timplements(private::listp)).\n",
"\timplements(private::lists_protocol)).\n",
"\n",
":- end_object."
]
Expand All @@ -418,7 +434,7 @@
"\n",
"## Prototypes\n",
"\n",
"An object without an _instantiation_ or _specialization_ relation with another object plays the role of a prototype. A prototype can _extend_ another object, its parent prototype."
"An object without an _instantiation_ or _specialization_ relation with another object plays the role of a prototype."
]
},
{
Expand Down Expand Up @@ -466,6 +482,14 @@
":- end_object."
]
},
{
"cell_type": "markdown",
"id": "9ee4d54e",
"metadata": {},
"source": [
" A prototype can also _extend_ another object, its parent prototype."
]
},
{
"cell_type": "code",
"execution_count": 12,
Expand Down Expand Up @@ -1047,7 +1071,6 @@
"\n",
":- set_logtalk_flag(complements, allow).\n",
"\n",
"\n",
":- object(buggy).\n",
"\n",
"\t:- public(p/0).\n",
Expand Down Expand Up @@ -1408,7 +1431,8 @@
"@file tracer.lgt\n",
"\n",
":- object(tracer,\n",
"\timplements(monitoring)). % built-in protocol for event handlers\n",
"\t% built-in protocol for event handlers\n",
"\timplements(monitoring)).\n",
"\n",
"\t:- initialization(define_events(_, list, _, _, tracer)).\n",
"\n",
Expand Down Expand Up @@ -1488,10 +1512,10 @@
{
"data": {
"text/plain": [
"call: list <-- member(_15194,[1,2,3]) from jupyter_term_handling\n",
"exit: list <-- member(1,[1,2,3]) from jupyter_term_handling\n",
"exit: list <-- member(2,[1,2,3]) from jupyter_term_handling\n",
"exit: list <-- member(3,[1,2,3]) from jupyter_term_handling"
"call: list <-- member(_15110,[1,2,3]) from user\n",
"exit: list <-- member(1,[1,2,3]) from user\n",
"exit: list <-- member(2,[1,2,3]) from user\n",
"exit: list <-- member(3,[1,2,3]) from user"
]
},
"metadata": {},
Expand Down Expand Up @@ -1694,10 +1718,12 @@
"@file my_macros.lgt\n",
"\n",
":- object(my_macros,\n",
"\timplements(expanding)). % built-in protocol for expanding predicates\n",
"\t% built-in protocol for expanding predicates\n",
"\timplements(expanding)).\n",
"\n",
"\tterm_expansion(foo(Char), baz(Code)) :-\n",
"\t\tchar_code(Char, Code). % standard built-in predicate\n",
"\t\t% standard built-in predicate\n",
"\t\tchar_code(Char, Code).\n",
"\n",
"\tgoal_expansion(foo(X), baz(X)).\n",
"\n",
Expand Down Expand Up @@ -1745,6 +1771,8 @@
"source": [
"@file source.lgt\n",
"\n",
":- set_logtalk_flag(hook, my_macros).\n",
"\n",
":- object(source).\n",
"\n",
"\t:- public(bar/1).\n",
Expand All @@ -1758,42 +1786,6 @@
{
"cell_type": "code",
"execution_count": 42,
"id": "c6db4e4d",
"metadata": {
"vscode": {
"languageId": "logtalk"
}
},
"outputs": [
{
"data": {
"text/plain": [
"% [ /Users/pmoura/Documents/Logtalk/logtalk-jupyter-kernel/notebooks/source.lgt compiled ]\n",
"% Redefining object source\n",
"% [ /Users/pmoura/Documents/Logtalk/logtalk-jupyter-kernel/notebooks/source.lgt reloaded ]\n",
"% (0 warnings)"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"\u001b[1mtrue"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"logtalk_load(source, [hook(my_macros)])."
]
},
{
"cell_type": "code",
"execution_count": 43,
"id": "96a9efe2",
"metadata": {
"vscode": {
Expand Down

0 comments on commit dbcb8ae

Please sign in to comment.