I wrote a small snippet that uses an external library, can you code review it? https://github.com/danielmartincraig/yamlscript-experiments/blob/master/reverse.ys
How can I avoid using the parenthesis?
This worked for me:
defn main():
result =:
str/reverse: "hello world"
say: resultThanks!
You need to use :: instead of . in namespaces.
$ ys -ce 'require clojure::string: => str'
(require '[clojure.string :as str]). is the chaining operator and there was no good way to keep it as a namespace separator.
At some point I'll try to recognize when people make that mistake. (I do it all the time)
but in YS you don't need to require clojure.string or alias as str.
those are automatically available.
!yamlscript/v0
require clojure::string: => foo
say: foo/reverse("hello world")
say: str/reverse("hello world")
say: clojure::string/reverse("hello world")
all work!yamlscript/v0
defn main(name='world'):
result =: str/reverse("hello $name")
say: result
is a variation using default args and string interpolationThe main function is automatically called with (apply main ARGS)
ARGS is a "parsed" version of *command-line-args*
$ cat foo.ys
!yamlscript/v0
defn main(& args):
say: json/dump(args)
say: json/dump(ARGS)
say: json/dump(ARGV)
say: ns-name(NS)
say: FILE
each [a ARGS]:
say: "$a -> $(type(a))"
$ ys foo.ys 'foo bar' 42 3.1415
["foo bar",42,3.1415]
["foo bar",42,3.1415]
["foo bar","42","3.1415"]
main
/home/ingy/foo.ys
foo bar -> class java.lang.String
42 -> class java.lang.Long
3.1415 -> class java.lang.Double
$ ys foo.ys -c
(defn
main
[& args]
(say (json/dump args))
(say (json/dump ARGS))
(say (json/dump ARGV))
(say (ns-name *ns*))
(say FILE)
(each [a ARGS] (say (str a " -> " (type a)))))
(apply main ARGS)