aboutsummaryrefslogtreecommitdiff
path: root/go/src/types
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-10-06 20:36:23 -0500
committerJoel Martin <github@martintribe.org>2014-10-06 20:36:23 -0500
commitaf8fdff41e260b1b21be0e127afb536980f43804 (patch)
tree6dc9b5d54a38c6197001291cf85cdffc7cf100b7 /go/src/types
parent9feb2c9527294d82592bf35b97f8039f61bbec45 (diff)
downloadmal-af8fdff41e260b1b21be0e127afb536980f43804.tar.gz
mal-af8fdff41e260b1b21be0e127afb536980f43804.zip
go: add step4_if_fn_do
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
+ }
+}