Logic & Infix Operations

Familiar Forms in Some New Flavors

# Infix operations take this form
      a OPERATOR b
      

Most of what you'll do in C&S will take the form of a function call. However, like in most languages, There are some quick operations you can perform and comparisons you can make outside of function call syntax using infix operators.

Let's start with basic math:

3 + 2 #=> 5
      3 - 2 #=> 1
      3 * 2 #=> 6
      3 / 2 #=> 1.5
      3 % 2 #=> 1
      

You will also use infix operators to perform comparisons:

3 is 3 #=> true
      3 == 3 #=> true
      3 isnt 2 #=> true
      3 != 2 #=> true
      

Note that C&S does not allow type coercive comparisons, equality checks are translated to JavaScript's === operator, while inequality checks are translated to !==.

3 lt 2 #=> false
      3 gt 2 #=> true
      3 lte 2 #=> false
      3 gte 2 #=> true
      

C&S also includes friendly, readable operators for basic logic:

a and b
      a or b
      

Note that && and || are not logic operators in C&S.

Two other infix operators worthy of note are the cons and back cons operators.

1 >> [2, 3, 4] #=> [1, 2, 3, 4]
      [1, 2, 3] << 4 #=> [1, 2, 3, 4]