Skip to content

Commit

Permalink
Support Scan. Fixes #83
Browse files Browse the repository at this point in the history
  • Loading branch information
corywalker committed Aug 25, 2017
1 parent f056b4d commit a23fa58
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
29 changes: 29 additions & 0 deletions expreduce/builtin_list.go
Expand Up @@ -472,6 +472,35 @@ func GetListDefinitions() (defs []Definition) {
return this
},
})
defs = append(defs, Definition{
Name: "Scan",
legacyEvalFn: func(this *Expression, es *EvalState) Ex {
if len(this.Parts) != 3 {
return this
}

expr, isExpr := this.Parts[2].(*Expression)
if !isExpr {
return this
}
for _, part := range expr.Parts[1:] {
res := (NewExpression([]Ex{
this.Parts[1],
part,
})).Eval(es)
if es.HasThrown() {
return es.thrown
}
if asReturn, isReturn := HeadAssertion(res, "System`Return"); isReturn {
if len(asReturn.Parts) < 2 {
return &Symbol{"System`Null"}
}
return asReturn.Parts[1]
}
}
return &Symbol{"System`Null"}
},
})
defs = append(defs, Definition{Name: "ListQ"})
defs = append(defs, Definition{Name: "Last"})
defs = append(defs, Definition{Name: "First"})
Expand Down

0 comments on commit a23fa58

Please sign in to comment.