 
 /// A Scheme Env is implemented as a Swift `[String: Any]` dictionary.
 public typealias Env = [Symbol: Any]
+
+/**
+ Extension to Array for safer indexing
+ */
+private extension Array {
+    subscript (safe index: Int) -> Element? {
+        return (index >= 0 && index < count) ? self[index] : nil
+    }
+}
 
 /**
  A simple Scheme interpreter written in Swift

            var exp = bool ? conseq : alt
            return try eval(&exp, withEnvironment: &env)
        } else if let x = x as? List, x.first as? Symbol == "define" { // definition
            guard let `var` = x[1] as? Symbol else {
                throw InterpreterError.SyntaxError("invalid variable definition")
            }
            var exp = x[2]

            env[`var`] = try eval(&exp, withEnvironment: &env)
            return 0
        } else if let x = x as? List { // procedure call
            var args: [Any] = []
            var exp = x[0]

            let proc = try eval(&exp, withEnvironment: &env)


                guard let proc = proc as? (Any, Any)->Any? else {
                    throw InterpreterError.SyntaxError("unknown two parameter function")
                }
                guard let result = proc(args[safe: 0] as Any, args[safe: 1] as Any) else {
                    throw InterpreterError.SyntaxError("bad input to two parameter function")
                }
                return result
