description

iterates over array, evaluating body once for each value in array. If item is a literal name, that will be the variable into which the array element is yielded (current value). If item is an expression, it can contain the current value, the index, and the array.

arguments

itemarray...body

example 1
sibilant(each number [ 1 2 3 ] (console.log number))
js[ 1, 2, 3 ].forEach((function(number) {
  /* src/macros/lists.sibilant:92:17 */

  return console.log(number);
}))
example 2
sibilant(each (letter index) `[ a b c d ]
                       (set letters letter index)
                       (pipe letter (.to-upper-case) (console.log)))
js[ "a", "b", "c", "d" ].forEach((function(letter, index) {
  /* src/macros/lists.sibilant:93:17 */

  letters[letter] = index;
  return console.log(letter.toUpperCase());
}))
description

returns true if the array arr has a length of zero

arguments

arr

example 1
sibilant(empty? [])
js0 === [].length
description

returns true if haystack does NOT include needle. haystack can be a string or array/list

arguments

haystackneedle

example 1
sibilant(excludes? 'hello 10)
js"hello".indexOf(10) === -1
example 2
sibilant(excludes? `[ Veni vidi vici] 'attenti)
js[ "Veni", "vidi", "vici" ].indexOf("attenti") === -1
description

gets the first element of arr

arguments

arr

example 1
sibilant(first `[ a b c d e ])
js[ "a", "b", "c", "d", "e" ][0]
description

returns true if haystack includes needle. haystack can be a string or array/list.

arguments

haystackneedle

example 1
sibilant(includes? 'hello 'h)
js"hello".indexOf("h") !== -1
example 2
sibilant(includes? `[ Veni vidi vici] 'vidi)
js[ "Veni", "vidi", "vici" ].indexOf("vidi") !== -1
description

combines elements of array arr into a string, inserting glue string between each element. if glue is omitted (only one argument provided), the elements of arr are joined with an empty string

arguments

arrglue

example 1
sibilant(join `[ a few words ]  ", " )
js[ "a", "few", "words" ].join(", ")
example 2
sibilant(join `[ several more words ])
js[ "several", "more", "words" ].join("")
description

fetches just the last element of arr by slicing.

arguments

arr

example 1
sibilant(last [ 1 2 3 ])
js[ 1, 2, 3 ].slice(-1)[0]
description

fetches length attribute from arr

arguments

arr

example 1
sibilant(length [ 1 2 3 ])
js[ 1, 2, 3 ].length
description

fetches all but the first item of arr

arguments

arr

example 1
sibilant(rest [ 1 2 3 ])
js[ 1, 2, 3 ].slice(1)
description

gets the second element of arr

arguments

arr

example 1
sibilant(second `[ a b c d e ])
js[ "a", "b", "c", "d", "e" ][1]
description

This is the macro that is called when brackets ([]) are used. Emits a javascript array literal. Splats (...) can be used to in-line other arrays.

arguments

args

example 1
sibilant(list 1 2 3 4 5)
js[ 1, 2, 3, 4, 5 ]
example 2
sibilant[ 'a 'b 'c 'd 'e ]
js[ "a", "b", "c", "d", "e" ]
example 3
sibilant[ a b ...c d ...e ]
js[ a, b ].concat(c, [ d ], e)
description

gets the third element of arr

arguments

arr

example 1
sibilant(third `[ a b c d e ])
js[ "a", "b", "c", "d", "e" ][2]
description

returns the last element if all elements of args are truthy, or the first non-truthy element if it exists

arguments

...args

example 1
sibilant(and (string? "string") (number? 10) (= 1 1))
js(typeof "string" === "string" && typeof 10 === "number" && 1 === 1)
description

boolean negation, as determined by javascript truthiness

arguments

exp

example 1
sibilant(not (string? 1))
js!(typeof 1 === "string")
description

retreives object properties, potentially deeply. If more than one keys are provided, get fetches deeply into nested objects or arrays. When javascript dot notation can be used (a.b = 3), it is. Otherwise, bracket notation is used.

arguments

obj...keys

example 1
sibilant(get an-object 'static-attribute-name)
jsanObject.staticAttributeName
example 2
sibilant(get object dynamic-attribute-name)
jsobject[dynamicAttributeName]
example 3
sibilant(get object "these attributes" "can't be dotted")
jsobject["these attributes"]["can't be dotted"]
example 4
sibilant(get array 0)
jsarray[0]
example 5
sibilant(get object 'a 'b c)
jsobject.a.b[c]
example 6
sibilant(get array 0 1 2)
jsarray[0][1][2]
description

this is the macro that is called by braces ({}). Produces a javascript object out of alternating key value pairs. To repeat an entry as both key and value, use the & character, as shown in examples. To use the value of a variable as a key, use the backtick character before the key. These can be combined

arguments

...pairs

example 1
sibilant(hash k1 v1 k2 v2)
js{
  k1: v1,
  k2: v2
}
example 2
sibilant(hash 'key 'value)
js{ "key": "value" }
example 3
sibilant{ 'key { 'nested 'value } }
js{ "key": { "nested": "value" } }
example 4
sibilant{ kv1& kv2& }
js{
  kv1: kv1,
  kv2: kv2
}
example 5
sibilant{ `variable 1 }
js(function() {
  var hash$1 = {  };
  hash$1[variable] = 1;
  return hash$1;
}).call(this)
example 6
sibilant{ `variable & }
js(function() {
  var hash$2 = {  };
  hash$2[variable] = variable;
  return hash$2;
}).call(this)
description

assigns object properties to arr in pairs, alternating between keys and values. When javascript dot notation can be used (a.b = 3), it is. Otherwise, bracket notation is used

arguments

arr...kv-pairs

example 1
sibilant(set an-object 'static-attribute-name 'value)
jsanObject.staticAttributeName = "value";
example 2
sibilant(set object dynamic-attribute-name "key name determined at runtime")
jsobject[dynamicAttributeName] = "key name determined at runtime";
example 3
sibilant(set array 0 "first element of array")
jsarray[0] = "first element of array";
example 4
sibilant(set object "can't be dotted" 'value)
jsobject["can't be dotted"] = "value";
example 5
sibilant(set object 'first-attribute 'first-value
                      'second-attribute 'second-value)
jsobject.firstAttribute = "firstValue";
object.secondAttribute = "secondValue";
description

tests any number of alternating-conditions-and-branches. If an odd number of branches are supplied, the final branch is a default else clause. To evaluate more than one expression as a branch, use the do macro, as shown in the examples:

arguments

...alternating-conditions-and-branches

example 1
sibilant(if true (console.log 'here))
js(function() {
  if (true) {
    return console.log("here");
  }
}).call(this)
example 2
sibilant(if (= 1 arguments.length) (console.log "one argument")
                     (= 'blue favorite-color) (console.log "blue")
                     (assign examples 'difficult))
js(function() {
  if (1 === arguments.length) {
    return console.log("one argument");
  } else if ("blue" === favoriteColor) {
    return console.log("blue");
  } else {
    return examples = "difficult";
  }
}).call(this)
example 3
sibilant(if (foo?) (do (a b)
                                (c))
                     (bar?) (do (baz)
                                (wibble))
                     (do (d e)
                         (console.log 'default)))
js(function() {
  if (foo__QUERY()) {
    a(b);
    return c();
  } else if (bar__QUERY()) {
    baz();
    return wibble();
  } else {
    d(e);
    return console.log("default");
  }
}).call(this)
description

short circuiting operator returns the first element of args that evaluates to be truthy

arguments

...args

example 1
sibilant(or (= 1 2) (string? []) "one is not two and an array is not a string")
js(1 === 2 || typeof [] === "string" || "one is not two and an array is not a string")
description

the simplest way to conditionally execute code.

arguments

condif-trueif-false

example 1
sibilant(ternary (< 50 100)
         "fifty is less than 100"
         "fifty is more than 100")
js(50 < 100) ? "fifty is less than 100" : "fifty is more than 100"
description

evaluates statements in body if condition is falsy. body is scoped in a self-evaluating function to support having a return value from the if statement.

arguments

condition...body

example 1
sibilant(unless (< 3 i) (console.log i) (get arr i))
js(function() {
  if (!(3 < i)) {
    console.log(i);
    return arr[i];
  }
}).call(this)
description

evaluates statements in body if condition is true. body is scoped in a self-evaluating function to support having a return value from the if statement.

arguments

condition...body

example 1
sibilant(when (< 3 i) (console.log i) (get arr i))
js(function() {
  if (3 < i) {
    console.log(i);
    return arr[i];
  }
}).call(this)
description

calls the function fn with arguments passed as an array in arglist

arguments

fnarglist

example 1
sibilant(apply my-function [ first-arg second-arg third-arg ])
jsmyFunction.apply(this, [ firstArg, secondArg, thirdArg ])

argument

description

gets the argument at index in the current function context. Inside of a thunk (#>), this can be abbreviated with #n, where n is the argument index.

arguments

index

example 1
sibilant(argument 3)
jsarguments[3]

arguments

description

transforms function arguments into an array, using the Array prototype's slice

arguments

...args

example 1
sibilant(arguments)
jsArray.prototype.slice.call(arguments)
description

This is the macro that is executed when a function is the first element in an expression. Assuming that there is no macro named a, (a b c) internatlly compiles to (call a b c). splats (...) can be used in function calls.

arguments

fn-name...args

example 1
sibilant(call a b c)
jsa(b, c)
example 2
sibilant(call a b ...c)
jsa.apply(this, [ b ].concat(c))
example 3
sibilant(call a ...args)
jsa.apply(this, args)

function?

description

returns true if all of the things are functions

arguments

...things

example 1
sibilant(function? fn)
jstypeof fn === "function"
example 2
sibilant(function? err cb)
js(typeof err === "function" && typeof cb === "function")
description

Defines a lambda/function/closure in Sibilant. Equivalent to the function keyword in JavaScript. Most of the time args is a paren-wrapped list of arguments, which can include one triple-dotted splat in the terminal position. The last expression of body will be returned. Aliased as #, as shown in examples.

arguments

args-or-options...body

example 1
sibilant(lambda (a b c) (|> a (+ b) (/ c)))
js(function(a, b, c) {
  /* src/macros/lambda.sibilant:9:17 */

  return ((a + b) / c);
})
example 2
sibilant(lambda (a b ...numbers)
        (console.log ("a: "a", b: "b""))
        (numbers.map (#-> (+ 10))))
js(function(a, b, numbers) {
  /* src/macros/lambda.sibilant:10:0 */

  var numbers = Array.prototype.slice.call(arguments, 2);

  console.log(("a: " + a + ", b: " + b + ""));
  return numbers.map((function() {
    /* src/macros/lambda.sibilant:12:21 */
  
    return (arguments[0] + 10);
  }));
})
example 3
sibilant(#({ destructured-object }) (destructured-object))
js(function(destructured_ob$1) {
  /* src/macros/lambda.sibilant:13:0 */

  var destructuredObject = destructured_ob$1.destructuredObject;

  return destructuredObject();
})
example 4
sibilant(#([ one two three ]) { one& two& three& })
js(function(one_two_three$1) {
  /* src/macros/lambda.sibilant:14:0 */

  var one = one_two_three$1[0],
      two = one_two_three$1[1],
      three = one_two_three$1[2];

  return {
    one: one,
    two: two,
    three: three
  };
})
example 5
sibilant(|> document.body
    (.add-event-listener
     (#(event)
       (console.log ("click at point ("event.x","event.y")"))
       (event.prevent-default))))
jsdocument.body.addEventListener((function(event) {
  /* src/macros/lambda.sibilant:17:5 */

  console.log(("click at point (" + event.x + "," + event.y + ")"));
  return event.preventDefault();
}))
description

uses the javascript new keyword to construct an object using constructor, with args passed as arguments to the constructor.

arguments

constructor...args

example 1
sibilant(new RegExp "hello" 'g)
js(new RegExp("hello", "g"))
description

most often called as its alias, #->, pipe-thunk applies a pipe chain to the argument of a function and returns the result

arguments

...calls

example 1
sibilant(.map `[ a b c ] (#-> (.to-upper-case) (concat " is a letter")))
js[ "a", "b", "c" ].map((function() {
  /* src/macros/pipe.sibilant:54:34 */

  return (arguments[0].toUpperCase() + " is a letter");
}))

scoped

description

executes the body inside of a self-executing function. The last statement/expression of the body is returned.

arguments

...body

example 1
sibilant(scoped true)
js(function() {
  /* src/macros/lambda.sibilant:212:16 */

  return true;
}).call(this)
example 2
sibilant(scoped (var a 1) (+ a 2))
js(function() {
  /* src/macros/lambda.sibilant:212:30 */

  var a = 1;
  return (a + 2);
}).call(this)
description

calls the method on object as a function with args as the arguments

arguments

objectmethod...args

example 1
sibilant(send object method first-argument second-argument third-argument)
jsobject.method(firstArgument, secondArgument, thirdArgument)
description

most often called as its alias, #>, thunk creates a function with no named arguments. To refer to arguments anonymously, use #n, such as #0 for the first argument.

arguments

...body

example 1
sibilant(.map [ 1 2 3 ] (#> (+ 1(argument'0'))))
js[ 1, 2, 3 ].map((function() {
  /* src/macros/lambda.sibilant:70:34 */

  return (1 + arguments[0]);
}))
example 2
sibilant(window.set-timeout (#> (console.log 'here)) 10)
jswindow.setTimeout((function() {
  /* src/macros/lambda.sibilant:71:38 */

  return console.log("here");
}), 10)
description

assigns alternating keys and values in args. This works much like var, but without the var keyword. It is important to understand variable scope in javascript in order to use this macro safely. This macro supports destructuring, as shown in examples

arguments

...pairs

example 1
sibilant(assign a 1)
jsa = 1;
example 2
sibilant(assign a: 1, b: 2)
jsa = 1;
b = 2;
example 3
sibilant(assign [ right left ] [ left right ])
jsleft_right$1 = [ left, right ];
right = left_right$1[0];
left = left_right$1[1];
left_right$1 = undefined;
example 4
sibilant(assign {log} console)
jslog = console.log;
example 5
sibilant(assign [ a b ] c)
jsa = c[0];
b = c[1];
example 6
sibilant(assign { a b } c
        [ x y ] a)
jsa = c.a;
b = c.b;
x = a[0];
y = a[1];

comment

description

inserts contents transpiled to javascript as a comment in the output file, removing it from execution.

arguments

...contents

example 1
sibilant(comment (scoped 1))
js// (function() {
//   /* src/macros/misc.sibilant:25:23 */
// 
//   return 1;
// }).call(this)
description

defines a function in the local scope. name is the variable name that the function will be stored as. Note that sibilant does *not* support hoisting. args is a paren-wrapped list of arguments, as shown in the examples. body can be any number of statements, the last of which will be the return value of the function.

arguments

nameargs...body

example 1
sibilant(def square (x) (* x x))
jsvar square = (function square$(x) {
  /* square src/macros/lambda.sibilant:157:17 */

  return (x * x);
});

include

description

loads and transpiles content from another file or files as if it were written in-line. This is distinct from node's require function, as include will drop the output javascript directly in place of the include statement. Namespaced macros defined in the included file will not by default be imported into the current macro namespace. Include will append ".sibilant" to the end of files, and will also use node's module system to resolve sibilant files from other packages. As a noncompiling example, it is possible to npm install sibilant-react and (include "sibilant-react/macros"), which introduces the react macro namespace.

arguments

...files

instance-of?

description

uses the javascript instanceof operator to check if item is of type.

arguments

itemtype

example 1
sibilant(instance-of? (new Date) Date)
js(transpile(item)" instanceof "transpile(type))

log-pretty

description

outputs debug information about arg. If label is omitted (only one argument is provided), the name of the variable or expression of that first expression will be logged. Aliased as pretty-log

arguments

labelarg

example 1
sibilant(log-pretty 'my-label value)
jsconsole.log(("src/macros/misc.sibilant:40" + " " + "myLabel" + " = " + prettify(value)))
example 2
sibilant(log-pretty (+ 1 2))
jsconsole.log(("src/macros/misc.sibilant:41" + " " + "(+ 1 2)" + " = " + prettify((1 + 2))))
description

Defines a macro. The arguments are the same as for def: the function defined with args and body will be stored in the current macro namespace as name. The last statement of body will be returned, and should either be an array of strings and/or sibilant ast nodes, or a sibilant ast node. Most of the time this is accomplished through use of quote and unquote. Note that there are no examples for this macro, but hopefully there will be a tutorial.

arguments

nameargs...body

description

Equivalent to defining a macro and immediately evaluating it. Evaluates body at compile time in the compiler context. Note that the result is inserted directly into the code, not as a string. Often you will want to use this in conjunction with quote or comment, as shown in the examples.

arguments

...body

example 1
sibilant(comment (meta (sibilant.version)))
js// 0.5.5
example 2
sibilant(quote (meta (sibilant.version)))
js"0.5.5"
description

inserts the result of each subsequent call in calls as the second argument to the next macro. This is very much akin to clojure's thread-first arrow or elixir's pipe operator. Advanced: in order to thread the preceding topic into a position other than the second position, use the character # to specify topic position

arguments

...calls

example 1
sibilant(pipe "a b c d"
      .to-upper-case
      (.replace "A" "X")
      (.split " ")
      first
      (concat " marks the spot"))
js("a b c d".toUpperCase().replace("A", "X").split(" ")[0] + " marks the spot")
example 2
sibilant(pipe "{\"a\": {\"b\": [ 1, 2, 3 ]}}"
      JSON.parse
      (get 'a)
      JSON.stringify)
jsJSON.stringify(JSON.parse("{\"a\": {\"b\": [ 1, 2, 3 ]}}").a)
example 3
sibilant(pipe 3 (+ 1) (var a #))
jsvar a = (3 + 1);
description

generates a function intended to be used in conjunction with pipe or pipe-thunk that does not interrupt the main flow of the pipe

arguments

thing...body

example 1
sibilant(|> 2 (tap (+ 5) console.log) (* 10))
js((function() {
  /* src/macros/pipe.sibilant:66:9 */

  console.log((arguments[0] + 5));
  return arguments[0];
})(2) * 10)
example 2
sibilant(#-> .to-upper-case (tap console.log) (.split " "))
js(function() {
  /* src/macros/pipe.sibilant:64:17 */

  return (function() {
    /* src/macros/pipe.sibilant:66:9 */
  
    console.log(arguments[0]);
    return arguments[0];
  })(arguments[0].toUpperCase()).split(" ");
})
description

throws a new javascript error with arguments as the string

arguments

error

example 1
sibilant(throw (new Error "could not find matching socks"))
jsthrow (new Error("could not find matching socks"))
description

evaluates the body as long as condition is falsy, returning the value of the last expression in block when condition ceases to be falsy. See also while

arguments

condition...body

example 1
sibilant(until (< 5 i) (console.log i) (incr i))
js(function() {
  var while$2 = undefined;
  while (!(5 < i)) {
    while$2 = (function() {
      console.log(i);
      return ((i)++);
    }).call(this);
  };
  return while$2;
}).call(this)
description

evaluates the body as long as condition is truthy, returning the value of the last expression in block when condition ceases to be truthy. See also until

arguments

condition...body

example 1
sibilant(while (> 5 i) (console.log i) (decr i))
js(function() {
  var while$1 = undefined;
  while (5 > i) {
    while$1 = (function() {
      console.log(i);
      return ((i)--);
    }).call(this);
  };
  return while$1;
}).call(this)

alias-macro

description

stores a duplicate copy of current-macro-name as new-macro-name in current namespace. No output.

arguments

current-macro-namenew-macro-name

delete-macro

description

deletes each macro name in macro-names from the current namespace. Use carefully

arguments

...macro-names

rename-macro

description

moves macro from current-macro-name to new-macro-name. Use carefully

arguments

current-macro-namenew-macro-name

description

multiplies elements of args

arguments

...args

example 1
sibilant(* 3 4 5)
js(3 * 4 * 5)
description

subtracts each subsequent element of args

arguments

...args

example 1
sibilant(- 2 1)
js(2 - 1)
example 2
sibilant(- 10 5 1)
js(10 - 5 - 1)
description

divides each subsequent element of args

arguments

...args

example 1
sibilant(/ 1 2)
js(1 / 2)
example 2
sibilant(/ 1 2 3)
js(1 / 2 / 3)
description

decrements item by 1

arguments

item

example 1
sibilant(decr i)
js((i)--)

even?

description

returns true if number is divisible by 2 with no remainder

arguments

number

example 1
sibilant(even? 10)
js0 === (10 % 2)
description

increments item by 1

arguments

item

example 1
sibilant(incr i)
js((i)++)

incr-by

description

increments item by increment

arguments

itemincrement

example 1
sibilant(incr-by n 5)
jsn += 5
description

modulus operator

arguments

...args

example 1
sibilant(mod 10 2)
js(10 % 2)
description

returns true if all of the things are numbers, as tested with typeof

arguments

...things

example 1
sibilant(number? 1)
jstypeof 1 === "number"
example 2
sibilant(number? 1 2 3)
js(typeof 1 === "number" && typeof 2 === "number" && typeof 3 === "number")
description

returns true if number is not divisible by 2

arguments

number

example 1
sibilant(odd? 5)
js1 === (5 % 2)

zero?

description

predicate to test for equality with zero

arguments

item

example 1
sibilant(zero? n)
jsn === 0
description

uses the javascript delete keyword on any number of objects. Use in conjunction with get or dotted literal notation (a.b).

arguments

...objects

example 1
sibilant(delete object.a object.b)
jsdelete object.a;
delete object.b;
example 2
sibilant(delete (get object attribute) (get object "other attribute"))
jsdelete object[attribute];
delete object["other attribute"];
description

iterates over each attribute in obj

arguments

asobj...body

example 1
sibilant(each-key key { a 1 b 2 } (console.log key))
jsObject.keys({
  a: 1,
  b: 2
}).forEach((function(key) {
  /* src/macros/hash.sibilant:121:14 */

  return console.log(key);
}))
description

checks if object has property key. returns true or false.

arguments

objectkey

example 1
sibilant(has-key? object 'a)
jsobject.hasOwnProperty("a")
description

returns the property names of obj.

arguments

obj

example 1
sibilant(keys { a 1 b 2 })
jsObject.keys({
  a: 1,
  b: 2
})

match-regex?

description

similar to match? but builds a regex out of the pattern and flags.

arguments

stringpatternflags

example 1
sibilant(match-regex? 'word "^[a-z]+$" 'i)
js"word".match((new RegExp("^[a-z]+$", "i")))
description

returns true if the string matches regexp. Deprecated in preference to .match (send dot-invocation).

arguments

regexpstring

example 1
sibilant(match? (regex "^[a-z]+$" 'i) 'word)
js"word".match((new RegExp("^[a-z]+$", "i")))

regex

description

builds a regex using pattern and flags as arguments to the RegExp constructor

arguments

patternflags

example 1
sibilant(regex "[0-9]+")
js(new RegExp("[0-9]+", undefined))
example 2
sibilant(regex "0x[0-9a-f]+" 'i)
js(new RegExp("0x[0-9a-f]+", "i"))
description

replaces the first occurance of pattern (as a regex) with replacement

arguments

stringpatternreplacement

example 1
sibilant(replace "hello world" "l+o" "y there,")
js"hello world".replace((new RegExp("l+o", undefined)), "y there,")

replace-all

description

replaces all occurrances of pattern (as a regex) with replacement

arguments

stringpatternreplacement

example 1
sibilant(replace-all "503-555-1212" "[0-9]" "#")
js"503-555-1212".replace((new RegExp("[0-9]", "g")), "#")
description

adds args using the javascript + operator. Since javascript overloads this for string concatenation, this macro can be used for this as well.

arguments

...args

example 1
sibilant(+ 1 2 3)
js(1 + 2 + 3)
example 2
sibilant(+ 'hello 'world)
js("hello" + "world")

lower-case?

description

checks if a string is identical to the lower-cased version of itself

arguments

str

example 1
sibilant(lower-case? "abc")
js("abc".toUpperCase() !== "abc" && "abc".toLowerCase() === "abc")
description

returns true if all of the things are javascript strings

arguments

...things

example 1
sibilant(string? test-object)
jstypeof testObject === "string"
example 2
sibilant(string? 'yes 'yes 'yes)
js(typeof "yes" === "string" && typeof "yes" === "string" && typeof "yes" === "string")

upper-case?

description

checks if a string is identical to the upper-cased version of itself

arguments

str

example 1
sibilant(lower-case? "abc")
js("abc".toUpperCase() !== "abc" && "abc".toLowerCase() === "abc")
description

returns true if thing is an array in javascript. aliased as list?.

arguments

thing

example 1
sibilant(array? arr)
js(arr && "object" === typeof arr && "Array" === arr.constructor.name)

as-boolean

description

double-negates expr, converting it to a boolean

arguments

expr

example 1
sibilant(as-boolean 0)
js(!!(0))
example 2
sibilant(as-boolean true)
js(!!(true))

as-number

description

coerces expr to a number. Currently implemented through the use of Number()

arguments

expr

example 1
sibilant(as-number "0.1")
jsNumber("0.1")
example 2
sibilant(as-number 0.1)
jsNumber(0.1)

defined?

description

returns true if none of the things are undefined, as tested with typeof. This is the inverse of defined?

arguments

...things

example 1
sibilant(defined? variable)
jstypeof variable !== "undefined"
example 2
sibilant(defined? var1 var2 var3)
js(typeof var1 !== "undefined" && typeof var2 !== "undefined" && typeof var3 !== "undefined")

exists?

description

similar to the javascript truthiness predicate as-boolean, returns true unless the thing is undefined or null

arguments

thing

example 1
sibilant(exists? window)
js(typeof window !== "undefined" && window !== null)
description

returns true if thing is an object that is not an array in javascript. aliased as object?.

arguments

thing

example 1
sibilant(object? arr)
js("object" === typeof arr && arr !== null && arr.constructor.name !== "Array")

typeof

description

exposes the javascript typeof operator. most often, predicates such as string?, function?, number?, etc are preferred.

arguments

thing

example 1
sibilant(typeof 5)
jstypeof 5

undefined?

description

returns true if all of the things are undefined, as tested with typeof, not equality with literal undefined. This is the inverse of defined?

arguments

...things

example 1
sibilant(undefined? argument)
jstypeof argument === "undefined"
example 2
sibilant(undefined? 1 2 undefined)
js(typeof 1 === "undefined" && typeof 2 === "undefined" && typeof undefined === "undefined")
description

sets default values for variables in current scope. pairs are alternating variable names and default values

arguments

...pairs

example 1
sibilant(default a 10 b 20)
jsa = (typeof a !== "undefined") ? a : 10;
b = (typeof b !== "undefined") ? b : 20;
description

registers variables in pairs inside of the current scope using the javascript var keyword. destructuring from arrays and objects is also supported, as shown in the examples. Note: : and , are always ignored.

arguments

...pairs

example 1
sibilant(var a)
jsvar a = undefined;
example 2
sibilant(var a: 1, b: 2)
jsvar a = 1,
    b = 2;
example 3
sibilant(var a [ 1 2 3 ]
     [ b c d ] a)
jsvar a = [ 1, 2, 3 ],
    b = a[0],
    c = a[1],
    d = a[2];
example 4
sibilant(var {attribute} { attribute: 'hi })
jsvar attribute = ({ attribute: "hi" }).attribute;
example 5
sibilant(var {log dir} console)
jsvar log = console.log,
    dir = console.dir;
example 6
sibilant(var {a}: {a 1 b 2},
     {c d}: {c 3 d 4})
jsvar a = ({
  a: 1,
  b: 2
}).a,
    c_d$1 = {
  c: 3,
  d: 4
},
    c = c_d$1.c,
    d = c_d$1.d,
    c_d$1 = undefined;

source-mapping-url

description

inserts a pragma for source-mapping-url

arguments

url

example 1
sibilant(source-mapping-url "/example.map")
js//# sourceMappingURL=/example.map
description

adds additional elements onto the right-side (tail) of list. deprecated

arguments

list...additional

example 1
sibilant(append [ 1 2 3 ] 4 5 6)
js[ 1, 2, 3 ].concat([ 4, 5, 6 ])
description

builds an array with first as the zeroth index and the elements provided by array rest as the subsequent elements, as siblings with first.

arguments

firstrest

example 1
sibilant(cons 1 [ 2 3 4 ])
js[ 1 ].concat([ 2, 3, 4 ])
description

uses the javascript switch construction to test equality. documentation todo: needs better description

arguments

obj...cases

example 1
sibilant(switch char
                         ('a "it was an a")
                         ('b (console.log "found a b!")
                             "it was a b")
                         ([1 2 3 4 5] "it was an integer from one to five")
                         (default "not sure"))
js(function() {
  switch(char) {
  case "a":
    return "it was an a";
  
  case "b":
    console.log("found a b!");
    return "it was a b";
  
  case 1:
  case 2:
  case 3:
  case 4:
  case 5:
    return "it was an integer from one to five";
  
  default:
    return "not sure";
  }
}).call(this)

Made with love in 2016 by Jacob Rothstein

Colophon: sibilant, react, react-bootstrap, redux, highlightjs