Ben Langhinrichs

November, 2014
SMTWTFS
      01
02 03 04 05 06 07 08
09 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30

Search the weblog





























Genii Weblog

Parenthetically speaking

Fri 18 Jun 2004, 02:27 PM



by Ben Langhinrichs
I answered a post in the Gold forums recently that reminded me of another of those small nuisance items that tend to plague beginners, and even some who are not beginners but may just be having brain fog.  The problem was how to compose a server:database list in formula language for an @DbLookup when the database was to be made up of parts, and the attempt to use

@DbLookup("":"NoCache";"Server":"QuickPlace\\" + "databasdir" + "\\Main.nsf";"QPFolderIndex";"1";2)

was failing.  Now, leaving aside other issues such as the quotes that probably should not be around databasedir and other minor changes that I have made from the original question, this is a classic case of list addition gone awry.

Let's just look at the server:database pair:

"Server":"QuickPlace\\" + "databasdir" +"\\Main.nsf"

As shown, the result would be 

"Serverdatabasdir\\Main.nsf":"QuickPlace\\databasdir\\Main.nsf"

which certainly isn't what is desired.  Let's decompose this and see why we get that result.  Imagine the question were a:b+c+d and the result acd:bcd.  In this case, the implied parentheses are ((a:b)+c)+d, so working from the inside out, we get (ac:bc)+d and then acd:bcd.  We can't rely on the implied parentheses, but must add our own to help the formula language know what we want.  So, instead of a:b+c+d, we should use a:(b+c+d), which will then evaluate to a:(bcd) and then a:bcd.  Given that, our original database argument should be changed from

"Server":"QuickPlace\\" + "databasdir" +"\\Main.nsf"

to

"Server":("QuickPlace\\" + "databasdir" +"\\Main.nsf")

which will then result in

"Server":"QuickPlace\\databasdir\\Main.nsf"

which is what we want.  I guess the moral is that it is always better to overutilize parentheses than to underutilize them.

Copyright © 2004 Genii Software Ltd.

What has been said:

No documents found