<commit_before>#include "syntax.hpp"
#include "eval.hpp"

#include <map>


namespace lisp {

  namespace kw {
    const symbol def = "def", lambda = "lambda", seq = "do", cond = "cond", quote = "quote";
  }

  
  namespace special {

    using type = sexpr::list (*)(const ref<context>&, const sexpr::list& args);
    
    static sexpr::list def(const ref<context>& ctx, const sexpr::list& args) {

      static const auto fail = [] {
        throw syntax_error("(def `symbol` `expr`)");
      };
      
      sexpr::list curr = args;
      try{
        const symbol& name = head(curr).cast<symbol>();
        curr = tail(curr);
        
        const sexpr body = expand(ctx, head(curr));
        
        curr = tail(curr);
        if(curr) fail();
        
        return name >>= body >>= sexpr::list();
        
      } catch( value::bad_cast& e) {
        fail();
      } catch( empty_list& e) {
        fail();
      }

      throw;
    }


    static sexpr::list quote(const ref<context>& ctx, const sexpr::list& args) {
      static const auto fail = [] {
        throw syntax_error("(quote `expr`)");
      };
      
      sexpr::list curr = args;
      try {
        const sexpr& res = head(curr);

        curr = tail(curr);
        if(curr) fail();

        return res >>= sexpr::list();
        
      } catch( empty_list& e) {
        fail();
      }

      throw;
    }

    
    static sexpr::list lambda(const ref<context>& ctx, const sexpr::list& args) {
      static const auto fail = [] {
        throw syntax_error("(lambda (`symbol`...) `expr`)");
      };
      
      sexpr::list curr = args;
      try {

        const sexpr::list vars = map(head(curr).cast<sexpr::list>(), [](const sexpr& x) {
            return x.cast<symbol>();
          });
        
        curr = tail(curr);
        const sexpr body = expand(ctx, head(curr));
        
        curr = tail(curr);
        if(curr) fail();

        return vars >>= body >>= sexpr::list();
      }
      catch( value::bad_cast& e) {
        fail();
      }
      catch( empty_list& e) {
        fail();
      }

      throw;
    }
    


    static sexpr::list seq(const ref<context>& ctx, const sexpr::list& args) {
      return map(args, [&](const sexpr& x) {
          return expand_seq(ctx, x);
        });
    }


    static sexpr::list cond(const ref<context>& ctx, const sexpr::list& args) {
      static const auto fail = [] {
        throw syntax_error("(cond (`expr` `expr`)...)");
      };
      try{
        return map(args, [&](const sexpr& e) -> sexpr {
            sexpr::list curr = e.cast<sexpr::list>();
            
            const sexpr test = expand(ctx, head(curr));
            curr = tail(curr);
<commit_msg>fix compilation<commit_after>#include "syntax.hpp"
#include "eval.hpp"

#include <map>


namespace lisp {

  namespace kw {
    const symbol def = "def", lambda = "lambda", seq = "do", cond = "cond", quote = "quote";
  }

  
  namespace special {

    using type = sexpr::list (*)(const ref<context>&, const sexpr::list& args);
    
    static sexpr::list def(const ref<context>& ctx, const sexpr::list& args) {

      static const auto fail = [] {
        throw syntax_error("(def `symbol` `expr`)");
      };
      
      sexpr::list curr = args;
      try{
        const symbol& name = head(curr).cast<symbol>();
        curr = tail(curr);
        
        const sexpr body = expand(ctx, head(curr));
        
        curr = tail(curr);
        if(curr) fail();
        
        return name >>= body >>= sexpr::list();
        
      } catch( value::bad_cast& e) {
        fail();
      } catch( empty_list& e) {
        fail();
      }

      throw;
    }


    static sexpr::list quote(const ref<context>& ctx, const sexpr::list& args) {
      static const auto fail = [] {
        throw syntax_error("(quote `expr`)");
      };
      
      sexpr::list curr = args;
      try {
        const sexpr& res = head(curr);

        curr = tail(curr);
        if(curr) fail();

        return res >>= sexpr::list();
        
      } catch( empty_list& e) {
        fail();
      }

      throw;
    }

    
    static sexpr::list lambda(const ref<context>& ctx, const sexpr::list& args) {
      static const auto fail = [] {
        throw syntax_error("(lambda (`symbol`...) `expr`)");
      };
      
      sexpr::list curr = args;
      try {

        const sexpr::list vars = map(head(curr).cast<sexpr::list>(), [](const sexpr& x) {
            return x.cast<symbol>();
          });
        
        curr = tail(curr);
        const sexpr body = expand(ctx, head(curr));
        
        curr = tail(curr);
        if(curr) fail();

        return vars >>= body >>= sexpr::list();
      }
      catch( value::bad_cast& e) {
        fail();
      }
      catch( empty_list& e) {
        fail();
      }

      throw;
    }
    


    static sexpr::list seq(const ref<context>& ctx, const sexpr::list& args) {
      return map(args, [&ctx](const sexpr& x) {
          return expand_seq(ctx, x);
        });
    }


    static sexpr::list cond(const ref<context>& ctx, const sexpr::list& args) {
      static const auto fail = [] {
        throw syntax_error("(cond (`expr` `expr`)...)");
      };
      try{
        return map(args, [&ctx](const sexpr& e) -> sexpr {
            sexpr::list curr = e.cast<sexpr::list>();
            
            const sexpr test = expand(ctx, head(curr));
            curr = tail(curr);

{'fraction_non_alphanumeric': 0.15894039735099338, 'fraction_numerical': 0.0, 'mean_word_length': 1.8555672268907564, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 47, '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': '3549042', 'n_tokens_mistral': 1712, 'n_tokens_neox': 1677, 'n_words': 435}