[{"name":"ternary","namespace":"core","type":"macro","description":"the simplest way to conditionally execute code.","references":[],"arguments":["cond","if-true","if-false"],"definition":"(macro ternary (cond if-true if-false)\n       [\"(\" (transpile cond) \") ? \"\n            (transpile if-true) \" : \"\n            (transpile if-false)])","examples":[{"javascript":"(50 < 100) ? \"fifty is less than 100\" : \"fifty is more than 100\"","sibilant":"(ternary (< 50 100)\n         \"fifty is less than 100\"\n         \"fifty is more than 100\")"}],"tags":["conditional","flowControl"]},{"name":"when","namespace":"core","type":"macro","description":"evaluates statements in `body` if `condition` is true. `body`\n      is `scoped` in a self-evaluating function to support having a\n      return value from the if statement.","references":[],"arguments":["condition","...body"],"definition":"(macro when (condition ...body)\n       (^*scoped-without-return\n         \"if (\" @condition \") {\"\n         (indent `(do ...@body))\n         \"}\"))","examples":[{"javascript":"(function() {\n  if (3 < i) {\n    console.log(i);\n    return arr[i];\n  }\n}).call(this)","sibilant":"(when (< 3 i) (console.log i) (get arr i))"}],"tags":["conditional","flowControl","language"]},{"name":"unless","namespace":"core","type":"macro","description":"evaluates statements in `body` if `condition` is falsy. `body`\n      is `scoped` in a self-evaluating function to support having a\n      return value from the if statement.","references":[],"arguments":["condition","...body"],"definition":"(macro unless (condition ...body)\n       [\"(function() {\"\n        (indent [\"if (\" '(not @condition) \") {\"\n                        (indent '(do ...@body))\n                        \"}\"])\n        \"}).call(this)\"])","examples":[{"javascript":"(function() {\n  if (!(3 < i)) {\n    console.log(i);\n    return arr[i];\n  }\n}).call(this)","sibilant":"(unless (< 3 i) (console.log i) (get arr i))"}],"tags":["conditional","flowControl"]},{"name":"if","namespace":"core","type":"macro","description":"tests any number of `alternating-conditions-and-branches`.  If\n      an odd number of branches are supplied, the final branch is a\n      default else clause.  To evaluate more than one expression as a\n      branch, use the `do` macro, as shown in the examples:","references":[],"arguments":["...alternating-conditions-and-branches"],"definition":"(macro if (...alternating-conditions-and-branches)\n       [\"(function() {\"\n        (indent\n         (interleave \" else \"\n               (bulk-map alternating-conditions-and-branches\n                         (#(cond val)\n                           (if (!= (typeof val) 'undefined)\n                                 [\"if (\" (transpile cond) \") {\"\n                                   (indent '(do @val))\n                                   \"}\"]\n                                 [\"{\" (indent '(do @cond)) \"}\"])))))\n        \"}).call(this)\"])","examples":[{"javascript":"(function() {\n  if (true) {\n    return console.log(\"here\");\n  }\n}).call(this)","sibilant":"(if true (console.log 'here))"},{"javascript":"(function() {\n  if (1 === arguments.length) {\n    return console.log(\"one argument\");\n  } else if (\"blue\" === favoriteColor) {\n    return console.log(\"blue\");\n  } else {\n    return examples = \"difficult\";\n  }\n}).call(this)","sibilant":"(if (= 1 arguments.length) (console.log \"one argument\")\n                     (= 'blue favorite-color) (console.log \"blue\")\n                     (assign examples 'difficult))"},{"javascript":"(function() {\n  if (foo__QUERY()) {\n    a(b);\n    return c();\n  } else if (bar__QUERY()) {\n    baz();\n    return wibble();\n  } else {\n    d(e);\n    return console.log(\"default\");\n  }\n}).call(this)","sibilant":"(if (foo?) (do (a b)\n                                (c))\n                     (bar?) (do (baz)\n                                (wibble))\n                     (do (d e)\n                         (console.log 'default)))"}],"tags":["conditional","flowControl"]},{"name":"hash","namespace":"core","type":"macro","description":"this is the macro that is called by braces (`{}`). Produces a\njavascript object out of alternating key value pairs. To repeat an\nentry 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","references":[],"arguments":["...pairs"],"definition":"(macro hash (...pairs)\n       (assign pairs (pairs.map (#(p i)\n                                  (if (and (= p.token \"&\") (node? p 'special))\n                                      (do\n                                       (var double (get pairs (if (even? i) (+ 1 i) (- i 1))))\n                                       (if (and (node? double 'tick) (= double.token \"`\"))\n                                           (first double.contents)\n                                           double))\n                                      p))))\n                                                                                       \n       (when (odd? pairs.length)\n             (error (\"odd number of key-value pairs in hash: \"\n                     (call inspect pairs))))\n\n       (var {dynamic-keys static-keys}\n            (pairs.reduce (#(o item i)\n                            (if (and (even? i) (node? item 'tick) (= item.token \"`\"))\n                                (Object.assign {} o { dynamic-keys: [ ...o.dynamic-keys (first item.contents) ] })\n\n                                (and (odd? o.dynamic-keys.length) (odd? i))\n                                (Object.assign {} o { dynamic-keys: [ ...o.dynamic-keys item ] })\n\n                                (Object.assign {} o { static-keys: [ ...o.static-keys item ] })))\n                          { dynamic-keys: [], static-keys: [] }))\n\n       (var quote-keys sibilant.quote-hash-keys\n            pair-strings (bulk-map static-keys (#(key value)\n                                           [ (if (and quote-keys (not (node? key 'string)))\n                                                 [\"\\\"\" (transpile key) \"\\\"\"]\n                                                 (transpile key))\n                                             \": \"\n                                             (transpile value)])))\n\n       (if dynamic-keys.length\n           (do\n            (var symbol (generate-symbol 'hash))\n            `(*scoped-without-source\n              (var @symbol (hash ...@static-keys))\n              (set @symbol ...@dynamic-keys)\n              @symbol))\n\n        (>= 1 pair-strings.length)\n           [\"{ \" (interleave \", \" pair-strings) \" }\"]\n           [\"{\" (indent (interleave \",\n\" pair-strings)) \"}\"]))","examples":[{"javascript":"{\n  k1: v1,\n  k2: v2\n}","sibilant":"(hash k1 v1 k2 v2)"},{"javascript":"{ \"key\": \"value\" }","sibilant":"(hash 'key 'value)"},{"javascript":"{ \"key\": { \"nested\": \"value\" } }","sibilant":"{ 'key { 'nested 'value } }"},{"javascript":"{\n  kv1: kv1,\n  kv2: kv2\n}","sibilant":"{ kv1& kv2& }"},{"javascript":"(function() {\n  var hash$1 = {  };\n  hash$1[variable] = 1;\n  return hash$1;\n}).call(this)","sibilant":"{ `variable 1 }"},{"javascript":"(function() {\n  var hash$2 = {  };\n  hash$2[variable] = variable;\n  return hash$2;\n}).call(this)","sibilant":"{ `variable & }"}],"tags":["collections","objects"]},{"name":"get","namespace":"core","type":"macro","description":"retreives object properties, potentially deeply. If more than one `keys` are provided,\n`get` fetches deeply into nested objects or arrays.\nWhen javascript dot notation can be used (`a.b = 3`), it is.\nOtherwise, bracket notation is used.","references":[],"arguments":["obj","...keys"],"definition":"(macro get (obj ...keys)\n       [(transpile obj)\n         (map keys (#(key)\n                     (var transpiled (transpile key)\n                          output (output-formatter transpiled))\n\n                     (if (match-regex? output \"^\\\"[a-zA-Z0-9_]+\\\"$\")\n                         [\".\" (replace-all output \"\\\"\" \"\") ]\n                         [\"[\" transpiled \"]\"])))])","examples":[{"javascript":"anObject.staticAttributeName","sibilant":"(get an-object 'static-attribute-name)"},{"javascript":"object[dynamicAttributeName]","sibilant":"(get object dynamic-attribute-name)"},{"javascript":"object[\"these attributes\"][\"can't be dotted\"]","sibilant":"(get object \"these attributes\" \"can't be dotted\")"},{"javascript":"array[0]","sibilant":"(get array 0)"},{"javascript":"object.a.b[c]","sibilant":"(get object 'a 'b c)"},{"javascript":"array[0][1][2]","sibilant":"(get array 0 1 2)"}],"tags":["collections","objects"]},{"name":"set","namespace":"core","type":"macro","description":"assigns object properties to `arr` in pairs, alternating between keys and values.\nWhen javascript dot notation can be used (`a.b = 3`), it is.  Otherwise, bracket notation is used","references":[],"arguments":["arr","...kv-pairs"],"definition":"(macro set (arr ...kv-pairs)\n       (interleave \"\n\" (bulk-map kv-pairs (#(k v) `(assign (get @arr @k) @v)))))","examples":[{"javascript":"anObject.staticAttributeName = \"value\";","sibilant":"(set an-object 'static-attribute-name 'value)"},{"javascript":"object[dynamicAttributeName] = \"key name determined at runtime\";","sibilant":"(set object dynamic-attribute-name \"key name determined at runtime\")"},{"javascript":"array[0] = \"first element of array\";","sibilant":"(set array 0 \"first element of array\")"},{"javascript":"object[\"can't be dotted\"] = \"value\";","sibilant":"(set object \"can't be dotted\" 'value)"},{"javascript":"object.firstAttribute = \"firstValue\";\nobject.secondAttribute = \"secondValue\";","sibilant":"(set object 'first-attribute 'first-value\n                      'second-attribute 'second-value)"}],"tags":["collections","objects"]},{"name":"keys","namespace":"core","type":"macro","description":"returns the property names of `obj`.","references":["https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys"],"arguments":["obj"],"definition":"(macro keys (obj)\n       '(Object.keys @obj))","examples":[{"javascript":"Object.keys({\n  a: 1,\n  b: 2\n})","sibilant":"(keys { a 1 b 2 })"}],"tags":["objects","collections"]},{"name":"delete","namespace":"core","type":"macro","description":"uses the javascript delete keyword on any number of `objects`.\n      Use in conjunction with `get` or dotted literal notation (a.b).","references":[],"arguments":["...objects"],"definition":"(macro delete (...objects)\n       (interleave \"\n\" (map objects (#(obj)\n                                 (as-statement [\"delete \" (transpile obj)])))))","examples":[{"javascript":"delete object.a;\ndelete object.b;","sibilant":"(delete object.a object.b)"},{"javascript":"delete object[attribute];\ndelete object[\"other attribute\"];","sibilant":"(delete (get object attribute) (get object \"other attribute\"))"}],"tags":["objects","collections"]},{"name":"each-key","namespace":"core","type":"macro","description":"iterates over each attribute in `obj`","references":[],"arguments":["as","obj","...body"],"definition":"(macro each-key (as obj ...body)\n       `(pipe @obj (keys)\n              (.for-each (lambda @{ args: (if (node? as 'expression) as [as])\n                                    node: this }\n                                 ...@body))))","examples":[{"javascript":"Object.keys({\n  a: 1,\n  b: 2\n}).forEach((function(key) {\n  /* src/macros/hash.sibilant:121:14 */\n\n  return console.log(key);\n}))","sibilant":"(each-key key { a 1 b 2 } (console.log key))"}],"tags":["objects","collections"]},{"name":"lambda","namespace":"core","type":"macro","description":"Defines a lambda/function/closure in Sibilant. Equivalent to\nthe `function` keyword in JavaScript. Most of the time `args` is a\nparen-wrapped list of arguments, which can include one triple-dotted\nsplat in the terminal position.  The last expression of `body` will be\nreturned. Aliased as `#`, as shown in examples.","references":[],"arguments":["args-or-options","...body"],"definition":"(macro lambda (args-or-options ...body)\n       (debug! 3 args-or-options)\n       (var args (or args-or-options.args args-or-options)\n            body (or args-or-options.body body)\n            node (or args-or-options.node this)\n            args (if (node? args 'expression 'bracket) args.contents\n                     (and (node? args) (empty? body)) (do (assign body [ args ]) [])\n                     (node? args 'brace) [ args ]\n                     args)\n            name (when args-or-options.name\n                       (|> args-or-options.name\n                           transpile\n                           output-formatter\n                           (replace-all \"\\\\W+\" \"$\")\n                           (.concat \"$\")))\n            rest (detect args (#-> (node? 'dots)))\n\n            destructured-args (map args (#(arg)\n                                          (if (node? arg 'bracket 'brace)\n                                              (do (var arg-name (generate-symbol (make-symbol-clue arg)))\n                                                  { arg-name &\n                                                    destructured-pair [ arg arg-name ] })\n                                              { arg-name arg })))\n\n            destructured-statements (|> [ (when (exists? rest) [ rest `(Array.prototype.slice.call arguments @(- args.length 1)) ])\n                                          ...(map destructured-args (#-> (get 'destructured-pair))) ]\n                                        flat-compact))\n\n       (assign node (detect\n                     [ node args-or-options.name args (first body) ]\n                     (#(n) (and (node? n) (get n 'file)))))\n\n\n       [\"(function\" (if name (\" \" name) \"\") \"(\"\n         (interleave \", \" (map destructured-args (#-> (get 'arg-name)))) \") {\"\n         (when (and sibilant.state.function-comments (or name node))\n               (indent [\"/*\"\n                         (when name (\" \" (sibilant.pretty-print args-or-options.name false)))\n                         (when node (\" \" node.file \":\" node.line \":\" node.col))\n                         \" */\"]))\n         (when destructured-statements.length (indent `(var ...@destructured-statements)))\n         (indent (apply ^do body))\n         \"})\"])","examples":[{"javascript":"(function(a, b, c) {\n  /* src/macros/lambda.sibilant:9:17 */\n\n  return ((a + b) / c);\n})","sibilant":"(lambda (a b c) (|> a (+ b) (/ c)))"},{"javascript":"(function(a, b, numbers) {\n  /* src/macros/lambda.sibilant:10:0 */\n\n  var numbers = Array.prototype.slice.call(arguments, 2);\n\n  console.log((\"a: \" + a + \", b: \" + b + \"\"));\n  return numbers.map((function() {\n    /* src/macros/lambda.sibilant:12:21 */\n  \n    return (arguments[0] + 10);\n  }));\n})","sibilant":"(lambda (a b ...numbers)\n        (console.log (\"a: \"a\", b: \"b\"\"))\n        (numbers.map (#-> (+ 10))))"},{"javascript":"(function(destructured_ob$1) {\n  /* src/macros/lambda.sibilant:13:0 */\n\n  var destructuredObject = destructured_ob$1.destructuredObject;\n\n  return destructuredObject();\n})","sibilant":"(#({ destructured-object }) (destructured-object))"},{"javascript":"(function(one_two_three$1) {\n  /* src/macros/lambda.sibilant:14:0 */\n\n  var one = one_two_three$1[0],\n      two = one_two_three$1[1],\n      three = one_two_three$1[2];\n\n  return {\n    one: one,\n    two: two,\n    three: three\n  };\n})","sibilant":"(#([ one two three ]) { one& two& three& })"},{"javascript":"document.body.addEventListener((function(event) {\n  /* src/macros/lambda.sibilant:17:5 */\n\n  console.log((\"click at point (\" + event.x + \",\" + event.y + \")\"));\n  return event.preventDefault();\n}))","sibilant":"(|> document.body\n    (.add-event-listener\n     (#(event)\n       (console.log (\"click at point (\"event.x\",\"event.y\")\"))\n       (event.prevent-default))))"}],"tags":["functions","language"]},{"name":"thunk","namespace":"core","type":"macro","description":"most often called as its alias, `#>`, thunk creates a function\nwith no named arguments. To refer to arguments anonymously, use #n,\nsuch as #0 for the first argument.","references":[],"arguments":["...body"],"definition":"(macro thunk (...body)\n       (var node this\n            lambda-options { node node args [] })\n\n       (when (not (node? (first body)))\n             (merge-into lambda-options (first body))\n             (assign body (rest body)))\n\n       '(lambda @lambda-options\n       ...@(map-node body\n                 (#(node)\n                   (if (node? node 'arg-placeholder)\n                       '(argument @(replace node.token \"^#\" \"\"))\n                       node)))))","examples":[{"javascript":"[ 1, 2, 3 ].map((function() {\n  /* src/macros/lambda.sibilant:70:34 */\n\n  return (1 + arguments[0]);\n}))","sibilant":"(.map [ 1 2 3 ] (#> (+ 1(argument'0'))))"},{"javascript":"window.setTimeout((function() {\n  /* src/macros/lambda.sibilant:71:38 */\n\n  return console.log(\"here\");\n}), 10)","sibilant":"(window.set-timeout (#> (console.log 'here)) 10)"}],"tags":["functions","language"]},{"name":"def","namespace":"core","type":"macro","description":"defines a function in the local scope. `name` is the\nvariable name that the function will be stored as.  Note that sibilant\ndoes *not* support hoisting. `args` is a paren-wrapped list of\narguments, as shown in the examples.  `body` can be any number of\nstatements, the last of which will be the return value of the\nfunction.","references":[],"arguments":["name","args","...body"],"definition":"(macro def (name args ...body)\n       (var node this)\n       (when (node? name 'expression)\n             (assign body [ args ...body ]\n                     args (merge-with name { contents (rest name.contents)})\n                     name (first name.contents)))\n\n                     \n     (if (undefined? name) (error \"invalid function definition. missing name.\")\n         (undefined? args) (error \"invalid function definition. missing arguments or return value.\"))\n\n     (sibilant.docs.record 'function (first sibilant.macros.search-path) name node)\n\n     (if (match? (regex \"\\\\.\") (|> name transpile output-formatter))\n         `(assign @name (lambda @{ name& args& node& body& }))\n         `(var @name (lambda @{ name& args& node& body& }))))","examples":[{"javascript":"var square = (function square$(x) {\n  /* square src/macros/lambda.sibilant:157:17 */\n\n  return (x * x);\n});","sibilant":"(def square (x) (* x x))"}],"tags":["language","functions"]},{"name":"call","namespace":"core","type":"macro","description":"This is the macro that is executed when a function is the first\nelement in an expression. Assuming that there is no macro named\n`a`, `(a b c)` internatlly compiles to `(call a b c)`. splats (`...`)\ncan be used in function calls.","references":[],"arguments":["fn-name","...args"],"definition":"(macro call (fn-name ...args)\n     (if (any? args (#> (node?(argument'0') 'dots)))\n           (macros.apply fn-name (macros.list ...args))\n           [ (transpile fn-name)\n                   \"(\" (interleave \", \" (map args transpile)) \")\" ]))","examples":[{"javascript":"a(b, c)","sibilant":"(call a b c)"},{"javascript":"a.apply(this, [ b ].concat(c))","sibilant":"(call a b ...c)"},{"javascript":"a.apply(this, args)","sibilant":"(call a ...args)"}],"tags":["functions","language"]},{"name":"send","namespace":"core","type":"macro","description":"calls the `method` on `object` as a function with `args` as the arguments","references":[],"arguments":["object","method","...args"],"definition":"(macro send (object method ...args)\n       [(transpile object) \".\" (transpile method)\n               \"(\" (interleave \", \" (map args transpile)) \")\"])","examples":[{"javascript":"object.method(firstArgument, secondArgument, thirdArgument)","sibilant":"(send object method first-argument second-argument third-argument)"}],"tags":["functions"]},{"name":"apply","namespace":"core","type":"macro","description":"calls the function `fn` with arguments passed as an array in `arglist`","references":[],"arguments":["fn","arglist"],"definition":"(macro apply (fn arglist)\n       '(.apply @fn this @arglist))","examples":[{"javascript":"myFunction.apply(this, [ firstArg, secondArg, thirdArg ])","sibilant":"(apply my-function [ first-arg second-arg third-arg ])"}],"tags":["functions"]},{"name":"scoped","namespace":"core","type":"macro","description":"executes the `body` inside of a self-executing function. The\nlast statement/expression of the body is returned.","references":[],"arguments":["...body"],"definition":"(macro scoped (...body)\n       '(.call (lambda @{node this args []} ...@body) this))","examples":[{"javascript":"(function() {\n  /* src/macros/lambda.sibilant:212:16 */\n\n  return true;\n}).call(this)","sibilant":"(scoped true)"},{"javascript":"(function() {\n  /* src/macros/lambda.sibilant:212:30 */\n\n  var a = 1;\n  return (a + 2);\n}).call(this)","sibilant":"(scoped (var a 1) (+ a 2))"}],"tags":["functions"]},{"name":"arguments","namespace":"core","type":"macro","description":"transforms function arguments into an array, using the Array prototype's slice","references":[],"arguments":["...args"],"definition":"(macro arguments (...args)\n       `(Array.prototype.slice.call arguments ...@args))","examples":[{"javascript":"Array.prototype.slice.call(arguments)","sibilant":"(arguments)"}],"tags":["functions"]},{"name":"argument","namespace":"core","type":"macro","description":"`get`s 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.","references":[],"arguments":["index"],"definition":"(macro argument (index)\n       '(get arguments @index))","examples":[{"javascript":"arguments[3]","sibilant":"(argument 3)"}],"tags":["functions"]},{"name":"simple-list","namespace":"core","type":"function","description":"This is the macro that is called when brackets (`[]`) are\nused. Emits a javascript array literal. Splats (`...`) can be used to\nin-line other arrays.","references":[],"arguments":["args"],"definition":"(def simple-list (args)\n                 [\"[ \" (interleave \", \" (map args (#(arg) arg.transpiled))) \" ]\"])","examples":[{"javascript":"[ 1, 2, 3, 4, 5 ]","sibilant":"(list 1 2 3 4 5)"},{"javascript":"[ \"a\", \"b\", \"c\", \"d\", \"e\" ]","sibilant":"[ 'a 'b 'c 'd 'e ]"},{"javascript":"[ a, b ].concat(c, [ d ], e)","sibilant":"[ a b ...c d ...e ]"}],"tags":["arrays","collections"]},{"name":"length","namespace":"core","type":"macro","description":"fetches length attribute from `arr`","references":[],"arguments":["arr"],"definition":"(macro length (arr)\n       '(get @arr 'length))","examples":[{"javascript":"[ 1, 2, 3 ].length","sibilant":"(length [ 1 2 3 ])"}],"tags":["arrays","collections"]},{"name":"first","namespace":"core","type":"macro","description":"`get`s the first element of `arr`","references":[],"arguments":["arr"],"definition":"(macro first (arr) `(get @arr 0))","examples":[{"javascript":"[ \"a\", \"b\", \"c\", \"d\", \"e\" ][0]","sibilant":"(first `[ a b c d e ])"}],"tags":["arrays","collections"]},{"name":"second","namespace":"core","type":"macro","description":"`get`s the second element of `arr`","references":[],"arguments":["arr"],"definition":"(macro second (arr) `(get @arr 1))","examples":[{"javascript":"[ \"a\", \"b\", \"c\", \"d\", \"e\" ][1]","sibilant":"(second `[ a b c d e ])"}],"tags":["arrays","collections"]},{"name":"third","namespace":"core","type":"macro","description":"`get`s the third element of `arr`","references":[],"arguments":["arr"],"definition":"(macro third (arr) `(get @arr 2))","examples":[{"javascript":"[ \"a\", \"b\", \"c\", \"d\", \"e\" ][2]","sibilant":"(third `[ a b c d e ])"}],"tags":["arrays","collections"]},{"name":"rest","namespace":"core","type":"macro","description":"fetches all but the first item of `arr`","references":[],"arguments":["arr"],"definition":"(macro rest (arr) '(.slice @arr 1))","examples":[{"javascript":"[ 1, 2, 3 ].slice(1)","sibilant":"(rest [ 1 2 3 ])"}],"tags":["arrays","collections"]},{"name":"last","namespace":"core","type":"macro","description":"fetches just the last element of `arr` by slicing.","references":[],"arguments":["arr"],"definition":"(macro last (arr) '(first (.slice @arr -1)))","examples":[{"javascript":"[ 1, 2, 3 ].slice(-1)[0]","sibilant":"(last [ 1 2 3 ])"}],"tags":["arrays","collections"]},{"name":"cons","namespace":"core","type":"macro","description":"builds an array with `first` as the zeroth index and the\nelements provided by array `rest` as the subsequent elements, as\nsiblings with `first`.","references":[],"arguments":["first","rest"],"definition":"(macro cons (first rest)\n       `(pipe\n         (list @first)\n         (.concat @rest)))","examples":[{"javascript":"[ 1 ].concat([ 2, 3, 4 ])","sibilant":"(cons 1 [ 2 3 4 ])"}],"tags":["arrays","collections","deprecated"]},{"name":"append","namespace":"core","type":"macro","description":"adds `additional` elements onto the right-side (tail) of `list`. deprecated","references":[],"arguments":["list","...additional"],"definition":"(macro append (list ...additional)\n       `(.concat @list (list ...@additional)))","examples":[{"javascript":"[ 1, 2, 3 ].concat([ 4, 5, 6 ])","sibilant":"(append [ 1 2 3 ] 4 5 6)"}],"tags":["arrays","collections","deprecated"]},{"name":"each","namespace":"core","type":"macro","description":"iterates over `array`, evaluating `body` once for each value in\n`array`.  If `item` is a literal name, that will be the variable into\nwhich the `array` element is yielded (current value).  If `item` is an expression, it\ncan contain the current value, the index, and the `array`.","references":["https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach"],"arguments":["item","array","...body"],"definition":"(macro each (item array ...body)\n       (var node this\n            args (if (node? item 'expression) item [item]))\n       `(|> @array\n            (.for-each (lambda @{ node& args& body& }))))","examples":[{"javascript":"[ 1, 2, 3 ].forEach((function(number) {\n  /* src/macros/lists.sibilant:92:17 */\n\n  return console.log(number);\n}))","sibilant":"(each number [ 1 2 3 ] (console.log number))"},{"javascript":"[ \"a\", \"b\", \"c\", \"d\" ].forEach((function(letter, index) {\n  /* src/macros/lists.sibilant:93:17 */\n\n  letters[letter] = index;\n  return console.log(letter.toUpperCase());\n}))","sibilant":"(each (letter index) `[ a b c d ]\n                       (set letters letter index)\n                       (pipe letter (.to-upper-case) (console.log)))"}],"tags":["arrays","language","collections"]},{"name":"includes?","namespace":"core","type":"macro","description":"returns true if `haystack` includes `needle`.  `haystack` can be a string or array/list.","references":[],"arguments":["haystack","needle"],"definition":"(macro includes? (haystack needle)\n       `(pipe @haystack (.index-of @needle) (!= -1)))","examples":[{"javascript":"\"hello\".indexOf(\"h\") !== -1","sibilant":"(includes? 'hello 'h)"},{"javascript":"[ \"Veni\", \"vidi\", \"vici\" ].indexOf(\"vidi\") !== -1","sibilant":"(includes? `[ Veni vidi vici] 'vidi)"}],"tags":["arrays","collections"]},{"name":"excludes?","namespace":"core","type":"macro","description":"returns true if `haystack` does NOT include `needle`.\n`haystack` can be a string or array/list","references":[],"arguments":["haystack","needle"],"definition":"(macro excludes? (haystack needle)\n       `(pipe @haystack (.index-of @needle) (= -1)))","examples":[{"javascript":"\"hello\".indexOf(10) === -1","sibilant":"(excludes? 'hello 10)"},{"javascript":"[ \"Veni\", \"vidi\", \"vici\" ].indexOf(\"attenti\") === -1","sibilant":"(excludes? `[ Veni vidi vici] 'attenti)"}],"tags":["arrays","collections"]},{"name":"while","namespace":"core","type":"macro","description":"evaluates the `body` as long as `condition` is truthy,\nreturning the value of the last expression in `block` when `condition`\nceases to be truthy. See also `until`","references":[],"arguments":["condition","...body"],"definition":"(macro while (condition ...body)\n       (var symbol (generate-symbol 'while))\n       '(*scoped-without-source\n         (var @symbol)\n         @{ type 'output\n               contents [\"while (\" (transpile condition) \") {\"\n                          (indent '(assign @symbol (*scoped-without-source ...@body)))\n                          \"}\"] }\n         @symbol))","examples":[{"javascript":"(function() {\n  var while$1 = undefined;\n  while (5 > i) {\n    while$1 = (function() {\n      console.log(i);\n      return ((i)--);\n    }).call(this);\n  };\n  return while$1;\n}).call(this)","sibilant":"(while (> 5 i) (console.log i) (decr i))"}],"tags":["loops","flowControl"]},{"name":"until","namespace":"core","type":"macro","description":"evaluates the `body` as long as `condition` is falsy,\nreturning the value of the last expression in `block` when `condition`\nceases to be falsy. See also `while`","references":[],"arguments":["condition","...body"],"definition":"(macro until (condition ...body)\n       '(while (not @condition) ...@body))","examples":[{"javascript":"(function() {\n  var while$2 = undefined;\n  while (!(5 < i)) {\n    while$2 = (function() {\n      console.log(i);\n      return ((i)++);\n    }).call(this);\n  };\n  return while$2;\n}).call(this)","sibilant":"(until (< 5 i) (console.log i) (incr i))"}],"tags":["loops","flowControl"]},{"name":"macro","namespace":"core","type":"macro","description":"Defines a macro. The arguments are the same as for `def`: the\nfunction defined with `args` and `body` will be stored in the current\nmacro namespace as `name`. The last statement of `body` will be\nreturned, and should either be an array of strings and/or sibilant ast\nnodes, or a sibilant ast node. Most of the time this is accomplished\nthrough use of `quote` and `unquote`.  Note that there are no examples\nfor this macro, but hopefully there will be a tutorial.","references":[],"arguments":["name","args","...body"],"definition":"(macro macro (name args ...body)\n     (var name-tr (output-formatter (transpile name))\n          options { name name args args node this}\n          js (|> `(lambda @options ...@body)\n                 transpile\n                 output-formatter))\n\n     (debug! 2 js)\n\n     (sibilant.docs.record 'macro (first sibilant.macros.search-path) name this)\n\n     (var evaled-js (try (eval js)\n                         (do\n                          (console.log e.message)\n                          (console.log (|> e.stack (.split \"\n\") second red))\n                          (console.log (\"error in parsing macro \"\n                                        (sibilant.pretty-print name) \":\n\" js)))))\n\n     (set sibilant.macros.namespace name-tr evaled-js)\n\n     undefined)","examples":[],"tags":["language","macros"]},{"name":"meta","namespace":"core","type":"macro","description":"Equivalent to defining a macro and immediately evaluating it.\nEvaluates `body` at compile time in the compiler context.  Note that\nthe 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.","references":[],"arguments":["...body"],"definition":"(macro meta (...body)\n     (var js (output-formatter (transpile (^scoped ...body))))\n     (when sibilant.debug (console.log js))\n     (|> js eval output-formatter))","examples":[{"javascript":"// 0.5.6","sibilant":"(comment (meta (sibilant.version)))"},{"javascript":"\"0.5.6\"","sibilant":"(quote (meta (sibilant.version)))"}],"tags":["language","macros"]},{"name":"alias-macro","namespace":"core","type":"macro","description":"stores a duplicate copy of `current-macro-name` as\n`new-macro-name` in current namespace.  No output.","references":[],"arguments":["current-macro-name","new-macro-name"],"definition":"(macro alias-macro (current-macro-name new-macro-name)\n       (var current-macro-name (output-formatter (transpile current-macro-name))\n            new-macro-name (output-formatter (transpile new-macro-name)))\n       (set sibilant.macros.namespace\n            new-macro-name (get sibilant.macros.namespace current-macro-name))\n       null)","examples":[],"tags":["macros"]},{"name":"delete-macro","namespace":"core","type":"macro","description":"deletes each macro name in `macro-names` from the current namespace. Use carefully","references":[],"arguments":["...macro-names"],"definition":"(macro delete-macro (...macro-names)\n       (each macro-name macro-names\n             (delete (get sibilant.macros.namespace (output-formatter (transpile macro-name)))))\n       null)","examples":[],"tags":["macros","language"]},{"name":"rename-macro","namespace":"core","type":"macro","description":"moves macro from `current-macro-name` to `new-macro-name`. Use carefully","references":[],"arguments":["current-macro-name","new-macro-name"],"definition":"(macro rename-macro (current-macro-name new-macro-name)\n       (^alias-macro current-macro-name new-macro-name)\n       (^delete-macro current-macro-name)\n       null)","examples":[],"tags":["macros","language"]},{"name":"+","namespace":"core","type":"macro","description":"adds `args` using the javascript `+` operator. Since javascript\noverloads this for string concatenation, this macro can be used for\nthis as well.","references":[],"arguments":["...args"],"definition":"(macro +   (...args)\n       [\"(\" (interleave \" + \" (map args transpile)) \")\"])","examples":[{"javascript":"(1 + 2 + 3)","sibilant":"(+ 1 2 3)"},{"javascript":"(\"hello\" + \"world\")","sibilant":"(+ 'hello 'world)"}],"tags":["strings","numbers"]},{"name":"-","namespace":"core","type":"macro","description":"subtracts each subsequent element of `args`","references":[],"arguments":["...args"],"definition":"(macro -   (...args)\n       [\"(\" (interleave \" - \" (map args transpile)) \")\"])","examples":[{"javascript":"(2 - 1)","sibilant":"(- 2 1)"},{"javascript":"(10 - 5 - 1)","sibilant":"(- 10 5 1)"}],"tags":["numbers"]},{"name":"*","namespace":"core","type":"macro","description":"multiplies elements of `args`","references":[],"arguments":["...args"],"definition":"(macro *   (...args)\n       [\"(\" (interleave \" * \" (map args transpile)) \")\"])","examples":[{"javascript":"(3 * 4 * 5)","sibilant":"(* 3 4 5)"}],"tags":["numbers"]},{"name":"/","namespace":"core","type":"macro","description":"divides each subsequent element of `args`","references":[],"arguments":["...args"],"definition":"(macro /   (...args)\n           [\"(\" (interleave \" / \" (map args transpile)) \")\"])","examples":[{"javascript":"(1 / 2)","sibilant":"(/ 1 2)"},{"javascript":"(1 / 2 / 3)","sibilant":"(/ 1 2 3)"}],"tags":["numbers"]},{"name":"mod","namespace":"core","type":"macro","description":"modulus operator","references":[],"arguments":["...args"],"definition":"(macro mod (...args)\n       [\"(\" (interleave \" % \" (map args transpile)) \")\"])","examples":[{"javascript":"(10 % 2)","sibilant":"(mod 10 2)"}],"tags":["numbers"]},{"name":"incr-by","namespace":"core","type":"macro","description":"increments `item` by `increment`","references":[],"arguments":["item","increment"],"definition":"(macro incr-by (item increment)\n       [ (transpile item) \" += \" (transpile increment)])","examples":[{"javascript":"n += 5","sibilant":"(incr-by n 5)"}],"tags":["numbers"]},{"name":"incr","namespace":"core","type":"macro","description":"increments item by 1","references":[],"arguments":["item"],"definition":"(macro incr (item)\n       [\"((\" (transpile item) \")++)\"])","examples":[{"javascript":"((i)++)","sibilant":"(incr i)"}],"tags":["numbers"]},{"name":"decr","namespace":"core","type":"macro","description":"decrements item by 1","references":[],"arguments":["item"],"definition":"(macro decr (item) [\"((\" (transpile item) \")--)\"])","examples":[{"javascript":"((i)--)","sibilant":"(decr i)"}],"tags":["numbers"]},{"name":"or","namespace":"core","type":"macro","description":"short circuiting operator returns the first element of `args` that evaluates to be truthy","references":[],"arguments":["...args"],"definition":"(macro or  (...args)\n       [\"(\" (interleave \" || \" (map args transpile)) \")\"])","examples":[{"javascript":"(1 === 2 || typeof [] === \"string\" || \"one is not two and an array is not a string\")","sibilant":"(or (= 1 2) (string? []) \"one is not two and an array is not a string\")"}],"tags":["conditional","flowControl","booleans"]},{"name":"and","namespace":"core","type":"macro","description":"returns the last element if all elements of `args` are truthy, or the\nfirst non-truthy element if it exists","references":[],"arguments":["...args"],"definition":"(macro and (...args)\n       (if (= 1 (length args))\n           (transpile (first args))\n           `(parens ...@(interleave \" && \" (map args transpile)))))","examples":[{"javascript":"(typeof \"string\" === \"string\" && typeof 10 === \"number\" && 1 === 1)","sibilant":"(and (string? \"string\") (number? 10) (= 1 1))"}],"tags":["booleans"]},{"name":"not","namespace":"core","type":"macro","description":"boolean negation, as determined by javascript truthiness","references":["https://developer.mozilla.org/en-US/docs/Glossary/Truthy","https://developer.mozilla.org/en-US/docs/Glossary/Falsy"],"arguments":["exp"],"definition":"(macro not (exp)\n       [\"!\" `(parens @exp) ])","examples":[{"javascript":"!(typeof 1 === \"string\")","sibilant":"(not (string? 1))"}],"tags":["booleans"]},{"name":"as-boolean","namespace":"core","type":"macro","description":"double-negates `expr`, converting it to a boolean","references":[],"arguments":["expr"],"definition":"(macro as-boolean (expr)\n       `(parens @\"!!\" (parens @expr)))","examples":[{"javascript":"(!!(0))","sibilant":"(as-boolean 0)"},{"javascript":"(!!(true))","sibilant":"(as-boolean true)"}],"tags":["type","booleans"]},{"name":"as-number","namespace":"core","type":"macro","description":"coerces `expr` to a number.  Currently implemented through the use of Number()","references":["https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number"],"arguments":["expr"],"definition":"(macro as-number (expr) `(Number @expr))","examples":[{"javascript":"Number(\"0.1\")","sibilant":"(as-number \"0.1\")"},{"javascript":"Number(0.1)","sibilant":"(as-number 0.1)"}],"tags":["type","numbers"]},{"name":"new","namespace":"core","type":"macro","description":"uses the javascript new keyword to construct an object using\n      `constructor`, with `args` passed as arguments to the constructor.","references":[],"arguments":["constructor","...args"],"definition":"(macro new (constructor ...args)\n       [\"(new \" '(call @constructor ...@args) \")\"])","examples":[{"javascript":"(new RegExp(\"hello\", \"g\"))","sibilant":"(new RegExp \"hello\" 'g)"}],"tags":["functions"]},{"name":"typeof","namespace":"core","type":"macro","description":"exposes the javascript typeof operator. most often, predicates\nsuch as `string?`, `function?`, `number?`, etc are preferred.","references":[],"arguments":["thing"],"definition":"(macro typeof (thing) [\"typeof \" (transpile thing)])","examples":[{"javascript":"typeof 5","sibilant":"(typeof 5)"}],"tags":["type"]},{"name":"comment","namespace":"core","type":"macro","description":"inserts `contents` transpiled to javascript as a comment in the\noutput file, removing it from execution.","references":[],"arguments":["...contents"],"definition":"(macro comment (...contents)\n       (map contents (#(content)\n                       [\"// \"(recurse-map (transpile content)\n                                    (#(item)\n                                      (ternary item\n                                               (pipe item transpile output-formatter\n                                                     (.replace (regex \"\n\" 'g) \"\n// \"))\n                                               null)))])))","examples":[{"javascript":"// (function() {\n//   /* src/macros/misc.sibilant:25:23 */\n// \n//   return 1;\n// }).call(this)","sibilant":"(comment (scoped 1))"}],"tags":["language"]},{"name":"log-pretty","namespace":"core","type":"macro","description":"outputs debug information about `arg`.  If `label` is\nomitted (only one argument is provided), the name of the variable or\nexpression of that first expression will be logged. Aliased as `pretty-log`","references":[],"arguments":["label","arg"],"definition":"(macro log-pretty (label arg)\n       (var node this)\n       (when (undefined? arg)\n             (assign arg label\n                     label [\"\\\"\" (prettify label false) \"\\\"\"]))\n       `(console.log (concat @[\"\\\"\" node.file \":\" node.line \"\\\"\"] \" \" @label \" = \" (prettify @arg))))","examples":[{"javascript":"console.log((\"src/macros/misc.sibilant:40\" + \" \" + \"myLabel\" + \" = \" + prettify(value)))","sibilant":"(log-pretty 'my-label value)"},{"javascript":"console.log((\"src/macros/misc.sibilant:41\" + \" \" + \"(+ 1 2)\" + \" = \" + prettify((1 + 2))))","sibilant":"(log-pretty (+ 1 2))"}],"tags":["language"]},{"name":"throw","namespace":"core","type":"macro","description":"throws a new javascript error with arguments as the string","references":[],"arguments":["error"],"definition":"(macro throw (error)\n       [\"throw \" (transpile error)])","examples":[{"javascript":"throw (new Error(\"could not find matching socks\"))","sibilant":"(throw (new Error \"could not find matching socks\"))"}],"tags":["language"]},{"name":"join","namespace":"core","type":"macro","description":"combines elements of array `arr` into a string, inserting\n`glue` string between each element.  if `glue` is omitted (only one\nargument provided), the elements of `arr` are joined with an empty\nstring","references":[],"arguments":["arr","glue"],"definition":"(macro join (arr glue)\n       (if (and (defined? glue) (undefined? arr))\n           (assign arr glue glue undefined))\n       `(.join @arr @(or glue \"\\\"\\\"\")))","examples":[{"javascript":"[ \"a\", \"few\", \"words\" ].join(\", \")","sibilant":"(join `[ a few words ]  \", \" )"},{"javascript":"[ \"several\", \"more\", \"words\" ].join(\"\")","sibilant":"(join `[ several more words ])"}],"tags":["arrays","collections","strings"]},{"name":"source-mapping-url","namespace":"core","type":"macro","description":"inserts a pragma for source-mapping-url","references":[],"arguments":["url"],"definition":"(macro source-mapping-url (url)\n       [ \"//# sourceMappingURL=\" (|> url transpile output-formatter eval) \"\n\" ])","examples":[{"javascript":"//# sourceMappingURL=/example.map\n","sibilant":"(source-mapping-url \"/example.map\")"}],"tags":[]},{"name":"include","namespace":"core","type":"macro","description":"loads and transpiles content from another file or `files` as if\nit were written in-line.  This is distinct from node's `require`\nfunction, as `include` will drop the output javascript directly in\nplace of the include statement.  Namespaced macros defined in the\nincluded file will not by default be imported into the current macro\nnamespace.  Include will append \".sibilant\" to the end of files, and\nwill also use node's module system to resolve sibilant files from\nother packages.  As a noncompiling example, it is possible to `npm\ninstall sibilant-react` and `(include \"sibilant-react/macros\")`,\nwhich introduces the `react` macro namespace.","references":[],"arguments":["...files"],"definition":"(macro include (...files)\n     (pipe files\n           (.map (#(file)\n                   (sibilant.with-default-search-path\n                    (#>\n                     (pipe file\n                           transpile\n                           output-formatter\n                           eval\n                           sibilant.include)))))\n           (interleave \"\n\")))","examples":[],"tags":["language"]},{"name":"pipe","namespace":"core","type":"macro","description":"inserts the result of each subsequent call in `calls` as the\nsecond argument to the next macro. This is very much akin to clojure's\nthread-first arrow or elixir's pipe operator.  Advanced: in order to\nthread the preceding topic into a position other than the second\nposition, use the character `#` to specify topic position","references":["https://clojuredocs.org/clojure.core/-%3E","http://elixir-lang.org/docs/v1.0/elixir/Kernel.html#|>/2"],"arguments":["...calls"],"definition":"(macro pipe (...calls)\n       (inject undefined calls\n               (#(value item)\n                 (if (undefined? value) item\n                     (scoped\n                      (var cloned (if (node? item 'literal 'dots)\n                                      `(@item)\n                                      (clone item)))\n\n                      (var placeholder (detect cloned.contents\n                                               (#(node)\n                                                 (and (node? node 'other-char)\n                                                      (= \"#\" node.token))))\n                           placeholder-index (cloned.contents.index-of placeholder)\n\n                           placeholder-boundaries (if placeholder\n                                                      [ placeholder-index (+ 1 placeholder-index) ]\n                                                      [ 1 1 ]))\n\n                      (merge-into cloned\n                                  { contents [ ...(cloned.contents.slice 0 (first placeholder-boundaries))\n                                               value\n                                               ...(cloned.contents.slice (second placeholder-boundaries)) ] }))))))","examples":[{"javascript":"(\"a b c d\".toUpperCase().replace(\"A\", \"X\").split(\" \")[0] + \" marks the spot\")","sibilant":"(pipe \"a b c d\"\n      .to-upper-case\n      (.replace \"A\" \"X\")\n      (.split \" \")\n      first\n      (concat \" marks the spot\"))"},{"javascript":"JSON.stringify(JSON.parse(\"{\\\"a\\\": {\\\"b\\\": [ 1, 2, 3 ]}}\").a)","sibilant":"(pipe \"{\\\"a\\\": {\\\"b\\\": [ 1, 2, 3 ]}}\"\n      JSON.parse\n      (get 'a)\n      JSON.stringify)"},{"javascript":"var a = (3 + 1);","sibilant":"(pipe 3 (+ 1) (var a #))"}],"tags":["language","flowControl"]},{"name":"pipe-thunk","namespace":"core","type":"macro","description":"most often called as its alias, `#->`, pipe-thunk applies a pipe chain to the argument of a function and returns the result","references":[],"arguments":["...calls"],"definition":"(macro pipe-thunk (...calls) `(thunk @{ node this } (pipe #0 ...@calls)))","examples":[{"javascript":"[ \"a\", \"b\", \"c\" ].map((function() {\n  /* src/macros/pipe.sibilant:54:34 */\n\n  return (arguments[0].toUpperCase() + \" is a letter\");\n}))","sibilant":"(.map `[ a b c ] (#-> (.to-upper-case) (concat \" is a letter\")))"}],"tags":["functions","language"]},{"name":"tap","namespace":"core","type":"macro","description":"generates a function intended to be used in conjunction with\n`pipe` or `pipe-thunk` that does not interrupt the main flow of the\n`pipe`","references":[],"arguments":["thing","...body"],"definition":"(macro tap (thing ...body)\n       `((#> (|> #0 ...@body) #0) @thing))","examples":[{"javascript":"((function() {\n  /* src/macros/pipe.sibilant:66:9 */\n\n  console.log((arguments[0] + 5));\n  return arguments[0];\n})(2) * 10)","sibilant":"(|> 2 (tap (+ 5) console.log) (* 10))"},{"javascript":"(function() {\n  /* src/macros/pipe.sibilant:64:17 */\n\n  return (function() {\n    /* src/macros/pipe.sibilant:66:9 */\n  \n    console.log(arguments[0]);\n    return arguments[0];\n  })(arguments[0].toUpperCase()).split(\" \");\n})","sibilant":"(#-> .to-upper-case (tap console.log) (.split \" \"))"}],"tags":["language","flowControl"]},{"name":"zero?","namespace":"core","type":"macro","description":"predicate to test for equality with zero","references":[],"arguments":["item"],"definition":"(macro zero? (item) '(= @item 0))","examples":[{"javascript":"n === 0","sibilant":"(zero? n)"}],"tags":["numbers"]},{"name":"empty?","namespace":"core","type":"macro","description":"returns true if the array `arr` has a length of zero","references":[],"arguments":["arr"],"definition":"(macro empty? (arr)\n       `(= 0 (length @arr)))","examples":[{"javascript":"0 === [].length","sibilant":"(empty? [])"}],"tags":["arrays","collections"]},{"name":"odd?","namespace":"core","type":"macro","description":"returns true if `number` is not divisible by 2","references":[],"arguments":["number"],"definition":"(macro odd? (number)\n       '(= 1 (mod @number 2)))","examples":[{"javascript":"1 === (5 % 2)","sibilant":"(odd? 5)"}],"tags":["numbers"]},{"name":"even?","namespace":"core","type":"macro","description":"returns true if `number` is divisible by 2 with no remainder","references":[],"arguments":["number"],"definition":"(macro even? (number)\n       '(= 0 (mod @number 2)))","examples":[{"javascript":"0 === (10 % 2)","sibilant":"(even? 10)"}],"tags":["numbers"]},{"name":"string?","namespace":"core","type":"macro","description":"returns true if all of the `things` are javascript strings","references":[],"arguments":["...things"],"definition":"(macro string? (...things)\n       '(and ...@(map things (#(thing) '(= (typeof @thing) 'string)))))","examples":[{"javascript":"typeof testObject === \"string\"","sibilant":"(string? test-object)"},{"javascript":"(typeof \"yes\" === \"string\" && typeof \"yes\" === \"string\" && typeof \"yes\" === \"string\")","sibilant":"(string? 'yes 'yes 'yes)"}],"tags":["strings","type"]},{"name":"function?","namespace":"core","type":"macro","description":"returns true if all of the `things` are functions","references":[],"arguments":["...things"],"definition":"(macro function? (...things)\n       '(and ...@(map things (#(thing) '(= (typeof @thing) 'function)))))","examples":[{"javascript":"typeof fn === \"function\"","sibilant":"(function? fn)"},{"javascript":"(typeof err === \"function\" && typeof cb === \"function\")","sibilant":"(function? err cb)"}],"tags":["functions","type"]},{"name":"undefined?","namespace":"core","type":"macro","description":"returns true if all of the `things` are undefined, as tested\nwith `typeof`, not equality with literal undefined. This is the\ninverse of `defined?`","references":[],"arguments":["...things"],"definition":"(macro undefined? (...things)\n       '(and ...@(map things (#(thing) '(= (typeof @thing) 'undefined)))))","examples":[{"javascript":"typeof argument === \"undefined\"","sibilant":"(undefined? argument)"},{"javascript":"(typeof 1 === \"undefined\" && typeof 2 === \"undefined\" && typeof undefined === \"undefined\")","sibilant":"(undefined? 1 2 undefined)"}],"tags":["type"]},{"name":"defined?","namespace":"core","type":"macro","description":"returns true if none of the `things` are undefined, as tested\nwith `typeof`. This is the inverse of `undefined?`","references":[],"arguments":["...things"],"definition":"(macro defined? (...things)\n       '(and ...@(map things (#(thing) '(!= (typeof @thing) 'undefined)))))","examples":[{"javascript":"typeof variable !== \"undefined\"","sibilant":"(defined? variable)"},{"javascript":"(typeof var1 !== \"undefined\" && typeof var2 !== \"undefined\" && typeof var3 !== \"undefined\")","sibilant":"(defined? var1 var2 var3)"}],"tags":["type"]},{"name":"number?","namespace":"core","type":"macro","description":"returns true if all of the `things` are numbers, as tested\nwith `typeof`","references":[],"arguments":["...things"],"definition":"(macro number? (...things)\n       '(and ...@(map things (#(thing) '(= (typeof @thing) 'number)))))","examples":[{"javascript":"typeof 1 === \"number\"","sibilant":"(number? 1)"},{"javascript":"(typeof 1 === \"number\" && typeof 2 === \"number\" && typeof 3 === \"number\")","sibilant":"(number? 1 2 3)"}],"tags":["numbers","type"]},{"name":"array?","namespace":"core","type":"macro","description":"returns true if `thing` is an array in javascript. aliased as\n`list?`.","references":[],"arguments":["thing"],"definition":"(macro array? (thing)\n       `(and\n         @thing\n         (= 'object (typeof @thing))\n         (= 'Array (get @thing 'constructor 'name))))","examples":[{"javascript":"(arr && \"object\" === typeof arr && \"Array\" === arr.constructor.name)","sibilant":"(array? arr)"}],"tags":["type","arrays"]},{"name":"hash?","namespace":"core","type":"macro","description":"returns true if `thing` is an object that is not an array in javascript. aliased as\n`object?`.","references":[],"arguments":["thing"],"definition":"(macro hash? (thing)\n       `(and (= 'object (typeof @thing))\n             (!= @thing null)\n             (!= (get @thing 'constructor 'name) 'Array)))","examples":[{"javascript":"(\"object\" === typeof arr && arr !== null && arr.constructor.name !== \"Array\")","sibilant":"(object? arr)"}],"tags":["type","objects"]},{"name":"instance-of?","namespace":"core","type":"macro","description":"uses the javascript `instanceof` operator to check if `item` is of `type`.","references":[],"arguments":["item","type"],"definition":"(macro instance-of? (item type)\n       `(parens (transpile item) \" instanceof \" (transpile type)))","examples":[{"javascript":"(transpile(item)\" instanceof \"transpile(type))","sibilant":"(instance-of? (new Date) Date)"}],"tags":["language","type"]},{"name":"exists?","namespace":"core","type":"macro","description":"similar to the javascript truthiness predicate `as-boolean`, returns true unless the `thing` is undefined or null","references":[],"arguments":["thing"],"definition":"(macro exists? (thing)\n       `(and (defined? @thing) (!= @thing null)))","examples":[{"javascript":"(typeof window !== \"undefined\" && window !== null)","sibilant":"(exists? window)"}],"tags":["type"]},{"name":"has-key?","namespace":"core","type":"macro","description":"checks if `object` has property `key`.  returns true or false.","references":[],"arguments":["object","key"],"definition":"(macro has-key? (object key)\n       `(.has-own-property @object @key))","examples":[{"javascript":"object.hasOwnProperty(\"a\")","sibilant":"(has-key? object 'a)"}],"tags":["objects","collections"]},{"name":"lower-case?","namespace":"core","type":"macro","description":"checks if a string is identical to the lower-cased version of itself","references":[],"arguments":["str"],"definition":"(macro lower-case? (str)\n       `(and\n         (!= (.to-upper-case @str) @str)\n         (= (.to-lower-case @str) @str)))","examples":[{"javascript":"(\"abc\".toUpperCase() !== \"abc\" && \"abc\".toLowerCase() === \"abc\")","sibilant":"(lower-case? \"abc\")"}],"tags":["strings"]},{"name":"upper-case?","namespace":"core","type":"macro","description":"checks if a string is identical to the upper-cased version of itself","references":[],"arguments":["str"],"definition":"(macro upper-case? (str)\n       `(and\n         (!= (.to-lower-case @str) @str)\n         (= (.to-upper-case @str) @str)))","examples":[{"javascript":"(\"abc\".toUpperCase() !== \"abc\" && \"abc\".toLowerCase() === \"abc\")","sibilant":"(lower-case? \"abc\")"}],"tags":["strings"]},{"name":"match?","namespace":"core","type":"macro","description":"returns true if the `string` matches `regexp`.  Deprecated in\n      preference to `.match` (`send` dot-invocation).","references":[],"arguments":["regexp","string"],"definition":"(macro match? (regexp string)\n       '(.match @string @regexp))","examples":[{"javascript":"\"word\".match((new RegExp(\"^[a-z]+$\", \"i\")))","sibilant":"(match? (regex \"^[a-z]+$\" 'i) 'word)"}],"tags":["regex","strings"]},{"name":"match-regex?","namespace":"core","type":"macro","description":"similar to `match?` but builds a regex out of the `pattern` and `flags`.","references":[],"arguments":["string","pattern","flags"],"definition":"(macro match-regex? (string pattern flags)\n       '(match? (regex @pattern @flags) @string))","examples":[{"javascript":"\"word\".match((new RegExp(\"^[a-z]+$\", \"i\")))","sibilant":"(match-regex? 'word \"^[a-z]+$\" 'i)"}],"tags":["regex","strings"]},{"name":"replace","namespace":"core","type":"macro","description":"replaces the first occurance of `pattern` (as a regex) with `replacement`","references":[],"arguments":["string","pattern","replacement"],"definition":"(macro replace (string pattern replacement)\n       '(.replace @string\n              (regex @pattern)\n              @replacement))","examples":[{"javascript":"\"hello world\".replace((new RegExp(\"l+o\", undefined)), \"y there,\")","sibilant":"(replace \"hello world\" \"l+o\" \"y there,\")"}],"tags":["regex","strings"]},{"name":"replace-all","namespace":"core","type":"macro","description":"replaces all occurrances of `pattern` (as a regex) with `replacement`","references":[],"arguments":["string","pattern","replacement"],"definition":"(macro replace-all (string pattern replacement)\n       '(.replace @string (regex @pattern 'g) @replacement))","examples":[{"javascript":"\"503-555-1212\".replace((new RegExp(\"[0-9]\", \"g\")), \"#\")","sibilant":"(replace-all \"503-555-1212\" \"[0-9]\" \"#\")"}],"tags":["regex","strings"]},{"name":"regex","namespace":"core","type":"macro","description":"builds a regex using `pattern` and `flags` as arguments to the RegExp constructor","references":[],"arguments":["pattern","flags"],"definition":"(macro regex (pattern flags)\n       '(new RegExp @pattern @(or flags 'undefined)))","examples":[{"javascript":"(new RegExp(\"[0-9]+\", undefined))","sibilant":"(regex \"[0-9]+\")"},{"javascript":"(new RegExp(\"0x[0-9a-f]+\", \"i\"))","sibilant":"(regex \"0x[0-9a-f]+\" 'i)"}],"tags":["regex"]},{"name":"switch","namespace":"core","type":"macro","description":"uses the javascript switch construction to test equality.  documentation todo: needs better description","references":[],"arguments":["obj","...cases"],"definition":"(macro switch (obj ...cases)\n       [\"(function() {\"\n         (indent [\"switch(\" (transpile obj) \") {\"\n                   (map cases (#(case-def)\n                                (var case-name-node (first case-def.contents)\n                                     case-labels (if (node? case-name-node 'expression 'bracket)\n                                                     case-name-node.contents\n                                                     [case-name-node])\n                                     case-string (interleave \"\n\"\n                                                             (map case-labels (#(c)\n                                                                                (if (= 'default c.token)\n                                                                                    \"default:\"\n                                                                                    [\"case \" (transpile c) \":\"])))))\n                                [\"\n\" case-string (indent '(do ...@(rest case-def.contents)))]))\n                   \"}\"])\n         \"}).call(this)\"])","examples":[{"javascript":"(function() {\n  switch(char) {\n  case \"a\":\n    return \"it was an a\";\n  \n  case \"b\":\n    console.log(\"found a b!\");\n    return \"it was a b\";\n  \n  case 1:\n  case 2:\n  case 3:\n  case 4:\n  case 5:\n    return \"it was an integer from one to five\";\n  \n  default:\n    return \"not sure\";\n  }\n}).call(this)","sibilant":"(switch char\n                         ('a \"it was an a\")\n                         ('b (console.log \"found a b!\")\n                             \"it was a b\")\n                         ([1 2 3 4 5] \"it was an integer from one to five\")\n                         (default \"not sure\"))"}],"tags":["flowControl","conditional","deprecated"]},{"name":"var","namespace":"core","type":"macro","description":"registers variables in `pairs` inside of the current scope using the javascript var keyword.\ndestructuring from arrays and objects is also supported, as shown in the examples. Note: `:` and `,` are always ignored.","references":[],"arguments":["...pairs"],"definition":"(macro var (...pairs)\n       (as-statement\n        [\"var \" (|> pairs\n                    destructure\n                    (map (#(pair) [(first pair) \" = \" (second pair)]))\n                    (interleave \",\n    \")) ]))","examples":[{"javascript":"var a = undefined;","sibilant":"(var a)"},{"javascript":"var a = 1,\n    b = 2;","sibilant":"(var a: 1, b: 2)"},{"javascript":"var a = [ 1, 2, 3 ],\n    b = a[0],\n    c = a[1],\n    d = a[2];","sibilant":"(var a [ 1 2 3 ]\n     [ b c d ] a)"},{"javascript":"var attribute = ({ attribute: \"hi\" }).attribute;","sibilant":"(var {attribute} { attribute: 'hi })"},{"javascript":"var log = console.log,\n    dir = console.dir;","sibilant":"(var {log dir} console)"},{"javascript":"var a = ({\n  a: 1,\n  b: 2\n}).a,\n    c_d$1 = {\n  c: 3,\n  d: 4\n},\n    c = c_d$1.c,\n    d = c_d$1.d,\n    c_d$1 = undefined;","sibilant":"(var {a}: {a 1 b 2},\n     {c d}: {c 3 d 4})"}],"tags":["variables","language"]},{"name":"const","namespace":"core","type":"macro","description":"registers constants in `pairs` inside of the current scope using the javascript const keyword.\ndestructuring from arrays and objects is also supported, as shown in the examples. Note: `:` and `,` are always ignored.","references":[],"arguments":["...pairs"],"definition":"(macro const (...pairs)\n      (as-statement\n        [\"const \" (|> pairs\n                    destructure\n                    (map (#(pair) [(first pair) \" = \" (second pair)]))\n                    (interleave \",\n    \")) ]))","examples":[{"javascript":"const a = undefined;","sibilant":"(const a)"},{"javascript":"const a = 1,\n    b = 2;","sibilant":"(const a: 1, b: 2)"},{"javascript":"const a = [ 1, 2, 3 ],\n    b = a[0],\n    c = a[1],\n    d = a[2];","sibilant":"(const a [ 1 2 3 ]\n     [ b c d ] a)"},{"javascript":"const attribute = ({ attribute: \"hi\" }).attribute;","sibilant":"(const {attribute} { attribute: 'hi })"},{"javascript":"const log = console.log,\n    dir = console.dir;","sibilant":"(const {log dir} console)"},{"javascript":"const a = ({\n  a: 1,\n  b: 2\n}).a,\n    c_d$2 = {\n  c: 3,\n  d: 4\n},\n    c = c_d$2.c,\n    d = c_d$2.d,\n    c_d$2 = undefined;","sibilant":"(const {a}: {a 1 b 2},\n     {c d}: {c 3 d 4})"}],"tags":["variables","language"]},{"name":"assign","namespace":"core","type":"macro","description":"assigns alternating keys and values in `args`.  This works much\nlike `var`, but without the var keyword.  It is important to\nunderstand variable scope in javascript in order to use this macro safely.\nThis macro supports destructuring, as shown in examples","references":[],"arguments":["...pairs"],"definition":"(macro assign (...pairs)\n        (|> pairs\n            destructure\n            (map (#(pair) (as-statement [(first pair) \" = \" (second pair)])))\n            (interleave \"\n\")))","examples":[{"javascript":"a = 1;","sibilant":"(assign a 1)"},{"javascript":"a = 1;\nb = 2;","sibilant":"(assign a: 1, b: 2)"},{"javascript":"left_right$1 = [ left, right ];\nright = left_right$1[0];\nleft = left_right$1[1];\nleft_right$1 = undefined;","sibilant":"(assign [ right left ] [ left right ])"},{"javascript":"log = console.log;","sibilant":"(assign {log} console)"},{"javascript":"a = c[0];\nb = c[1];","sibilant":"(assign [ a b ] c)"},{"javascript":"a = c.a;\nb = c.b;\nx = a[0];\ny = a[1];","sibilant":"(assign { a b } c\n        [ x y ] a)"}],"tags":["language","variables"]},{"name":"default","namespace":"core","type":"macro","description":"sets default values for variables in current scope. `pairs` are\nalternating variable names and default values","references":[],"arguments":["...pairs"],"definition":"(macro default (...pairs)\n       (interleave \"\n\" (bulk-map pairs (#(name value)\n                                  '(assign @name (ternary (defined? @name) @name @value))))))","examples":[{"javascript":"a = (typeof a !== \"undefined\") ? a : 10;\nb = (typeof b !== \"undefined\") ? b : 20;","sibilant":"(default a 10 b 20)"}],"tags":["variables","language"]}]
