Thursday, October 9, 2008

ArrayAppend accepts single values

From the documentation, it looks like you need two arrays to use ArrayAppend. In Notes 8.02, at least, you can also use this function to add single values at the end of a dynamic array (arrays created using Split, NotesItemValues, etc).

Dim i As Integer, numberlist As Variant
numberList = Split( 1 )
For i = 2 To 20
numberList = Arrayappend( numberlist, i )
Next
Print Join( numberList, ", " )
'Prints 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20

It seems to work in the same way as Array.push in Javascript for adding single values to an array, and Array.concat for combining two arrays.

Update: To do the equivalent of Array.unshift in Javascript (add a value to the start of an array), it seems you need to split the value (the first parameter has to be an array).

Dim arr As Variant, i As Integer
arr = Split( 20 )
i = 20
While i > 0
i = i - 1
arr = Arrayappend( Split( i ), arr )
Wend

Print Join( arr, ", " )
'Prints 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20



I would think there would be a performance hit when dealing with a lot of values, but at least it's possible.

If IBM would just give us the Eclipse Java editor inside DDE, I could finally stop dealing with the crappy array-implementation in LS.

What would be even better was if IBM teamed up with Aptana for editing server-side Javascript agents/script libraries.. Throw in E4X for dealing with XML.. One can always dream.. :D

2 comments:

Tommy Valand said...

Thanks for the link! I hadn't heard of the project.

Will definitely try it out.. :)

Mike Miller said...

I used this tip today. Works in 7.0.2