<commit_before># Copyright 2010 Curtis (Programble) <<EMAIL>>
# Licensed under the GNU GPLv3

from scope import Scope
import lisp

# Global scope (This is where the entire core goes)
global_scope = Scope()

# Standard core bindings
t = lisp.Symbol("t")
global_scope["t"] = t
nil = lisp.Symbol("nil")
global_scope["nil"] = nil

# Core functions (from McCarthy's paper)

def atom(scope, x):
    """Returns t if x is atomic"""
    x = x.evaluate(scope)
    
    if x.__class__ == lisp.Atom:
        return t
    else:
        return nil
global_scope["atom"] = atom

def eq(scope, x, y):
    """Returns t if x and y are equal"""
    # First evaluate arguments
    x = x.evaluate(scope)
    y = y.evaluate(scope)
    
    if x == y:
        return t
    else:
        return nil
global_scope["eq"] = eq
global_scope["="] = eq

def car(scope, x):
    """Returns the first item (car) of list x"""
    return x.evaluate(scope).car()
global_scope["car"] = car

def cdr(scope, x):
    """Returns the tail (cdr) of list x"""
    return x.evaluate(scope).cdr()
global_scope["cdr"] = cdr

def cons(scope, x, y):
    """Joins y and x"""
    # First evaluate arguments
    x = x.evaluate(scope)
    y = y.evaluate(scope)
    
    return y.cons(x)
global_scope["cons"] = cons

def cond(scope, *x):
    """For each expression, if the car evaluates to t, the cdr is evaluated and its result returned"""
    for test in x:
        if test.car().evaluate(scope) == t:
            return test.cdr().car().evaluate(scope)
    return nil
global_scope["cond"] = cond

def quote(scope, x):
    """Returns its argument"""
    return x
global_scope["quote"] = quote

# Special Forms (from McCarthy's paper)

def def_(scope, symbol, x):
    # Can only bind to a symbol
    if symbol.__class__ != lisp.Symbol:
        return nil
    # Evaluate value
    x = x.evaluate(scope)
    # Bind in current scope
    scope[symbol.data] = x
    return scope[symbol.data]
global_scope["def"] = def_

def lambda_(scope, names, *body):
    """Returns a new lambda"""
    l = lisp.Lambda(names, body)
    return l
global_scope["lambda"] = lambda_<commit_msg>Made def always use the global scope<commit_after># Copyright 2010 Curtis (Programble) <<EMAIL>>
# Licensed under the GNU GPLv3

from scope import Scope
import lisp

# Global scope (This is where the entire core goes)
global_scope = Scope()

# Standard core bindings
t = lisp.Symbol("t")
global_scope["t"] = t
nil = lisp.Symbol("nil")
global_scope["nil"] = nil

# Core functions (from McCarthy's paper)

def atom(scope, x):
    """Returns t if x is atomic"""
    x = x.evaluate(scope)
    
    if x.__class__ == lisp.Atom:
        return t
    else:
        return nil
global_scope["atom"] = atom

def eq(scope, x, y):
    """Returns t if x and y are equal"""
    # First evaluate arguments
    x = x.evaluate(scope)
    y = y.evaluate(scope)
    
    if x == y:
        return t
    else:
        return nil
global_scope["eq"] = eq
global_scope["="] = eq

def car(scope, x):
    """Returns the first item (car) of list x"""
    return x.evaluate(scope).car()
global_scope["car"] = car

def cdr(scope, x):
    """Returns the tail (cdr) of list x"""
    return x.evaluate(scope).cdr()
global_scope["cdr"] = cdr

def cons(scope, x, y):
    """Joins y and x"""
    # First evaluate arguments
    x = x.evaluate(scope)
    y = y.evaluate(scope)
    
    return y.cons(x)
global_scope["cons"] = cons

def cond(scope, *x):
    """For each expression, if the car evaluates to t, the cdr is evaluated and its result returned"""
    for test in x:
        if test.car().evaluate(scope) == t:
            return test.cdr().car().evaluate(scope)
    return nil
global_scope["cond"] = cond

def quote(scope, x):
    """Returns its argument"""
    return x
global_scope["quote"] = quote

# Special Forms (from McCarthy's paper)

def def_(scope, symbol, x):
    # Can only bind to a symbol
    if symbol.__class__ != lisp.Symbol:
        return nil
    # Evaluate value
    x = x.evaluate(scope)
    # Bind in global scope
    global_scope[symbol.data] = x
    return scope[symbol.data]
global_scope["def"] = def_

def lambda_(scope, names, *body):
    """Returns a new lambda"""
    l = lisp.Lambda(names, body)
    return l
global_scope["lambda"] = lambda_
{'fraction_non_alphanumeric': 0.13383423338811928, 'fraction_numerical': 0.0023479690068091102, 'mean_word_length': 3.0532825880114176, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '3323493', 'n_tokens_mistral': 1432, 'n_tokens_neox': 1380, 'n_words': 477}