Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
tutorials:intermediate:json_prolog [2019/04/24 11:23] – [prolog-simple-1] gkazhoya | tutorials:intermediate:json_prolog [2019/04/24 11:43] – [Some more information about Prolog in LISP] gkazhoya | ||
---|---|---|---|
Line 83: | Line 83: | ||
</ | </ | ||
is a list of bindings for variable ''? | is a list of bindings for variable ''? | ||
+ | |||
The last outer bracket is explained next. | The last outer bracket is explained next. | ||
Line 95: | Line 96: | ||
</ | </ | ||
| | ||
- | The result is basically still the same, but it looks a little bit more complex on the first glance. What we get is a list which contains two elements. The first one is a list in a list with two elements which we already know from the previous call with '' | + | The result is basically still the same, but it looks a little bit more complex on the first glance. What we get is a list which contains two elements. The first one is a list in a list with two elements which we already know from the previous call with '' |
{1005F52FAB}> | {1005F52FAB}> | ||
==== lazy lists ==== | ==== lazy lists ==== | ||
Line 113: | Line 114: | ||
We save our list in a variable for convenience purposes. This allows us also to expand the so stored list, and we can see all the possible values Prolog found for the variable ''? | We save our list in a variable for convenience purposes. This allows us also to expand the so stored list, and we can see all the possible values Prolog found for the variable ''? | ||
- | If we do the same with '' | + | Now we see why we need the outer bracket: the result of the query is a (lazy) list of all possible bindings for the query variables. Let us add another variable to the query again: |
<code lisp> | <code lisp> | ||
- | | + | CL-USER> (cut:force-ll (json-prolog: |
- | (((?X . 1))) | + | (((?X . 1) (?Y . 1)) ((?X . 2) (?Y . 2)) ((?X . 3) (?Y . 3))) |
- | CL-USER> (cut: | + | </ |
- | (((?X . 1))) | + | We get a list of all possible bindings of the query variables, where the bindings is itself a list with one element for each variable. |
+ | |||
+ | If we evaluate our original '' | ||
+ | <code lisp> | ||
+ | CL-USER> (cut: | ||
+ | (((?X . 1)) ((?X . 2)) ((?X . 3))) | ||
+ | CL-USER> (cut: | ||
+ | (((?X . 1))) | ||
</ | </ | ||
Line 130: | Line 139: | ||
Now that we have a lazy list with interesting information, | Now that we have a lazy list with interesting information, | ||
| | ||
- | We can use '' | + | We can use '' |
- | <code lisp> | + | |
- | CL-USER> (setq *our-list* | + | |
- | | + | |
- | (json-prolog: | + | |
- | </ | + | |
- | + | ||
- | This gives us a (normal) list of bindings for the variables in the query. We only have one variable ''? | + | |
<code lisp> | <code lisp> | ||
+ | CL-USER> (cut: | ||
((?X . 1)) | ((?X . 1)) | ||
</ | </ | ||
- | Now we can use '' | + | Same goes for '' |
+ | <code lisp> | ||
+ | CL-USER> (cut: | ||
+ | (((?X . 2)) | ||
+ | . # | ||
+ | :GENERATOR #< | ||
+ | | ||
+ | </ | ||
+ | |||
+ | When we have one element of the lazy list, we can use '' | ||
<code lisp> | <code lisp> | ||
- | | + | CL-USER> (cut: |
- | | + | 1 |
</ | </ | ||
- | Gives us the result '' | + | Gives us the result '' |
That way, one can extract the necessary information, | That way, one can extract the necessary information, | ||
Line 160: | Line 172: | ||
<code lisp> | <code lisp> | ||
- | |||
CL-USER> (json-prolog: | CL-USER> (json-prolog: | ||
- | (NIL | + | (NIL) |
- | . # | + | |
- | : | + | |
- | {1006444B3B}> | + | |
- | | + | |
</ | </ | ||
+ | |||
+ | In JSON Prolog '' | ||
| | ||
- | This allows us to use the **knowrob_common** package, which allows us to access many utility functions and also the most commonly used queries of KnowRob. | + | This allows us to use the '' |
With this imported package we could now do the following: | With this imported package we could now do the following: | ||
<code lisp> | <code lisp> | ||
- | + | | |
- | | + | (((?RESULT |
- | (((|?Result| | + | |
. # | . # | ||
:GENERATOR #< | :GENERATOR #< | ||
Line 182: | Line 190: | ||
</ | </ | ||
- | This query converts the first elements upper case letters into lower case, and stores the obtained result in the '' | + | This query converts the first elements upper case letters into lower case, and stores the obtained result in the '' |
- | An overview of the currently available packages and their queries can be found [[http:// | + | An overview of the currently available packages and their queries can be found [[http:// |
<code bash> | <code bash> | ||
| | ||
Line 193: | Line 201: | ||
| | ||
<code lisp> | <code lisp> | ||
- | |||
Prolog query failed: PrologException: | Prolog query failed: PrologException: | ||
[Condition of type SIMPLE-ERROR] | [Condition of type SIMPLE-ERROR] | ||
- | | ||
</ | </ | ||
| | ||
- | and if you check your terminal, in which the **json_prolog** node is running, there will be a huge java print as well, basically explaining the same thing. | + | and if you check your terminal, in which the '' |
| | ||
| | ||
- | ==== Some more information about Prolog in LISP ==== | + | ==== (NIL) vs NIL ==== |
| | ||
If we want to check, if a certain number is member of the list, we must declare the variable accordingly. e.g. | If we want to check, if a certain number is member of the list, we must declare the variable accordingly. e.g. |