From 9967918418bd28c7cabf5f6391fea87d478bb165 Mon Sep 17 00:00:00 2001 From: Celestino Amoroso Date: Sun, 19 May 2024 02:20:36 +0200 Subject: [PATCH] operator-sum.go: adding item to a list is no more allowed. The sum operator '+' now ca only join two list. --- operator-sum.go | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/operator-sum.go b/operator-sum.go index 85abace..b6dcdd9 100644 --- a/operator-sum.go +++ b/operator-sum.go @@ -38,15 +38,28 @@ func evalPlus(ctx ExprContext, self *term) (v any, err error) { rightInt, _ := rightValue.(int64) v = leftInt + rightInt } - } else if IsList(leftValue) || IsList(rightValue) { + // } else if IsList(leftValue) || IsList(rightValue) { + // var leftList, rightList *ListType + // var ok bool + // if leftList, ok = leftValue.(*ListType); !ok { + // leftList = &ListType{leftValue} + // } + // if rightList, ok = rightValue.(*ListType); !ok { + // rightList = &ListType{rightValue} + // } + // sumList := make(ListType, 0, len(*leftList)+len(*rightList)) + // for _, item := range *leftList { + // sumList = append(sumList, item) + // } + // for _, item := range *rightList { + // sumList = append(sumList, item) + // } + // v = &sumList + } else if IsList(leftValue) && IsList(rightValue) { var leftList, rightList *ListType - var ok bool - if leftList, ok = leftValue.(*ListType); !ok { - leftList = &ListType{leftValue} - } - if rightList, ok = rightValue.(*ListType); !ok { - rightList = &ListType{rightValue} - } + leftList, _ = leftValue.(*ListType) + rightList, _ = rightValue.(*ListType) + sumList := make(ListType, 0, len(*leftList)+len(*rightList)) for _, item := range *leftList { sumList = append(sumList, item)