Function calls are surrounded with parenthesis and arguments are separated by spaces not commas. String literals are surrounded by quotes.
Print "hello world" to stdout:
(println "hello world")
Single quotes cannot be used for string literals though
(println 'hello world')
java.lang.Exception: Unmatched delimiter: )
(println 'hello world')
java.lang.Exception: Unmatched delimiter: )
Clojure provides access to the core java libraries - albeit with some slight syntax changes...
Java:
System.out.println(System.getProperty("user.dir"));
System.out.println(System.getProperty("user.dir"));
Clojure:
(println (System/getProperty "user.dir"))
You can use defn to declare a function. Notice the argument list in square brakets.
(defn foo [bar baz] (str bar "," baz))
(foo 1 2)
==> "1,2"
The str function concatenates the strings passed.
No comments:
Post a Comment