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:35] – [Accessing data from Prolog] gkazhoya | tutorials:intermediate:json_prolog [2019/04/24 11:54] – [Case-sensitive variable names] gkazhoya | ||
---|---|---|---|
Line 172: | 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 194: | 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 205: | 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 ==== | + | ==== Case-sensitive variable names ==== |
+ | |||
+ | In the former query we got a weird result from Prolog which looked like this: | ||
+ | <code lisp> | ||
+ | |'' | ||
+ | </ | ||
+ | What do the pipes stand for in this case? | ||
+ | |||
+ | Lisp is case-insensitive, | ||
+ | |||
+ | <code lisp> | ||
+ | CL-USER> (eq 'hello ' | ||
+ | T | ||
+ | CL-USER> (eq 'hello ' | ||
+ | T | ||
+ | </ | ||
+ | |||
+ | Prolog, on the other hand, is case-sensitive. | ||
+ | And in some cases, one would like to have a case-sensitive variable in Lisp as well. | ||
+ | This is where the pipes come into play: | ||
+ | <code lisp> | ||
+ | CL-USER> (intern " | ||
+ | HELLO | ||
+ | :INTERNAL | ||
+ | CL-USER> (intern " | ||
+ | |Hello| | ||
+ | NIL | ||
+ | </ | ||
+ | The function '' | ||
+ | If the string is all capital, we get a normal usual symbol, in the other case we get the pipes. | ||
+ | |||
+ | The same is with Prolog, if your variable or any other symbol is not all caps, you will get a symbol in Lisp which has pipes around it: | ||
+ | |||
+ | <code lisp> | ||
+ | CL-USER> (json-prolog: | ||
+ | (((?X . 1))) | ||
+ | CL-USER> (json-prolog: | ||
+ | (((?MYVAR . 1))) | ||
+ | CL-USER> (json-prolog: | ||
+ | (((?MY_VAR . 1))) | ||
+ | CL-USER> (json-prolog: | ||
+ | (((|? | ||
+ | </ | ||
+ | |||
+ | In that case, to get the value of the variable you should also use pipes: | ||
+ | |||
+ | <code lisp> | ||
+ | CL-USER> (cut: | ||
+ | (car (json-prolog: | ||
+ | 1 | ||
+ | </ | ||
+ | |||
+ | Please note that in Prolog, all variables have to start with a capital letter and cannot contain dashes: | ||
+ | <code lisp> | ||
+ | CL-USER> (json-prolog: | ||
+ | NIL | ||
+ | CL-USER> (json-prolog: | ||
+ | NIL | ||
+ | </ | ||
+ | ==== (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. |