<commit_before>// Copyright 2014 SteelSeries ApS.  All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// This package implements a basic LISP interpretor for embedding in a go program for scripting.
// This file contains the string primitive functions.

package golisp

import (
	"strings"
)

func RegsterStringPrimitives() {
	MakePrimitiveFunction("split", 2, SplitImpl)
	MakePrimitiveFunction("trim", -1, TrimImpl)
}

func SplitImpl(args *Data, env *SymbolTableFrame) (result *Data, err error) {
	theString, err := Eval(First(args), env)
	if err != nil {
		return
	}

	theSeparator, err := Eval(Second(args), env)
	if err != nil {
		return<commit_msg>Better error handling<commit_after>// Copyright 2014 SteelSeries ApS.  All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// This package implements a basic LISP interpretor for embedding in a go program for scripting.
// This file contains the string primitive functions.

package golisp

import (
	"errors"
	"fmt"
	"strings"
)

func RegsterStringPrimitives() {
	MakePrimitiveFunction("split", 2, SplitImpl)
	MakePrimitiveFunction("trim", -1, TrimImpl)
}

func SplitImpl(args *Data, env *SymbolTableFrame) (result *Data, err error) {
	theString, err := Eval(First(args), env)
	if err != nil {
		return
	}
	if !StringP(theString) {
		err = errors.New(fmt.Sprintf("trim requires string arguments but was given %s.", String(theString)))
		return
	}

	theSeparator, err := Eval(Second(args), env)
	if err != nil {
		return
	}
	if !StringP(theSeparator) {
		err = errors.New(fmt.Sprintf("trim requires string arguments but was given %s.", String(theSeparator)))
		return
{'fraction_non_alphanumeric': 0.10627473148671567, 'fraction_numerical': 0.006783493499152063, 'mean_word_length': 4.347432024169184, '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': '4067587', 'n_tokens_mistral': 556, 'n_tokens_neox': 534, 'n_words': 201}