From c08ca5b9c94abb576b56c00206315f3074b9b89d Mon Sep 17 00:00:00 2001 From: Paulo Moura Date: Tue, 18 Oct 2016 16:15:43 +0100 Subject: [PATCH] Fixes and improvements to the Logtalk tutorial (#2470) --- logtalk.html.markdown | 77 ++++++++++++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 27 deletions(-) diff --git a/logtalk.html.markdown b/logtalk.html.markdown index 4f7a207b..385e38f9 100644 --- a/logtalk.html.markdown +++ b/logtalk.html.markdown @@ -13,14 +13,12 @@ To keep its size reasonable, this tutorial necessarily assumes that the reader h Logtalk uses standard Prolog syntax with the addition of a few operators and directives for a smooth learning curve and wide portability. One important consequence is that Prolog code can be easily encapsulated in objects with little or no changes. Moreover, Logtalk can transparently interpret most Prolog modules as Logtalk objects. -Some of the most important operators are: +The main operators are: * `::/2` - sending a message to an object * `::/1` - sending a message to _self_ (i.e. to the object that received the message being processed) * `^^/1` - _super_ call (of an inherited or imported predicate) -* `<>)/2` infix operator connecting them to the lambda. Some simple examples using library meta-predicates: @@ -470,6 +492,7 @@ Ys = [2,4,6] yes ``` +Lambda free variables can be expressed using the extended syntax `{Free1, ...}/[Parameter1, ...]>>Lambda`. # Macros @@ -486,21 +509,21 @@ Terms and goals in source files can be _expanded_ at compile time by specifying :- end_object. ``` -Let's define an hook object, saved in a `my_macros.lgt` file, that changes clauses and calls to the `foo/1` local predicate: +Assume the following hook object, saved in a `my_macros.lgt` file, that expands clauses and calls to the `foo/1` local predicate: ``` :- object(my_macros, - implements(expanding)). % built-in protocol for expanding predicates + implements(expanding)). % built-in protocol for expanding predicates term_expansion(foo(Char), baz(Code)) :- - char_code(Char, Code). % standard built-in predicate + char_code(Char, Code). % standard built-in predicate goal_expansion(foo(X), baz(X)). :- end_object. ``` -After loading the macros file, we can then expand our source file with it: +After loading the macros file, we can then expand our source file with it using the `hook` compiler flag: ``` ?- logtalk_load(my_macros), logtalk_load(source, [hook(my_macros)]).