Is it possible for a functionality where parameters can be used within parameters?
lets say I have
struct TwoDPoint {
var x : Int
var y : Int
init(x : Int, y : Int) {
self.x = x
self.y = y
}
}
static func someFuncThatPrintsSquaresNTimes( point: TwoDPoint , N : Int ) {
.....
.....
....
}
// using another parameters values
someFuncThatPrintsSquares( point : TwoDPoint(x : 5, y: 3), N : point.x * 5)
I know the function I am using is not a concrete example but nonetheless it demonstrates the point. If this is also not possible to include in Swift at a compiler level, please explain reason why. Im not a compiler expert.
Actually, what you're asking doesn't fit in compile-time expressions, either. The short answer is that it doesn't even make sense. A function parameter only has a value within the body of the function. It doesn't exist at the call-site, where it's only a label.
Why do you want to solve the problem in such a complex way?
What @rguerreiro showed is the right way to do it here. The pitched feature and call-site that was shown in the original post hurts code readability a lot and does not solve a real world issue in my eyes. Furthermore it won't work when parameter labels are missing (e.g. if it was _ point: instead).