11.07.2015 Views

[U] User's Guide

[U] User's Guide

[U] User's Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

[ U ] 18.3 Macros 209To a programmer, the length limit for string expressions may seem restrictive, but it is not, becauseof another feature discussed in [U] 18.3.6 Extended macro functions.There are some other issues of using macros and expressions that look a little strange to programmerscoming from other languages, at least the first time they see them. Say that the macro ‘i’ contains5. How would you increment i so that it contains 5 + 1 = 6? The answer islocal i = ‘i’ + 1Do you see why the single quotes are on the right but not the left? Remember, ‘i’ refers to thecontents of the local macro named i, which, we just said, is 5. Thus, after expansion, the line readslocal i = 5 + 1which is the desired result.There is a another way to increment local macros that will be more familiar to some programmers,especially C programmers:local ++iAs C programmers would expect, local ++i is more efficient (executes more quickly) than locali = i+1, but in terms of outcome, it is equivalent. You can decrement a local macro by usinglocal --ilocal --i is equivalent to local i = i-1 but executes more quickly. Finally,local i++will not increment the local macro i but instead redefines the local macro i to contain ++. There is,however, a context in which i++ (and i--) do work as expected; see [U] 18.3.7 Macro incrementand decrement functions.18.3.5 Double quotesConsider another local macro, ‘answ’, which might contain yes or no. In a program that wassupposed to do something different on the basis of answ’s content, you might codeif "‘answ’" == "yes" {. . .}else {. . .}Note the odd-looking "‘answ’", and now think about the line after substitution. The line readseitherorif "yes" == "yes" {if "no" == "yes" {either of which is the desired result. Had we omitted the double quotes, the line would have readif no == "yes" {

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!