1 import groovy
.transform
.InheritConstructors
2 import groovy
.transform
.AutoClone
7 if (obj
instanceof Collection
|| obj
instanceof Map
) {
9 if (obj
.hasProperty("meta")) {
10 new_obj
.getMetaClass().meta
= obj
.getProperties().meta
12 if (obj
.hasProperty("isvector")) {
13 new_obj
.getMetaClass().isvector
= obj
.getProperties().isvector
15 } else if (obj
instanceof Object
) {
22 static class MalException
extends Exception
{
24 MalException(String message
) {
29 super("mal exception containing object")
35 static class MalSymbol
implements Comparable
{
37 MalSymbol(String name
) {
40 int compareTo(o
) { value
<=> o
.value
}
43 def
static keyword(o
) {
44 types
.&keyword_Q(o
) ? o
: ("\u029e" + o
)
46 def
static keyword_Q(o
) {
47 return o
instanceof String
&& o
.size() > 0 && o
[0] == "\u029e"
50 def
static list_Q(o
) {
51 //return (o instanceof List || o instanceof Object[]) &&
52 return o
instanceof List
&& !o
.hasProperty("isvector")
55 def
static vector(o
) {
57 v
.metaClass
.isvector
= true
60 def
static vector_Q(o
) {
61 return o
instanceof List
&& o
.hasProperty("isvector") && o
.isvector
64 def
static hash_map(lst
) {
68 def
static assoc_BANG(m
, kvs
) {
69 for (int i
=0; i
<kvs
.size(); i
+=2) {
74 def
static dissoc_BANG(m
, ks
) {
75 for (int i
=0; i
<ks
.size(); i
++) {
80 def
static hash_map_Q(o
) {
81 return o
instanceof Map
84 def
static sequential_Q(o
) {
85 return types
.list_Q(o
) || types
.vector_Q(o
)
89 static class MalFunc
{
96 MalFunc(_EVAL
, _ast
, _env
, _params
) {
105 def new_env
= env
.class.newInstance([env
, params
, args
] as Object
[])
106 return EVAL(ast
, new_env
)
111 static class MalAtom
{