Dynamic Function Arguments?
-
Is there a keyword to access the arguments of a function as an array, similar to how the built in print function works?
I am trying to write a print line function that basically wraps print() but adds a new line char at the end. I know that I could just pass my arguments as an array and use a for loop to concat the string but that seems too messy and a waste.
Thank you for all the help!
-
I’m afraid it’s not possible. But you can concatenate strings with + instead of using , and that way you can use the same arguments to your own print function and the built-in one...
-
@vinicity Thanks! I really liked how clean the syntax was with commas so I think I'll just stick with adding "\n" manually at the end of everything.
-
You could write something like this:
function joinArray(values, separator) string result = "" int i for i = 0 to len(values) loop if i > 0 then result += separator endif result += str(values[i]) repeat return result function printLn(value) print(value + "\n") return void // then call like this: string joined = joinArray([1, 2, "test", [.example = true] ], "\n") printLn(joined)
-
@PB____ yeah, that's what I was trying to avoid. I'd rather just type the extra "\n" and save the extra syntax and compute cycles. Thank you though!