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:
2024-05-19 01:42:15 +02:00
parent 24a25bbf94
commit a543360151
3 changed files with 41 additions and 15 deletions
+24
View File
@@ -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)