Skip to content

YS Shorties

From the start, YAML has always been about making data clean and easy to read.

This carries over to YS code as well.

Even though YS code compiles to Clojure, YS often has shorter alternatives for Clojure's commonly used and longer function names.

To Name a Few🔗

Here are some shorter alternative functions that YS provides. Note: you can almost always use the Clojure version if you want to.

say is short for println External link . This is one of the most commonly used functions and found in almost every program.

a is short for identity External link .

len is short for count External link . count isn't that long, but lots of languages use len for this. In YS you can use either! Or even use .# in a chaining context.

out and err are short for print External link to stdout and stderr respectively.

read and write are short for slurp External link and spit External link respectively. write is longer, but spit is gross!

q is short for quote External link . In YS, a single quote is used for a string literal that doesn't have interpolation semantics. In Clojure, a single quote is used for form quoting (using a form without evaluating it) and is just sugar for the quote function. For instance in Clojure you might do '(1 2 3). In YS you'd use q((1 2 3)) or (1 2 3):q

To my Clojure Friends

I know that quote isn't really a function; it's a special form. And I know that I've called macros "functions" in this series. Forgive me, but it's just not that important to make the distinction; at least not at this point.

Also, macros are much less important to YS than they are to Clojure. I'll explain why in a future post.

chomp is short for str/trim-newline External link .

uc and lc are short for str/upper-case External link and str/lower-case External link respectively.

uc1 is short for str/capitalize External link .

index and rindex are short for str/index-of External link and str/last-index-of External link respectively.

replace1 is short for str/replace-first External link .

now returns a time object.

Casting Shorties🔗

YS has a bunch of functions whose job is to cast a value from one type to another. Functions like to-int, to-map and to-char. Each of these has a single character short name:

  • B is short for to-bool (boolean)
  • C is short for to-char (character)
  • F is short for to-float (floating point number)
  • I is short for to-int (integer)
  • K is short for to-keyw (keyword)
  • L is short for to-list (list)
  • M is short for to-map (mapping)
  • N is short for to-num (number)
  • O is short for to-omap (ordered mapping)
  • S is short for to-str (string)
  • T is short for to-type (string name of the type)
  • V is short for to-vec (vector)

(Maybe we'll talk about YS's data types later this week.)

There's also a few data collection type constructors that take a list of values:

  • L+ is short for list
  • M+ is short for hash-map
  • O+ is short for omap
  • V+ is short for vector

  • T? is short for truey?

  • F? is short for falsey?

Global Shorties🔗

Clojure has a set of variables called builtin dynamic variables. They have funny looking names like *out* and *command-line-args*. They are sometimes referred to as "earmuff variables" because they begin and end with an asterisk.

Theses names are invalid syntax in YS. In YS we call them global variables, they use capital letters, and their names are usually short.

  • IN is short for *in* (stdin)
  • OUT is short for *out* (stdout)
  • ERR is short for *err* (stderr)
  • ARGV is short for *command-line-args* (command line arguments)
  • ARGS is ARGV with number arguments auto-casted
  • NS is short for *ns* (current namespace)
  • VERSION is short for *clojure-version* (but for the YS version)
  • RUN is a mapping of runtime information
  • ENV is a mapping of environment variables
  • FILE is short for *file* (current file)

That's it for today. I could probably say more on this topic, but...

Let's keep it short!

Comments