<commit_before>require 'nydp/function_invocation'
require 'nydp/literal'

module Nydp
  class Compiler
    extend Helper

    def self.compile expression
      if expression.is_a? Nydp::Symbol
        SymbolLookup.build expression
      elsif literal? expression
        Literal.build expression
      elsif expression.is_a? Nydp::Pair
        puts "compiling #{expression}"
        compile_pair expression
      end
    end

    def self.compile_each expr
      if NIL.is?(expr)
        expr
      elsif pair?(expr)
        cons compile(expr.car), compile_each(expr.cdr)
      else
        compile(expr)
      end
    end

    def self.compile_pair expression
      key = expression.car
      if sym?(key, :if)
        Cond.build expression.cdr
      elsif sym?(key, :quote)
        Literal.build expression.cadr
      elsif sym?(key, "@")
        Assignment.build expression.cdr
      elsif sym?(key, :fn)
        InterpretedFunction.build expression.cadr, expression.cddr
      else
        FunctionInvocation.build expression
      end
    end
  end
end<commit_msg>assignment: use 'assign special form<commit_after>require 'nydp/function_invocation'
require 'nydp/literal'

module Nydp
  class Compiler
    extend Helper

    def self.compile expression
      if expression.is_a? Nydp::Symbol
        SymbolLookup.build expression
      elsif literal? expression
        Literal.build expression
      elsif expression.is_a? Nydp::Pair
        puts "compiling #{expression}"
        compile_pair expression
      end
    end

    def self.compile_each expr
      if NIL.is?(expr)
        expr
      elsif pair?(expr)
        cons compile(expr.car), compile_each(expr.cdr)
      else
        compile(expr)
      end
    end

    def self.compile_pair expression
      key = expression.car
      if sym?(key, :if)
        Cond.build expression.cdr
      elsif sym?(key, :quote)
        Literal.build expression.cadr
      elsif sym?(key, :assign)
        Assignment.build expression.cdr
      elsif sym?(key, :fn)
        InterpretedFunction.build expression.cadr, expression.cddr
      else
        FunctionInvocation.build expression
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.07297921478060046, 'fraction_numerical': 0.0, 'mean_word_length': 2.2968036529680367, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2056466', 'n_tokens_mistral': 635, 'n_tokens_neox': 638, 'n_words': 164}