Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

2 replies to this topic
• Moderators
• 717 posts
• Last active: Jul 31 2014 08:27 PM
• Joined: 27 Mar 2008
These calls are equivalent:
```test(  [1,2,3]   )
test([ [1,2,3] ]*) ; this is the same as above it just wraps it as an array and unpacks it again

test( v ) {
msgbox % v.maxindex()
}```

But when recursively calling a variadic param it fails:
```msgbox % "final result:`n" objnests(test(1,[1,2,3]))

test( i, v* ) {
msgbox % "nest #" i "`n" objnests(v)
if i < 3
return test(i+1, [v]*)  ; this works fine
;return test(i+1, v)    ; but this fails to re-wrap v as an array, and instead passes [""]
; however they should be equivalent
return v
}

objnests( obj ) {
; returns the maxindex of  obj and obj[1] recursively if obj[1] is an object
;     outermost maxindex on the left, innermost on the right
; e.g.
;   [1,2,3]      returns: 3
;   [[1,2,3]]    returns: 1 <- 3
;   [[[1,2,3]]]  returns: 1 <- 1 <- 3 . in other words: this object has a maxindex of 1 with a child that has a maxindex of 1 and a grandchild that has a maxindex of 3
return obj.maxindex() (IsObject(obj[1]) ? " <- " objnests(obj[1]) : "")
}```