Differences¶
Second Loop borrows its syntax from Clojure but is a much smaller language, chosen for driving a robot rather than for general programming. Where faithfulness to Clojure and staying small conflict, it stays small.
Language¶
- No namespaces.
Math/sinandstr/joinare simply names of functions. - No regexes or characters.
str/splitandstr/replacematch plain text, and a string is not a sequence of characters. - Macros are not supported.
Errors¶
catchknows three classes:Exception(any error),ExceptionInfo(fromex-info) andThrowable(also stack overflow). A stop request is never caught, andfinallyruns to the end even while stopping.- An error inside a future is printed at once by the connection that
started it, as well as being raised again by
deref. Printing it only whenderefruns would risk a dead control loop going unnoticed.
Collections¶
- Collections are copied, not shared. Nothing is ever modified in place, but every change copies the whole collection; there are no persistent data structures. Maps and sets keep the order items were added.
- Everything is eager.
map,filterandrangebuild their whole result straight away, sorangeneeds an end. - Destructuring supports
&and:asin vectors and:keys,:orand:asin maps, but not:strsor:syms. doseqtakes one or more bindings but not the:when,:whileor:letmodifiers.
Numbers and time¶
- Numbers are always doubles.
(+ 1 2)is3.0and(quot 7 2)is3.0. Informat, use%.0finstead of%d. - Dividing by zero is an error, rather than
##Inf, so an infinite value never reaches a motor. - Time is in seconds.
(time/elapsed)gives seconds since START and(time/sleep s)waits in seconds. Java'sSystem/currentTimeMillis,System/nanoTimeandThread/sleepare left out, so no code has to convert milliseconds or nanoseconds.
Atoms and futures¶
- Atoms have no watches or validators, and no
add-watch. To react to a change, read the atom in the loop, which already does that once per round. future-cancelwaits (up to a second) for the future's thread to end, so a cancelled loop cannot take one more step, such as setting a motor's power, after the call returns.