Skip to content

Commit 0b0fab7

Browse files
committed
destructive: change "do" signature
... to take lambda(s), not any value.
1 parent 80ef033 commit 0b0fab7

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

dsl/ops/func_do.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ type doOp struct {
1919
var DoOp = &doOp{funcBase("do")}
2020

2121
func (*doOp) Bind(args ...types.Value) (types.Expr, error) {
22+
thunkType := types.NewLambdaType(types.AnyValue)
2223
sig := make([]types.Type, 0, len(args))
2324
for i := 0; i < len(args); i++ {
24-
sig = append(sig, types.AnyValue)
25+
sig = append(sig, thunkType)
2526
}
2627
if err := util.Signature(sig...).Check(args); err != nil {
2728
return nil, err
@@ -49,8 +50,9 @@ func (*doOp) EvalExpr(ctx context.Context, args []types.Value) (_ types.Value, _
4950
}()
5051

5152
var lastVal types.Value
53+
empty := make([]types.Value, 0)
5254
for i := range args {
53-
v, rbFunc, err := args[i].Eval(ctx)
55+
v, rbFunc, err := args[i].(types.Op).EvalExpr(ctx, empty)
5456
g.Add(rbFunc)
5557
if err != nil {
5658
result = g.Error(err)

dsl/types/lambda.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package types
2+
3+
import "context"
4+
5+
// Lambda can be applicable, and it has an expression to execute.
6+
type Lambda Value
7+
8+
// NewLambda creates lambda value.
9+
// Signature must have 1 type at least for a return type.
10+
func NewLambda(t Type, rest ...Type) Lambda {
11+
return &lambdaT{typ: NewLambdaType(t, rest...)}
12+
}
13+
14+
type lambdaT struct {
15+
typ Type
16+
}
17+
18+
func (v *lambdaT) Invert(context.Context) (Value, error) {
19+
return v, nil
20+
}
21+
22+
func (v *lambdaT) Eval(context.Context) (Value, func(), error) {
23+
return v, nil, nil
24+
}
25+
26+
func (v *lambdaT) Type() Type {
27+
return v.typ
28+
}

0 commit comments

Comments
 (0)