/
value_set_eclosure.go
150 lines (120 loc) · 3.27 KB
/
value_set_eclosure.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package rel
import (
"context"
"fmt"
"reflect"
"github.com/arr-ai/arrai/pkg/fu"
"github.com/arr-ai/wbnf/parser"
)
// ExprClosure represents the closure of an expression over a scope.
type ExprClosure struct {
scope Scope
e Expr
}
// NewExprClosure returns a new ExprClosure.
func NewExprClosure(scope Scope, e Expr) Value {
return ExprClosure{scope: scope, e: e}
}
// Hash computes a hash for a ExprClosure.
func (c ExprClosure) Hash(seed uintptr) uintptr {
panic("not implemented")
// TODO: Is this enough?
// return c.e.Hash(seed)
}
// Equal tests two Values for equality. Any other type returns false.
func (c ExprClosure) Equal(i interface{}) bool {
if d, ok := i.(ExprClosure); ok {
return c.EqualExprClosure(d)
}
return false
}
// Equal tests two Values for equality. Any other type returns false.
func (c ExprClosure) EqualExprClosure(d ExprClosure) bool {
panic("not implemented")
// return c.f.EqualFunction(d.f)
}
// String returns a string representation of the expression.
func (c ExprClosure) String() string {
return fu.String(c)
}
// Format formats the expression.
func (c ExprClosure) Format(f fmt.State, verb rune) {
fu.WriteString(f, "◖")
fu.FRepr(f, c.e)
fu.WriteString(f, "◗")
}
// Eval returns the Value
func (c ExprClosure) Eval(ctx context.Context, _ Scope) (Value, error) {
return c.e.Eval(ctx, c.scope)
}
// Source returns a scanner locating the ExprClosure's source code.
func (c ExprClosure) Source() parser.Scanner {
return *parser.NewScanner("")
}
var eclosureKind = registerKind(206, reflect.TypeOf(ExprClosure{}))
// Kind returns a number that is unique for each major kind of Value.
func (c ExprClosure) Kind() int {
return eclosureKind
}
// Bool returns true iff the tuple has attributes.
func (c ExprClosure) IsTrue() bool {
return true
}
// Less returns true iff g is not a number or f.number < g.number.
func (c ExprClosure) Less(d Value) bool {
if c.Kind() != d.Kind() {
return c.Kind() < d.Kind()
}
return c.String() < d.String()
}
// Negate returns {(negateTag): f}.
func (c ExprClosure) Negate() Value {
return NewTuple(NewAttr(negateTag, c))
}
// Export exports a ExprClosure.
func (c ExprClosure) Export(ctx context.Context) interface{} {
return func(v Value) Value {
result, err := SetCall(ctx, c, v)
if err != nil {
panic(err)
}
return result
}
}
func (ExprClosure) getSetBuilder() setBuilder {
return newGenericTypeSetBuilder()
}
func (ExprClosure) getBucket() fmt.Stringer {
return genericType
}
func (ExprClosure) Count() int {
return 1
}
func (ExprClosure) Has(Value) bool {
panic("unimplemented")
}
func (ExprClosure) Enumerator() ValueEnumerator {
panic("unimplemented")
}
func (c ExprClosure) With(Value) Set {
panic("unimplemented")
}
func (ExprClosure) Without(Value) Set {
panic("unimplemented")
}
func (ExprClosure) Map(func(Value) (Value, error)) (Set, error) {
panic("unimplemented")
}
func (ExprClosure) Where(p func(v Value) (bool, error)) (Set, error) {
panic("unimplemented")
}
func (c ExprClosure) CallAll(_ context.Context, arg Value, b SetBuilder) error {
panic("unimplemented")
}
func (ExprClosure) unionSetSubsetBucket() string {
// TODO: create its own subset bucket in union set
return genericType.String()
}
func (ExprClosure) ArrayEnumerator() ValueEnumerator {
panic("unimplemented")
}