Skip to content

Commit

Permalink
Merge branch 'main' of github.com:refaktor/rye into contextplay
Browse files Browse the repository at this point in the history
  • Loading branch information
refaktor committed Mar 10, 2024
2 parents 040eaad + d74ea11 commit 16ce549
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
46 changes: 42 additions & 4 deletions evaldo/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -6142,16 +6142,54 @@ var builtins = map[string]*env.Builtin{
oldval.Series = *s.Append(arg0)
ctx.Set(wrd.Index, oldval)
return oldval
case env.List:
dataSlice := make([]any, 0)
switch listData := arg0.(type) {
case env.List:
for _, v1 := range oldval.Data {
dataSlice = append(dataSlice, env.ToRyeValue(v1))
}
for _, v2 := range listData.Data {
dataSlice = append(dataSlice, env.ToRyeValue(v2))
}
default:
return makeError(ps, "Need to pass List of data")
}
combineList := make([]any, 0, len(dataSlice))
for _, v := range dataSlice {
combineList = append(combineList, env.ToRyeValue(v))
}
finalList := *env.NewList(combineList)
ctx.Set(wrd.Index, finalList)
return finalList
default:
return makeError(ps, "Type of tagword is not String or Block")
}
}
return makeError(ps, "Tagword not found.")
case env.Block:
s := &wrd.Series
wrd.Series = *s.Append(arg0)
//ctx.Set(wrd.Index, oldval)
return nil
dataSlice := make([]env.Object, 0)
switch blockData := arg0.(type) {
case env.Block:
for _, v1 := range wrd.Series.S {
dataSlice = append(dataSlice, env.ToRyeValue(v1))
}
for _, v2 := range blockData.Series.S {
dataSlice = append(dataSlice, env.ToRyeValue(v2))
}
default:
return makeError(ps, "Need to pass block of data")
}
return *env.NewBlock(*env.NewTSeries(dataSlice))
case env.String:
finalStr := ""
switch str := arg0.(type) {
case env.String:
finalStr = wrd.Value + str.Value
case env.Integer:
finalStr = wrd.Value + strconv.Itoa(int(str.Value))
}
return *env.NewString(finalStr)
default:
return makeError(ps, "Value not tagword")
}
Expand Down
5 changes: 4 additions & 1 deletion tests/misc.rye
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,13 @@ section "Functions that change values in-place"

group "append!"
mold\nowrap ?append!
{ { word } { object } }
{ { word } { object } { list } }
{
equal { b: { 1 2 3 } , append! 4 'b , b } { 1 2 3 4 }
equal { b: { 1 2 3 } , append! { 4 5 } 'b , b } { 1 2 3 { 4 5 } }
equal { b: list { 3 4 } , append! list { 1 2 } 'b , b } list { 3 4 1 2 }
equal { append! "ab" "cd" } "cdab"
equal { append! { 3 4 } { 1 2 } } { 1 2 3 4 }
}

group "change\ nth!"
Expand Down

0 comments on commit 16ce549

Please sign in to comment.