onyx-lang icon indicating copy to clipboard operation
onyx-lang copied to clipboard

Feature suggestion: keyword splats

Open stugol opened this issue 9 years ago • 3 comments

Suggest support for Ruby 2.0+ style **args keyword argument splats.

stugol avatar Feb 21 '16 22:02 stugol

I think this would be much better solved with an Opts/Options class, that is essentially a Map easily casted to each required type else defaulted, etc. (host = opts["host"].else "default_host")

With som access-sugar for []-methods it could be made very sleak - without adding to the language (just from the hip: host = opts#host.else "default_host").

In that "imagined example", else would return the val if it's of the type of the default-val, otherwise default val - or something along those lines, reasonable behaviour for the use-case.

While coding in the nodejs world, it was very common to pass a hash-tree as last arg for confs/options, and also the funcs took either a hash (to simulate named args), or regular parsing if first arg wasn't an hash. So that's what first strikes my mind for the use cases.

Of course currently, there would be some type mismatch hassle if simply passing a Map and defining just some keys. But, as said, other more generic re-usable features would improve that situation.

ozra avatar Feb 24 '16 20:02 ozra

What if I don't want to supply a default value?

stugol avatar Feb 24 '16 20:02 stugol

Then just foo#bar.to-s, foo#bar as Str or which ever method ticks your clock ;-) These suggestions should be filed in the "pseudo domain", just off the top of the head ideas.

ozra avatar Feb 24 '16 23:02 ozra