Group Argument with Trailing Arguments


#1

I wanted to make my print helpers feel more like the :sk: println so I was trying something like this:

({Object} objs_as_strs
 Real    duration             : 0.0
 Color   text_color           : Color!rgba(0.0,0.66,1.0,1.0)
 ) 
[
  !result : String!
  objs_as_strs.do
  [
    result += item>>
  ]
  SystemLib.print_string(@@world, result, true, false, text_color, duration)
]

This works:
SystemLib.print_screen("Yo: ", 2, " and stuff", duration: 5)

This one does not work as intended for obvious reasons:
SystemLib.print_screen("Yo: ", 2, " and stuff", 5)

I’m wondering if there’s any other :sk: magic that would make it possible to pass arguments following a group argument without the use of named arguments.


#2

There are two additional options other than named arguments:

  • use types that don’t match the group argument type
  • put the extra arguments before the group arguments

As for passing in arguments that don’t match the type for a group argument, in this case of course {Object} will match any and all objects so that doesn’t help.

You could put them prior to the group argument, though that is potentially confusing:

( Real    duration             : 0.0
  Color   text_color           : Color!rgba(0.0,0.66,1.0,1.0)
 {Object} objs_as_strs
) 

Then call it like:

SystemLib.print_screen(5 Color!rgba(0 .66 1 1) "Yo: " 2 " and stuff")

// Skip color
SystemLib.print_screen(5, , "Yo: " 2 " and stuff")

// Skip both duration and color
SystemLib.print_screen(, , "Yo: " 2 " and stuff")

Compared to switching the order of the args above, I prefer specifying the later args by name after a group argument. This mechanism existed before Swift, though it looks similar to Swift where all the arguments are named.


Note that "" is the same as String! and probably more easy to read.

In the next update, if the desired class is known it can be inferred for a constructor - you don’t have to specify it.

So this default:

Color text_color: Color!rgba(0.0, 0.66, 1.0, 1.0)

Can look like this:

Color text_color: !rgba(0 .66 1 1)

Same thing with passing it as an argument:

SystemLib.print_screen("Yo: " 2 " and stuff" duration: 5 color: Color!rgba(0 .66 1 1))
SystemLib.print_screen("Yo: " 2 " and stuff" duration: 5 color: !rgba(0 .66 1 1))

And we will update the SkookumScript println() when we can.