aboutsummaryrefslogtreecommitdiff
path: root/go/src/types
diff options
context:
space:
mode:
Diffstat (limited to 'go/src/types')
-rw-r--r--go/src/types/types.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/go/src/types/types.go b/go/src/types/types.go
index 2eacaaf..95bdc1f 100644
--- a/go/src/types/types.go
+++ b/go/src/types/types.go
@@ -1,7 +1,9 @@
package types
import (
+ "reflect"
"errors"
+ //"fmt"
)
//type Error interface {
@@ -62,3 +64,40 @@ func Hash_Map_Q(obj MalType) bool {
default: return false
}
}
+
+// General functions
+
+func _obj_type(obj MalType) string {
+ return reflect.TypeOf(obj).Name()
+}
+
+func Sequential_Q(seq MalType) bool {
+ //fmt.Printf("here1 %#v\n", reflect.TypeOf(seq).Name())
+ return (reflect.TypeOf(seq).Name() == "List") ||
+ (reflect.TypeOf(seq).Name() == "Vector")
+}
+
+func Equal_Q(a MalType, b MalType) bool {
+ ota := reflect.TypeOf(a); otb := reflect.TypeOf(b)
+ if !((ota == otb) || (Sequential_Q(a) && Sequential_Q(b))) {
+ return false
+ }
+ //av := reflect.ValueOf(a); bv := reflect.ValueOf(b)
+ //fmt.Printf("here2: %#v\n", reflect.TypeOf(a).Name())
+ switch reflect.TypeOf(a).Name() {
+ case "Symbol":
+ return a.(Symbol).Val == b.(Symbol).Val
+ case "List": fallthrough
+ case "Vector":
+ as,_ := GetSlice(a); bs,_ := GetSlice(b)
+ if len(as) != len(bs) { return false }
+ for i := 0; i < len(as); i+=1 {
+ if !Equal_Q(as[i], bs[i]) { return false }
+ }
+ return true
+ case "map[string]MalType":
+ return false
+ default:
+ return a == b
+ }
+}