<commit_before>//
// Expanders for core syntaxes
//
import { List, Cons, isPair, isList } from "../pair.js"
import { Sym } from "../symbol.js"
import { isIdentifier } from "./syntactic_closure.js"

const expandLambda = async ([form, xp]) => {
  const err = new BiwaError("malformed lambda", form);
  const l = form.to_array();
  if (l.length < 3) throw err;
  const formals = form.cadr(err);
  if (!isPair(formals)) throw err;
  const body = form.cddr(err);

  const newEnv = env.extend(formal-list);

  // TODO

  return Cons(Sym("lambda"),
           Cons(newFormals, newBody));
};

const expandIf = async ([form, xp]) => {
  const l = form.to_array();
  switch (l.length) {
    case 3:
      return List(Sym("if"), await xp.expand(l[1]), await xp.expand(l[2]));
    case 4:
      return List(Sym("if"), await xp.expand(l[1]), await xp.expand(l[2]), await xp.expand(l[3]));
    default:
      throw new BiwaError("malformed if", form);
  }
};

// TODO
// const expandDefine
// const expandBegin
// const expandQuote
// const expandSet
// const expandCallCc

// TODO
// const expandDefineRecordType
// const expandParameterize
// const expandDefineSyntax
// const expandLetSyntax
// const expandLetrecSyntax
// const expandSyntaxError
// const expandInclude
// const expandIncludeCi
// const expandIfExpand
// const expandCaseLambda

// Install core expanders into `lib`
const installCore = (lib) => {
  lib.exportMacro(Sym("if"), expandIf);
  lib.exportMacro(Sym("lambda"), expandLambda);
};
export { installCore };<commit_msg>impl. expandQuote<commit_after>//
// Expanders for core syntaxes
//
import { List, Cons, isPair, isList } from "../pair.js"
import { Sym } from "../symbol.js"
import { isIdentifier, unwrapSyntax } from "./syntactic_closure.js"

const expandLambda = async ([form, xp]) => {
  const err = new BiwaError("malformed lambda", form);
  const l = form.to_array();
  if (l.length < 3) throw err;
  const formals = form.cadr(err);
  if (!isPair(formals)) throw err;
  const body = form.cddr(err);

  const newEnv = env.extend(formal-list);

  // TODO

  return Cons(Sym("lambda"),
           Cons(newFormals, newBody));
};

const expandIf = async ([form, xp]) => {
  const l = form.to_array();
  switch (l.length) {
    case 3:
      return List(Sym("if"), await xp.expand(l[1]), await xp.expand(l[2]));
    case 4:
      return List(Sym("if"), await xp.expand(l[1]), await xp.expand(l[2]), await xp.expand(l[3]));
    default:
      throw new BiwaError("malformed if", form);
  }
};

const expandQuote = async ([form, xp]) => {
  const l = form.to_array();
  switch (l.length) {
    case 2:
      return List(Sym("quote"), unwrapSyntax(l[1]));
    default:
      throw new BiwaError("malformed quote", form);
  }
};

// TODO
// const expandDefine
// const expandBegin
// const expandSet
// const expandCallCc

// TODO
// const expandDefineRecordType
// const expandParameterize
// const expandDefineSyntax
// const expandLetSyntax
// const expandLetrecSyntax
// const expandSyntaxError
// const expandInclude
// const expandIncludeCi
// const expandIfExpand
// const expandCaseLambda

// Install core expanders into `lib`
const installCore = (lib) => {
  lib.exportMacro(Sym("lambda"), expandLambda);
  lib.exportMacro(Sym("if"), expandIf);
  lib.exportMacro(Sym("quote"), expandQuote);
};
export { installCore };
{'fraction_non_alphanumeric': 0.15836832633473305, 'fraction_numerical': 0.005398920215956809, 'mean_word_length': 3.5873452544704265, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6931262', 'n_tokens_mistral': 1114, 'n_tokens_neox': 1079, 'n_words': 297}