Now let's take a look atCode:
The first one is nil, which has the same null value as Java. Like false, nil can express the condition that the condition is not true. The following is an explanation:
Nilnil is a possible value of any data type in clojure. nil has the same value as Java null. the clojure conditional System is based around nil and false, with nil and false representing the values of logical falsity in conditional tests-anything else is logical truth. in addition, Nil is used as the end-of-sequence sentinel value in the sequence protocol.
Because the main function code didn't use parameters before, modify the code here to demonstrate how to use parameters:
(NS project1.core) (defn-Main "I don't do a whole lot." [& ARGs] (println "Hello, world! ") (Println ARGs) (println (count ARGs )))
Run in repl session:
User => (require 'project1. Core) niluser => (project1.core/-Main "B") Hello, world! (B) 1nil
Explanation:
[] Square brackets are used to create a vector (array)
& ARGs refers to variable array elements
(Println ARGs) print all input parameters. ARGs is a list that contains all parameters.
(Count ARGs) calculates the number of parameters
Now let's see how to run without using repl sessionsProgramDirectly enter the following command:
~ /Project1 $ lein run-M project1.core "A" Hello, world! ()
The-main function under project1.core namespace is automatically found and executed.