when the list value involved in an insert or append operations (directly) comes from a variable, that variable receives the result list
This commit is contained in:
@@ -37,6 +37,9 @@ func evalInsert(ctx ExprContext, self *term) (v any, err error) {
|
||||
list, _ := rightValue.(*ListType)
|
||||
newList := append(ListType{leftValue}, *list...)
|
||||
v = &newList
|
||||
if self.children[1].symbol() == SymIdentifier {
|
||||
ctx.UnsafeSetVar(self.children[1].source(), v)
|
||||
}
|
||||
} else {
|
||||
err = self.errIncompatibleTypes(leftValue, rightValue)
|
||||
}
|
||||
@@ -54,12 +57,33 @@ func evalAppend(ctx ExprContext, self *term) (v any, err error) {
|
||||
list, _ := leftValue.(*ListType)
|
||||
newList := append(*list, rightValue)
|
||||
v = &newList
|
||||
if self.children[0].symbol() == SymIdentifier {
|
||||
ctx.UnsafeSetVar(self.children[0].source(), v)
|
||||
}
|
||||
} else {
|
||||
err = self.errIncompatibleTypes(leftValue, rightValue)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// func evalAssignAppend(ctx ExprContext, self *term) (v any, err error) {
|
||||
// var leftValue, rightValue any
|
||||
|
||||
// if leftValue, rightValue, err = self.evalInfix(ctx); err != nil {
|
||||
// return
|
||||
// }
|
||||
|
||||
// if IsList(leftValue) {
|
||||
// list, _ := leftValue.(*ListType)
|
||||
// newList := append(*list, rightValue)
|
||||
// v = &newList
|
||||
// if
|
||||
// } else {
|
||||
// err = self.errIncompatibleTypes(leftValue, rightValue)
|
||||
// }
|
||||
// return
|
||||
// }
|
||||
|
||||
// init
|
||||
func init() {
|
||||
registerTermConstructor(SymInsert, newInsertTerm)
|
||||
|
||||
Reference in New Issue
Block a user