<commit_before>package util;

import globals.*;

import gnu.mapping.Environment;
import gnu.mapping.Named;
import gui.ErrorFrame;
import kawa.standard.Scheme;

/**
 * Wrapper around Kawa.
 */
public class KawaWrap {
	Scheme kawa;
	Environment env;
	
	/**
	 * Connect to Kawa.
	 */
	public KawaWrap()
	{
		Scheme.registerEnvironment();
		kawa = Scheme.getInstance();
		env = Environment.getCurrent();
		
		// Load globals.
        for (Globals g : new Globals[]{
        		new Randomness(),
        		new Mathiness(),
        		new Treeitude(),
        		new Imageitude(),
        }) {
        	try {
        		g.addMethods(this);
        	} catch(Throwable ex) {
        		ErrorFrame.log("Unable to load globals from " + g.getClass().getName() + ": " + ex.getMessage());
        	}
        }
	}
	
	/**
	 * Bind a new function from the Java end of things.
	 * 
	 * @param proc The function to bind.
	 */
	public void bind(Named proc) {
		kawa.defineFunction(proc);
	}
	
	/**
	 * Evaluate a command, given as a string.
	 * @param s The string to evaluate.
	 * @return The result.
	 */
	public Object eval(String cmd) {
		try {
			Object result = Scheme.eval(cmd, env);

			// Return the final result.
			if (result == null || result.toString().length() == 0)
				return null;
			else 
				return result;
			
		}  catch(NoSuchFieldError ex) {
			ex.printStackTrace();
			
			return "Unbound variable: " + ex.getMessage();
		} catch (Throwable ex) {
			return "Error: " + ex;
		}<commit_msg>- Fix that replaces [] with () to make square brackets work correctly.<commit_after>package util;

import globals.*;

import gnu.mapping.Environment;
import gnu.mapping.Named;
import gui.ErrorFrame;
import kawa.standard.Scheme;

/**
 * Wrapper around Kawa.
 */
public class KawaWrap {
	Scheme kawa;
	Environment env;
	
	/**
	 * Connect to Kawa.
	 */
	public KawaWrap()
	{
		Scheme.registerEnvironment();
		kawa = Scheme.getInstance();
		env = Environment.getCurrent();
		
		// Load globals.
        for (Globals g : new Globals[]{
        		new Randomness(),
        		new Mathiness(),
        		new Treeitude(),
        		new Imageitude(),
        }) {
        	try {
        		g.addMethods(this);
        	} catch(Throwable ex) {
        		ErrorFrame.log("Unable to load globals from " + g.getClass().getName() + ": " + ex.getMessage());
        	}
        }
	}
	
	/**
	 * Bind a new function from the Java end of things.
	 * 
	 * @param proc The function to bind.
	 */
	public void bind(Named proc) {
		kawa.defineFunction(proc);
	}
	
	/**
	 * Evaluate a command, given as a string.
	 * @param s The string to evaluate.
	 * @return The result.
	 */
	public Object eval(String cmd) {
		try {
			cmd = cmd.replace('[', '(').replace(']', ')');
			Object result = Scheme.eval(cmd, env);

			// Return the final result.
			if (result == null || result.toString().length() == 0)
				return null;
			else 
				return result;
		} catch (StackOverflowError ex) {
			return "Possible infinite looped detected.";
		} catch (Throwable ex) {
			return "Unknown error: " + ex;
		}
{'fraction_non_alphanumeric': 0.13481675392670156, 'fraction_numerical': 0.0006544502617801048, 'mean_word_length': 2.411830357142857, 'pattern_counts': {'":': 2, '<': 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': '4702477', 'n_tokens_mistral': 1070, 'n_tokens_neox': 958, 'n_words': 277}