hi! i have a few questions that came up recently when discussing differences between Swift and Kotlin, the motivating context being differences between how the languages pass default parameter values. in particular, i was wondering:
- are there semantic guarantees about how default parameters are evaluated in Swift? e.g. are they always evaluated in the caller's context (i.e. how the
#file
directive/macro behaves)? - and more generally, are there 'formal' semantic guarantees about how functions/methods are evaluated & invoked? e.g. is argument evaluation always left to right, eager vs lazy, etc.
regarding question 1
, i did find this documentation on macro expansions that states:
A macro-expansion expression can’t appear as the default value for a parameter, except the file() and line() macros from the Swift standard library. When used as the default value of a function or method parameter, these macros are evaluated using the source code location of the call site, not the location where they appear in a function definition.
but this wording doesn't clarify the evaluation context of default arguments in general. i also found this quote from John McCall regarding evaluation order:
Swift uses a strict left-to-right evaluation order in most situations.
which begs the question: in what situations does the evaluation order differ? lastly, i also found this documentation on the ABI calling conventions, however i'm not well-versed enough in the domain to easily see how it does or does not address questions like order of argument evlaution, etc.
thanks in advance for any pointers/insights on this topic!