<commit_before>// leisp
// Copyright 2016 <NAME> <<EMAIL>>. All rights reserved.
// Under the MIT License

package interpreter

import (
	"fmt"
	"leisp/types"
	"os"
)

func builtinTypeOf(s *types.Scope, list []*types.AST) *types.Atom {

	args, errAtom := astListToAtomList(s, list)
	if errAtom != nil {
		return errAtom
	}

	if len(args) != 1 {
		return types.NewErrorMessageAtom(`invalid arguments number for type-of`)
	}
	a := args[0]
	if a.IsError() {
		return types.NewAtom(types.NewStringValue("error"))
	}
	return types.NewAtom(types.NewStringValue(a.Value.GetType()))
}

func builtinDefvar(s *types.Scope, list []*types.AST) *types.Atom {

	if len(list) != 2 {
		return types.NewErrorMessageAtom(`invalid arguments number for defvar`)
	}

	first := list[0]
	if !first.IsValue() {
		return types.NewErrorAtom(fmt.Errorf("function name must be symbol: %s", first.ToString()))
	}
	name, ok := first.Value.(*types.SymbolValue)
	if !ok {
		return types.NewErrorAtom(fmt.Errorf("function name must be symbol: %s", name.ToString()))
	}

	value := EvalAST(s, list[1])
	if value.IsError() {
		return value
	}

	if err := s.Declare(name.Value, value.Value); err != nil {
		return types.NewErrorAtom(err)
	}

	return value
}

func builtinNewScope(s *types.Scope, list []*types.AST) *types.Atom {

	args, errAtom := astListToAtomList(s, list)
	if errAtom != nil {
		return errAtom
	}

	argc := len(args)
	if argc > 1 {
		return types.NewErrorMessageAtom(`invalid arguments number for new-scope`)
	}<commit_msg>fix builtin.defvar<commit_after>// leisp
// Copyright 2016 <NAME> <<EMAIL>>. All rights reserved.
// Under the MIT License

package interpreter

import (
	"fmt"
	"leisp/types"
	"os"
)

func builtinTypeOf(s *types.Scope, list []*types.AST) *types.Atom {

	args, errAtom := astListToAtomList(s, list)
	if errAtom != nil {
		return errAtom
	}

	if len(args) != 1 {
		return types.NewErrorMessageAtom(`invalid arguments number for type-of`)
	}
	a := args[0]
	if a.IsError() {
		return types.NewAtom(types.NewStringValue("error"))
	}
	return types.NewAtom(types.NewStringValue(a.Value.GetType()))
}

func builtinDefvar(s *types.Scope, list []*types.AST) *types.Atom {

	if len(list) != 2 {
		return types.NewErrorMessageAtom(`invalid arguments number for defvar`)
	}

	first := list[0]
	if !first.IsValue() {
		return types.NewErrorAtom(fmt.Errorf("function name must be symbol: %s", first.ToString()))
	}
	name, ok := first.Value.(*types.SymbolValue)
	if !ok {
		return types.NewErrorAtom(fmt.Errorf("function name must be symbol: %s", first.ToString()))
	}

	value := EvalAST(s, list[1])
	if value.IsError() {
		return value
	}

	if err := s.Declare(name.Value, value.Value); err != nil {
		return types.NewErrorAtom(err)
	}

	return value
}

func builtinNewScope(s *types.Scope, list []*types.AST) *types.Atom {

	args, errAtom := astListToAtomList(s, list)
	if errAtom != nil {
		return errAtom
	}

	argc := len(args)
	if argc > 1 {
		return types.NewErrorMessageAtom(`invalid arguments number for new-scope`)
	}
{'fraction_non_alphanumeric': 0.14953580901856764, 'fraction_numerical': 0.006631299734748011, 'mean_word_length': 4.2287694974003465, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '4610488', 'n_tokens_mistral': 1158, 'n_tokens_neox': 1104, 'n_words': 269}