← Back to team overview

ooc-dev team mailing list archive

Re: Array literals? Variable arguments?

 

Hey Damian,

Yes and Yes! Here's a snippet showing both methods: http://bpaste.net/show/10150/

In case bpaste.net goes down:

import structs/ArrayList

printArray: func (a: ArrayList<String>) {
    for(i in 0..a size) {
        "%d) %s" format(i, a[i] toCString()) println()
    }
}

readUntilStringA: func (a: ArrayList<String>) {
    "A" println()
    printArray(a)
}

readUntilStringB: func (args: ...) {
    "B" println()
    a := ArrayList<String> new()
    args each(|arg|
        if(T != String)
            Exception new("NNNNOOOOOO") throw()
        a add(arg as String)
    )
    printArray(a)
}

main: func {
    readUntilStringA(["1", "2"] as ArrayList<String>)
    readUntilStringB("1", "2")
}


Cheers,

Friedrich



Follow ups

References