Ejemplo n.º 1
0
func doReadEval(str string) error {

	//R
	val, lerr := ds.ReadString(str)
	if lerr != nil {
		fmt.Println("ReadError: " + lerr.Error())
		return lerr
	}

	if val == nil {
		return nil
	}

	//E
	_, verr := ds.Eval(val, gEnv)
	if verr != nil {
		fmt.Println("EvalError: " + verr.Error())
		return verr
	}

	return nil
}
Ejemplo n.º 2
0
func shell() {
	defer func() {
		if x := recover(); x != nil {
			fmt.Println("droscheme: caught exception:")
			fmt.Println(x)
		}
	}()

	defaultPrompt := "ds"
	prompt := defaultPrompt
	lines := ""
	in := bufio.NewReader(os.Stdin)

	//L
	for line, rerr := getLine(in, prompt); rerr == nil; line, rerr = getLine(in, prompt) {

		if line == "\n" {
			lines = ""
			prompt = defaultPrompt
			continue
		} else {
			lines += line
		}

		if ds.CountParens(lines) != 0 {
			prompt = "   -"
			continue
		}

		//R
		val, lerr := ds.ReadString(lines)
		if lerr != nil {
			fmt.Println("ReadError: " + lerr.Error())
			continue
		}

		if val == nil {
			continue
		}

		lines = ""
		prompt = defaultPrompt

		if gDontEval {
			outs, ok := val.(fmt.Stringer)
			if ok && outs.String() != "" {
				fmt.Println(outs)
			}
			continue
		}

		//E
		out, verr := ds.Eval(val, gEnv)
		if verr != nil {
			fmt.Println("EvalError: " + verr.Error())
			continue
		}

		//P
		outs, ok := out.(fmt.Stringer)
		if ok && outs.String() != "" {
			fmt.Println(out)
		}
	}

	fmt.Println()
}