<commit_before>/**
 * ki: the lisp that macroexpands to JavaScript
 * MIT license http://www.opensource.org/licenses/mit-license.php/
 * Copyright (C) 2014 <NAME> http://lantiga.github.io
 */

macro _arr {
  rule { () } => {
  }

  rule { ($arg) } => {
    _sexpr $arg
  }

  rule { ($arg $args ...) } => {
    _sexpr $arg, _arr ($args ...)
  }
}

macro _obj {
  rule { () } => {
  }
  
  rule { ((keyword $k) $v) } => {
    _sexpr $k: _sexpr $v
  }

  rule { ((keyword $k) $v $args ...) } => {
    _sexpr $k: _sexpr $v, _obj ($args ...)
  }

  rule { ($k $v) } => {
    _sexpr $k: _sexpr $v
  }

  rule { ($k $v $args ...) } => {
    _sexpr $k: _sexpr $v, _obj ($args ...)
  }
}

macro _args {
  rule { () } => {
  }

  rule { ($arg) } => {
    _sexpr $arg
  }

  rule { ($arg $args ...) } => {
    _sexpr $arg, _args ($args ...)
  }
}

macro _x {
  case { $ctx null } => {
    throwSyntaxError('ki','<null> is not a valid literal, use nil',#{$ctx})
  }
  case { $ctx undefined } => {
    throwSyntaxError('ki','<undefined> is not a valid literal, use nil',#{$ctx})
  }
  case { _ nil } => {
    return #{null}
  }
  case { _ $x} => {
    return #{$x}
  }
}

macro _ns {
  case { _ $ns $sexprs ... } => {
    var nsname = unwrapSyntax(#{$ns});
    letstx $nsname = [makeValue(nsname,#{$ns})];
    return #{
      (function () {
        _ki.init(this,$nsname);
        _return_sexprs ($sexprs ...);
      }())
    }
  }
}

macro _def {
  case { _ $n $sexpr } => {
    var varname = unwrapSyntax(#{$n});
    letstx $varname = [makeValue(varname,#{$n})];
    return #{
      (function () {
        _ki_ns_ctx[$varname] = _sexpr $sexpr;
        _ki.namespaces[_ki_ns_name].vars.$n = _ki_ns_ctx[$varname]
        return _ki_ns_ctx[$varname];
      }())
    };
  }
}

macro _count {
  case { $m ($x(,) ...) } => {
    var n = #{$x ...}.length;
    letstx $n = [makeValue(n,#{$m})];
    return #{$n};
  }
}

macro _fnmap {
  rule { ([$args ...] $sexprs ...), $rest(,)... } => {
    _count ($args(,)...): _sexpr (fn [$args ...] $sexprs ...), _fnmap $rest(,)...
  }
  rule { ([$args ...] $sexprs ...) } => {
    _count ($args(,)...): _sexpr (fn [$args ...] $sexprs ...)
  }
}

macro _let {
  rule { ([$k $v $rest ...] $sexprs ...) } => {
    return (function ($k) {
      _let ([$rest ...] $sexprs ...)<commit_msg>Destructuring for nested vectors in let.<commit_after>/**
 * ki: the lisp that macroexpands to JavaScript
 * MIT license http://www.opensource.org/licenses/mit-license.php/
 * Copyright (C) 2014 <NAME> http://lantiga.github.io
 */

macro _arr {
  rule { () } => {
  }

  rule { ($arg) } => {
    _sexpr $arg
  }

  rule { ($arg $args ...) } => {
    _sexpr $arg, _arr ($args ...)
  }
}

macro _obj {
  rule { () } => {
  }
  
  rule { ((keyword $k) $v) } => {
    _sexpr $k: _sexpr $v
  }

  rule { ((keyword $k) $v $args ...) } => {
    _sexpr $k: _sexpr $v, _obj ($args ...)
  }

  rule { ($k $v) } => {
    _sexpr $k: _sexpr $v
  }

  rule { ($k $v $args ...) } => {
    _sexpr $k: _sexpr $v, _obj ($args ...)
  }
}

macro _args {
  rule { () } => {
  }

  rule { ($arg) } => {
    _sexpr $arg
  }

  rule { ($arg $args ...) } => {
    _sexpr $arg, _args ($args ...)
  }
}

macro _x {
  case { $ctx null } => {
    throwSyntaxError('ki','<null> is not a valid literal, use nil',#{$ctx})
  }
  case { $ctx undefined } => {
    throwSyntaxError('ki','<undefined> is not a valid literal, use nil',#{$ctx})
  }
  case { _ nil } => {
    return #{null}
  }
  case { _ $x} => {
    return #{$x}
  }
}

macro _ns {
  case { _ $ns $sexprs ... } => {
    var nsname = unwrapSyntax(#{$ns});
    letstx $nsname = [makeValue(nsname,#{$ns})];
    return #{
      (function () {
        _ki.init(this,$nsname);
        _return_sexprs ($sexprs ...);
      }())
    }
  }
}

macro _def {
  case { _ $n $sexpr } => {
    var varname = unwrapSyntax(#{$n});
    letstx $varname = [makeValue(varname,#{$n})];
    return #{
      (function () {
        _ki_ns_ctx[$varname] = _sexpr $sexpr;
        _ki.namespaces[_ki_ns_name].vars.$n = _ki_ns_ctx[$varname]
        return _ki_ns_ctx[$varname];
      }())
    };
  }
}

macro _count {
  case { $m ($x(,) ...) } => {
    var n = #{$x ...}.length;
    letstx $n = [makeValue(n,#{$m})];
    return #{$n};
  }
}

macro _fnmap {
  rule { ([$args ...] $sexprs ...), $rest(,)... } => {
    _count ($args(,)...): _sexpr (fn [$args ...] $sexprs ...), _fnmap $rest(,)...
  }
  rule { ([$args ...] $sexprs ...) } => {
    _count ($args(,)...): _sexpr (fn [$args ...] $sexprs ...)
  }
}

macro _destr { 
  rule { ([$a], $v) } => {
    var f = _sexpr(first $v);
    _destr($a,f)
  }
  rule { ([$a $b ...], $v) } => {
    var f = _sexpr(first $v);
    _destr($a,f)
    var r = _sexpr(rest $v)
    _destr([$b ...], r)
  }
  //rule { ({$b $a}, $v) } => {
  //  var $a = _sexpr(first $v);
  //}
  rule { ($a, $v) } => {
    var $a = $v;
  }
}

macro _let {
  rule { ([$k $v $rest ...] $sexprs ...) } => {
    return (function (v) {
      _destr($k, v)
      _let ([$rest ...] $sexprs ...)
{'fraction_non_alphanumeric': 0.24755440207626273, 'fraction_numerical': 0.001597125174685566, 'mean_word_length': 2.0235365117682558, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6830277', 'n_tokens_mistral': 2157, 'n_tokens_neox': 2060, 'n_words': 448}