JanetDocsSourcePlaygroundTutorialsI'm Feeling luckyCommunityGitHub sign in
# Linux pipes | send data through stdin # To make linux programs accepting varied input forms: (defn main [_ & args] # If no arguments, read from stdin (let [data (if (empty? args) (file/read stdin :all) (string/join args " "))] (print (sum (flatten (parse-all data)))))) # This accepts: 1 2 3 or "1" "2" "3" or "1 2 3" or "[1 2 3]" besides piping data in # janet fib.janet 5 | janet sum.janet # Allow file inputs also: (defn main [_ & args] (let [data (cond (empty? args) (file/read stdin :all) (os/stat (first args)) (slurp (first args)) (string/join args " "))] (print (sum (flatten (parse-all data))))))