Tuesday, February 19, 2013

To quote or not to quote

Quotes, really useful to convey a meaning or sentiment. When used in traditional software languages, quotes depict a string of characters. However, the mantra of expect-lite is keeping it simple, and quotes are not required.

In fact, quotes aren't even optional, and can cause problems when trying to quote strings. Take the following example:
$abc="hello world"
$def=hello world
The two variables are NOT equal. Expect-lite will store the quote characters as part of $abc.

Traditionally using quotes allows the programmer to encompass all characters between the quotes, but this becomes a problem when the quote character is part of the string to be stored. But then a whole system of escaping characters needs to be introduced.

Expect-lite eliminates all that complexity by storing everything after the equal sign, spaces, quotes, tabs, everything. Even more equals signs, such as below:
$equation=5 + 2 = 7

This feature is handy when assigning non-printable characters such as tab. It is possible to store the tab character by pressing the tab key after the equals sign:

The $tab can then be used to test tab completion of a command line, such as when using the bash shell, and pressing tab twice to see possible file names:
>ls /etc/rc$tab$tab

Quotes are not even required when using while loops or if statements. Expect-lite will just do the right thing. For example earlier we set the variable $def, and the following will totally work:
?if $def == hello world ? >hello back!

So save the quotes for Shakespeare, and remember expect-lite is about keeping it it simple.

No comments:

Post a Comment