Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
tutorials:intermediate:json_prolog [2019/04/24 11:46] gkazhoyatutorials:intermediate:json_prolog [2020/06/11 11:51] – [Prerequisites] Added the link to the source of the Episode Data. hawkin
Line 9: Line 9:
 This tutorial requires CRAM, roslisp_repl and ROS to have already been installed. Go through the previous tutorials and the installation page if you don't have CRAM installed yet. This tutorial requires CRAM, roslisp_repl and ROS to have already been installed. Go through the previous tutorials and the installation page if you don't have CRAM installed yet.
 Make sure you have **Java 8** and **Gradle 5.1** already installed. Otherwise you won't be able to build KnowRob. Other versions could work, but have not been tested yet, so use them at your own risk!  Make sure you have **Java 8** and **Gradle 5.1** already installed. Otherwise you won't be able to build KnowRob. Other versions could work, but have not been tested yet, so use them at your own risk! 
 +
 +Please also download the **episode data** provided at this [[https://seafile.zfn.uni-bremen.de/d/ba524dbadfa748488d4d/|source]]. The download can take about 10 minutes, depending on your internet connection. Unzip the archive and put the **episodes** directory next to your work space. It is it's own workspace, and is ment to be layered under your working workspace. To learn more about workspace layering and on how to set it up, please refer to this [[http://wiki.ros.org/catkin/Tutorials/workspace_overlaying|tutorial]]. 
  
  
Line 210: Line 212:
 ==== Case-sensitive variable names ==== ==== Case-sensitive variable names ====
  
-In the former query we got a weird result from Prolog which looked like this: ''|''helloworld''|''.+In the former query we got a weird result from Prolog which looked like this:  
 +<code lisp> 
 +|''helloworld''| 
 +</code> 
 +What do the pipes stand for in this case?
  
 +Lisp is case-insensitive, that means that variable of function names, or more correctly said, any symbol, can be written in any capitalization and will refer to the same symbol:
  
 +<code lisp>
 +CL-USER> (eq 'hello 'HELLO)
 +T
 +CL-USER> (eq 'hello 'Hello)
 +T
 +</code>
 +
 +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")
 +HELLO
 +:INTERNAL
 +CL-USER> (intern "Hello")
 +|Hello|
 +NIL
 +</code>
 +The function ''intern'' creates a symbol from a string.
 +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:prolog-simple-1 "member(X, [1,2,3])")
 +(((?X . 1)))
 +CL-USER> (json-prolog:prolog-simple-1 "member(MYVAR, [1,2,3])")
 +(((?MYVAR . 1)))
 +CL-USER> (json-prolog:prolog-simple-1 "member(MY_VAR, [1,2,3])")
 +(((?MY_VAR . 1)))
 +CL-USER> (json-prolog:prolog-simple-1 "member(My_var, [1,2,3])")
 +(((|?My_var| . 1)))
 +</code>
 +
 +In that case, to get the value of the variable you should also use pipes:
 +
 +<code lisp>
 +CL-USER> (cut:var-value '|?My_var|
 +                        (car (json-prolog:prolog-simple-1 "member(My_var, [1,2,3])")))
 +1
 +</code>
 +
 +Please note that in Prolog, all variables have to start with a capital letter and cannot contain dashes:
 +<code lisp>
 +CL-USER> (json-prolog:prolog-simple-1 "member(x, [1,2,3])")
 +NIL
 +CL-USER> (json-prolog:prolog-simple-1 "member(MY-VAR, [1,2,3])")
 +NIL
 +</code>
 ==== (NIL) vs NIL ==== ==== (NIL) vs NIL ====