Snippets

Sebastian Sardina FAQ for using SARL + SWI/JPL Prolog + Maven

Updated by Sebastian Sardina

File SARL-FAQ Deleted

  • Ignore whitespace
  • Hide word diff
-# FAQ for using SARL + SWI Prolog
-
-This is a collection of questions/issues that arose from my teaching of Agent Oriented Programming, where I have assessments in [SARL](http://www.sarl.io/) and [SWI Prolog](http://www.swi-prolog.org/), all packaged with [Apache Maven](https://maven.apache.org/).
-
-[TOC]
-
-
-## ECLIPSE
-
-## SWI-PROLOG
-
-# MAVEN
-
-## SARL
-
-### SARL is similar to Java but has different syntax in many places, how come?
-
-Because it uses and builts on [XTEND](https://www.eclipse.org/xtend/documentation/203_xtend_expressions.html) framework.
-
-### Seems my SARL application cannot find JPL!
-
-There could be many reasons and it may depend on the OS you are using. 
-
-First of all, _do you have the **JPL package installed** in the system?_
-
-* In **Windows**, it is easy as you can click to install JPL Java<-->SWI interface at installation time. 
-    * You should get jpl.dll file in `%SWI_HOME_DIR%/bin` and `jpl.jar` in `%SWI_HOME_DIR%/lib`.
-* In **Linux**, you need to make sure `libjpl.so` and `jpl.jar` are somewhere! If you cannot find it, then you may need to install JPL. 
-    * In Ubuntu, it is provided with package `swi-prolog-java`. 
-    * In ARCH,  you can generate it and install it using AUR package builder and `swi-prolog-git` package. Running the default PKG build file is enough to get JPL installed.
-    * In MAC, we don't know how to make it work, as there is a glitch in one of the packages built for Mac... :-( [if you make it work, please let me know!]
-
-Once JPL is in your system, you need to make the **system is aware** of it!
-
-* In **Windows**, make sure:
-    * A system variable `SWI_HOME_DIR` points to the root of SWI install.
-    * System variable `Path` includes `%SWI_HOME_DIR%\bin` and `%SWI_HOME_DIR%\lib\jpl.jar`.
-* In **Linux**, make sure:
-    * `export LD_PRELOAD=libswipl.so:$LD_PRELOAD`
-    * `export LD_LIBRARY_PATH=/usr/lib/swi-prolog/lib/amd64/` (or wherever `libjpl.so` is located)
-
-With this, your SARL application should be able to recognize where JPL is (hopefully!) :-)
-
-You may also refer to the instructions of the [SARL Prolog Capacity](https://bitbucket.org/ssardina-research/sarl-prolog-cap)
-
-### Strange error in CLI when using occurence on left hand side of assignments
-Consider this code:
-
-    on CarArrivedPercept {
-        cars.get(occurrence.car).floor = occurrence.floor
-    }
-
-We know that `occurrence` is static, so cannot be changed. However, in the above code, `occurrence.car`, is not being changed/assigned, but just used to refer to another entity where assignment is performed. 
-However, SARL compiler will think that you are changing static element `occurrence` and complain with error. Instead do this:
-
-    on CarArrivedPercept {
-        val n = occurrence.car
-		cars.get(n).floor = occurrence.floor
-	}
-
-### Can we document SARL code for JAVADOC?
-
-Presumably yes, but I was not yet successful (have not tried much though!). Check this post: <https://groups.google.com/forum/#!topic/sarl/E_mhpFWyBFo>
-
-### How do I control the log-level of the Logging built-in capacity?
-
-Use `setLogLevel()` as explained here: <http://www.sarl.io/docs/official/reference/bic/Logging.html>
-
-There used to be a bug in that `debug()` was passed to the system logging which if it was at level `INFO` it would not display it. 
-It should now be fixed; see this post:  <https://github.com/sarl/sarl/issues/803> 
-
-
-### How can we know when an agent has been created fully after being spawn?
-
-An event `AgentSpawned` will be emitted when an agent has been created and can be handled, say by a coordinator, to know the agent is now alive! Fo example:
-
-	on AgentSpawned {
-		info("Agent {0} of type {1} has been created successfully and is now alive!",
-			occurrence.agentIdentifiers, occurrence.agentType)
-	}
-
-
-### Equality and identity comparison in SARL and checking for null: same as Java ?
-
-SARL' s developer states that the mapping of the operator from SARL to Java are:
-
-* `a === b` becomes `a == b`
-* `a !== b" becomes `a != b`
-* `a == b` becomes `a == null ? (b == null) : a.equals(b)`
-* `a != b` becomes `!Objects.equals(a,b)`. This is null-safe (part of Google API) and the code of the function is `a == b || (a != null && a.equals(b))`
-
-It is always better to test valid against null with the `===` or `!==` operators. These operators are not replaced neither `operator_equals` nor `operator_notEquals` within the Java code.
-
-I believe this is because SARL comparison operators follow the  which means that:
-
-* In Xtend the equals operators (`==`, `!=`) are bound to `Object.equals`. 
-* Java’s identity equals semantic is mapped to the tripple-equals operators `===` and `!==` in Xtend.
-
-Check xtend doc [here](https://www.eclipse.org/xtend/documentation/203_xtend_expressions.html#operators) for more details and SARL doc [here](http://www.sarl.io/docs/official/reference/general/Operators.html#3-comparison-operators).
-
-_**Note from SARL developer**_: SARL extends a part of [Xtend dialect](https://www.eclipse.org/xtend/index.html) in order to have benefits of several background features, such as the validation tests for type inheritance. Since Xtend and SARL uses [Xbase](https://www.eclipse.org/Xtext/documentation/305_xbase.html#xbase-expressions), a large part of the syntax is the same, especially within the blocks of code. (The rest of the syntax is defined in parallel. SARL was inspired by languages such as Scala, Python and Ruby. Several bugs or incoherencies of Xtend are fixed in SARL.
-
-There is still a bit of an issue inside the Xbase library; check this <https://github.com/sarl/sarl/issues/852#issuecomment-420842088>
-
-
-### How to return two values? Pairs in SARL
-
-Java comes with a `Pair<A,B>` class to build an object for storing two values, nicknamed "key" and "value", but they have no meaning as key/value. It comes useful when a method has to return two values instead of just one. For example, the following function returns the next floor and direction that an elevator has to serve:
-
-	def kb_getNextJob() : Pair<Integer, Direction> {
-        ...........
-        }
-
-As of Java 8, and as part of JavaFX, Java provides this `Pair<A,B>` class; check [here](https://www.geeksforgeeks.org/pair-class-in-java/) and [here](https://docs.oracle.com/javase/8/javafx/api/javafx/util/Pair.html). 
-Note `Pairs` are different from `Map`, which can be seen as a collection of `Pairs` and with a proper key/value semantics.
-
-There exist more advanced implementations of `Pair`, for example from Apache. See [here](https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/tuple/package-summary.html), [here](https://www.baeldung.com/java-pairs) and [here](https://gangmax.me/blog/2017/10/10/how-to-return-multiple-values-from-a-java-method/).
-
-
-SARL itself have compact syntax do deal with `Pair`, by using `a -> b` to create a `Pair` object `(a,b)`. There are also compact ways of manipulating `Collection` and `Maps`. 
-
-Check SARL documentation on that [here](http://www.sarl.io/docs/official/reference/general/Operators.html#8-collection-operators).
-

File SARL-FAQ.markdown Added

  • Ignore whitespace
  • Hide word diff
+# FAQ for using SARL + SWI Prolog
+
+This is a collection of questions/issues that arose from my teaching of Agent Oriented Programming, where I have assessments in [SARL](http://www.sarl.io/) and [SWI Prolog](http://www.swi-prolog.org/), all packaged with [Apache Maven](https://maven.apache.org/).
+
+[TOC]
+
+
+## ECLIPSE
+
+## SWI-PROLOG
+
+# MAVEN
+
+## SARL
+
+### SARL is similar to Java but has different syntax in many places, how come?
+
+Because it uses and builts on [XTEND](https://www.eclipse.org/xtend/documentation/203_xtend_expressions.html) framework.
+
+### Seems my SARL application cannot find JPL!
+
+There could be many reasons and it may depend on the OS you are using. 
+
+First of all, _do you have the **JPL package installed** in the system?_
+
+* In **Windows**, it is easy as you can click to install JPL Java<-->SWI interface at installation time. 
+    * You should get jpl.dll file in `%SWI_HOME_DIR%/bin` and `jpl.jar` in `%SWI_HOME_DIR%/lib`.
+* In **Linux**, you need to make sure `libjpl.so` and `jpl.jar` are somewhere! If you cannot find it, then you may need to install JPL. 
+    * In Ubuntu, it is provided with package `swi-prolog-java`. 
+    * In ARCH,  you can generate it and install it using AUR package builder and `swi-prolog-git` package. Running the default PKG build file is enough to get JPL installed.
+    * In MAC, we don't know how to make it work, as there is a glitch in one of the packages built for Mac... :-( [if you make it work, please let me know!]
+
+Once JPL is in your system, you need to make the **system is aware** of it!
+
+* In **Windows**, make sure:
+    * A system variable `SWI_HOME_DIR` points to the root of SWI install.
+    * System variable `Path` includes `%SWI_HOME_DIR%\bin` and `%SWI_HOME_DIR%\lib\jpl.jar`.
+* In **Linux**, make sure:
+    * `export LD_PRELOAD=libswipl.so:$LD_PRELOAD`
+    * `export LD_LIBRARY_PATH=/usr/lib/swi-prolog/lib/amd64/` (or wherever `libjpl.so` is located)
+
+With this, your SARL application should be able to recognize where JPL is (hopefully!) :-)
+
+You may also refer to the instructions of the [SARL Prolog Capacity](https://bitbucket.org/ssardina-research/sarl-prolog-cap)
+
+### Strange error in CLI when using occurence on left hand side of assignments
+Consider this code:
+
+    on CarArrivedPercept {
+        cars.get(occurrence.car).floor = occurrence.floor
+    }
+
+We know that `occurrence` is static, so cannot be changed. However, in the above code, `occurrence.car`, is not being changed/assigned, but just used to refer to another entity where assignment is performed. 
+However, SARL compiler will think that you are changing static element `occurrence` and complain with error. Instead do this:
+
+    on CarArrivedPercept {
+        val n = occurrence.car
+		cars.get(n).floor = occurrence.floor
+	}
+
+### Can we document SARL code for JAVADOC?
+
+Presumably yes, but I was not yet successful (have not tried much though!). Check this post: <https://groups.google.com/forum/#!topic/sarl/E_mhpFWyBFo>
+
+### How do I control the log-level of the Logging built-in capacity?
+
+Use `setLogLevel()` as explained here: <http://www.sarl.io/docs/official/reference/bic/Logging.html>
+
+There used to be a bug in that `debug()` was passed to the system logging which if it was at level `INFO` it would not display it. 
+It should now be fixed; see this post:  <https://github.com/sarl/sarl/issues/803> 
+
+
+### How can we know when an agent has been created fully after being spawn?
+
+An event `AgentSpawned` will be emitted when an agent has been created and can be handled, say by a coordinator, to know the agent is now alive! Fo example:
+
+	on AgentSpawned {
+		info("Agent {0} of type {1} has been created successfully and is now alive!",
+			occurrence.agentIdentifiers, occurrence.agentType)
+	}
+
+
+### Equality and identity comparison in SARL and checking for null: same as Java ?
+
+SARL' s developer states that the mapping of the operator from SARL to Java are:
+
+* `a === b` becomes `a == b`
+* `a !== b" becomes `a != b`
+* `a == b` becomes `a == null ? (b == null) : a.equals(b)`
+* `a != b` becomes `!Objects.equals(a,b)`. This is null-safe (part of Google API) and the code of the function is `a == b || (a != null && a.equals(b))`
+
+It is always better to test valid against null with the `===` or `!==` operators. These operators are not replaced neither `operator_equals` nor `operator_notEquals` within the Java code.
+
+I believe this is because SARL comparison operators follow the  which means that:
+
+* In Xtend the equals operators (`==`, `!=`) are bound to `Object.equals`. 
+* Java’s identity equals semantic is mapped to the tripple-equals operators `===` and `!==` in Xtend.
+
+Check xtend doc [here](https://www.eclipse.org/xtend/documentation/203_xtend_expressions.html#operators) for more details and SARL doc [here](http://www.sarl.io/docs/official/reference/general/Operators.html#3-comparison-operators).
+
+_**Note from SARL developer**_: SARL extends a part of [Xtend dialect](https://www.eclipse.org/xtend/index.html) in order to have benefits of several background features, such as the validation tests for type inheritance. Since Xtend and SARL uses [Xbase](https://www.eclipse.org/Xtext/documentation/305_xbase.html#xbase-expressions), a large part of the syntax is the same, especially within the blocks of code. (The rest of the syntax is defined in parallel. SARL was inspired by languages such as Scala, Python and Ruby. Several bugs or incoherencies of Xtend are fixed in SARL.
+
+There is still a bit of an issue inside the Xbase library; check this <https://github.com/sarl/sarl/issues/852#issuecomment-420842088>
+
+
+### How to return two values? Pairs in SARL
+
+Java comes with a `Pair<A,B>` class to build an object for storing two values, nicknamed "key" and "value", but they have no meaning as key/value. It comes useful when a method has to return two values instead of just one. For example, the following function returns the next floor and direction that an elevator has to serve:
+
+	def kb_getNextJob() : Pair<Integer, Direction> {
+        ...........
+        }
+
+As of Java 8, and as part of JavaFX, Java provides this `Pair<A,B>` class; check [here](https://www.geeksforgeeks.org/pair-class-in-java/) and [here](https://docs.oracle.com/javase/8/javafx/api/javafx/util/Pair.html). 
+Note `Pairs` are different from `Map`, which can be seen as a collection of `Pairs` and with a proper key/value semantics.
+
+There exist more advanced implementations of `Pair`, for example from Apache. See [here](https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/tuple/package-summary.html), [here](https://www.baeldung.com/java-pairs) and [here](https://gangmax.me/blog/2017/10/10/how-to-return-multiple-values-from-a-java-method/).
+
+
+SARL itself have compact syntax do deal with `Pair`, by using `a -> b` to create a `Pair` object `(a,b)`. There are also compact ways of manipulating `Collection` and `Maps`. 
+
+Check SARL documentation on that [here](http://www.sarl.io/docs/official/reference/general/Operators.html#8-collection-operators).
+
Created by Sebastian Sardina

File SARL-FAQ Added

  • Ignore whitespace
  • Hide word diff
+# FAQ for using SARL + SWI Prolog
+
+This is a collection of questions/issues that arose from my teaching of Agent Oriented Programming, where I have assessments in [SARL](http://www.sarl.io/) and [SWI Prolog](http://www.swi-prolog.org/), all packaged with [Apache Maven](https://maven.apache.org/).
+
+[TOC]
+
+
+## ECLIPSE
+
+## SWI-PROLOG
+
+# MAVEN
+
+## SARL
+
+### SARL is similar to Java but has different syntax in many places, how come?
+
+Because it uses and builts on [XTEND](https://www.eclipse.org/xtend/documentation/203_xtend_expressions.html) framework.
+
+### Seems my SARL application cannot find JPL!
+
+There could be many reasons and it may depend on the OS you are using. 
+
+First of all, _do you have the **JPL package installed** in the system?_
+
+* In **Windows**, it is easy as you can click to install JPL Java<-->SWI interface at installation time. 
+    * You should get jpl.dll file in `%SWI_HOME_DIR%/bin` and `jpl.jar` in `%SWI_HOME_DIR%/lib`.
+* In **Linux**, you need to make sure `libjpl.so` and `jpl.jar` are somewhere! If you cannot find it, then you may need to install JPL. 
+    * In Ubuntu, it is provided with package `swi-prolog-java`. 
+    * In ARCH,  you can generate it and install it using AUR package builder and `swi-prolog-git` package. Running the default PKG build file is enough to get JPL installed.
+    * In MAC, we don't know how to make it work, as there is a glitch in one of the packages built for Mac... :-( [if you make it work, please let me know!]
+
+Once JPL is in your system, you need to make the **system is aware** of it!
+
+* In **Windows**, make sure:
+    * A system variable `SWI_HOME_DIR` points to the root of SWI install.
+    * System variable `Path` includes `%SWI_HOME_DIR%\bin` and `%SWI_HOME_DIR%\lib\jpl.jar`.
+* In **Linux**, make sure:
+    * `export LD_PRELOAD=libswipl.so:$LD_PRELOAD`
+    * `export LD_LIBRARY_PATH=/usr/lib/swi-prolog/lib/amd64/` (or wherever `libjpl.so` is located)
+
+With this, your SARL application should be able to recognize where JPL is (hopefully!) :-)
+
+You may also refer to the instructions of the [SARL Prolog Capacity](https://bitbucket.org/ssardina-research/sarl-prolog-cap)
+
+### Strange error in CLI when using occurence on left hand side of assignments
+Consider this code:
+
+    on CarArrivedPercept {
+        cars.get(occurrence.car).floor = occurrence.floor
+    }
+
+We know that `occurrence` is static, so cannot be changed. However, in the above code, `occurrence.car`, is not being changed/assigned, but just used to refer to another entity where assignment is performed. 
+However, SARL compiler will think that you are changing static element `occurrence` and complain with error. Instead do this:
+
+    on CarArrivedPercept {
+        val n = occurrence.car
+		cars.get(n).floor = occurrence.floor
+	}
+
+### Can we document SARL code for JAVADOC?
+
+Presumably yes, but I was not yet successful (have not tried much though!). Check this post: <https://groups.google.com/forum/#!topic/sarl/E_mhpFWyBFo>
+
+### How do I control the log-level of the Logging built-in capacity?
+
+Use `setLogLevel()` as explained here: <http://www.sarl.io/docs/official/reference/bic/Logging.html>
+
+There used to be a bug in that `debug()` was passed to the system logging which if it was at level `INFO` it would not display it. 
+It should now be fixed; see this post:  <https://github.com/sarl/sarl/issues/803> 
+
+
+### How can we know when an agent has been created fully after being spawn?
+
+An event `AgentSpawned` will be emitted when an agent has been created and can be handled, say by a coordinator, to know the agent is now alive! Fo example:
+
+	on AgentSpawned {
+		info("Agent {0} of type {1} has been created successfully and is now alive!",
+			occurrence.agentIdentifiers, occurrence.agentType)
+	}
+
+
+### Equality and identity comparison in SARL and checking for null: same as Java ?
+
+SARL' s developer states that the mapping of the operator from SARL to Java are:
+
+* `a === b` becomes `a == b`
+* `a !== b" becomes `a != b`
+* `a == b` becomes `a == null ? (b == null) : a.equals(b)`
+* `a != b` becomes `!Objects.equals(a,b)`. This is null-safe (part of Google API) and the code of the function is `a == b || (a != null && a.equals(b))`
+
+It is always better to test valid against null with the `===` or `!==` operators. These operators are not replaced neither `operator_equals` nor `operator_notEquals` within the Java code.
+
+I believe this is because SARL comparison operators follow the  which means that:
+
+* In Xtend the equals operators (`==`, `!=`) are bound to `Object.equals`. 
+* Java’s identity equals semantic is mapped to the tripple-equals operators `===` and `!==` in Xtend.
+
+Check xtend doc [here](https://www.eclipse.org/xtend/documentation/203_xtend_expressions.html#operators) for more details and SARL doc [here](http://www.sarl.io/docs/official/reference/general/Operators.html#3-comparison-operators).
+
+_**Note from SARL developer**_: SARL extends a part of [Xtend dialect](https://www.eclipse.org/xtend/index.html) in order to have benefits of several background features, such as the validation tests for type inheritance. Since Xtend and SARL uses [Xbase](https://www.eclipse.org/Xtext/documentation/305_xbase.html#xbase-expressions), a large part of the syntax is the same, especially within the blocks of code. (The rest of the syntax is defined in parallel. SARL was inspired by languages such as Scala, Python and Ruby. Several bugs or incoherencies of Xtend are fixed in SARL.
+
+There is still a bit of an issue inside the Xbase library; check this <https://github.com/sarl/sarl/issues/852#issuecomment-420842088>
+
+
+### How to return two values? Pairs in SARL
+
+Java comes with a `Pair<A,B>` class to build an object for storing two values, nicknamed "key" and "value", but they have no meaning as key/value. It comes useful when a method has to return two values instead of just one. For example, the following function returns the next floor and direction that an elevator has to serve:
+
+	def kb_getNextJob() : Pair<Integer, Direction> {
+        ...........
+        }
+
+As of Java 8, and as part of JavaFX, Java provides this `Pair<A,B>` class; check [here](https://www.geeksforgeeks.org/pair-class-in-java/) and [here](https://docs.oracle.com/javase/8/javafx/api/javafx/util/Pair.html). 
+Note `Pairs` are different from `Map`, which can be seen as a collection of `Pairs` and with a proper key/value semantics.
+
+There exist more advanced implementations of `Pair`, for example from Apache. See [here](https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/tuple/package-summary.html), [here](https://www.baeldung.com/java-pairs) and [here](https://gangmax.me/blog/2017/10/10/how-to-return-multiple-values-from-a-java-method/).
+
+
+SARL itself have compact syntax do deal with `Pair`, by using `a -> b` to create a `Pair` object `(a,b)`. There are also compact ways of manipulating `Collection` and `Maps`. 
+
+Check SARL documentation on that [here](http://www.sarl.io/docs/official/reference/general/Operators.html#8-collection-operators).
+
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.