1. I'm afraid this is a noobie question (or it might be because I'm confused because of my experience with other programming languages). In the example:

    print(string.format(“%2$d, %1$d, %d“, 13, 17))

    I can't understand why it prints 17, 13, 17. I understand the first two, since the n$ addition will print argument number n. But why does the last one print 17 and not 13 or even nil (as there are two arguments instead of three)?

    I'm afraid this is a noobie question (or it might be because I'm confused because of my experience with other programming languages). In the example:

    print(string.format(“%2$d, %1$d, %d“, 13, 17))

    I can't understand why it prints 17, 13, 17. I understand the first two, since the n$ addition will print argument number n. But why does the last one print 17 and not 13 or even nil (as there are two arguments instead of three)?

    What happens with the positional arguments is that string.format will move ahead to that point in the argument list. So after filling in %2$d, it is looking at the third argument after the format string, which doesn't exist. Then $1$d moves it to the first, so the 'next' argument is 17. You can see this with the following:

    print(string.format("%2$d, %d, %1$d, %d", 13, 17, 27))
    

    It should print 17, 27, 13, 17. Hope that makes sense!

    I see, thank you! Now I wonder, would there be any way to move the "pointer" to the argument list without printing that specific argument? That is, when writing "%1$d" Lua goes back to the first argument and prints. How to avoid the printing? I'm just curious now, I guess it would be easier to just use specific numbers.

    Thank you for everything, I love your book!

    Once you start using positional arguments you're best bet is to specify everything explicitly. But it's really only meant to be used for localisation, for languages that require it.