Understanding parenthetical elements (parentheses)

(imported topic written by jonesy91)

Anyone reading the subject will know I’m not just new to the BF language, but coding as a whole, so please bear with me.

I’ve just started going through the documentation and while basic comprehension is there (I think), such as with simpler syntaxes, I see enough differences in how parentheses are used where fully understanding when and how I should use them is escaping me.

Generally speaking, it seems parentheses should be used to encapsulate an entire clause of what asking BF to do. For instance (from pg. 17 of the relevance language reference):

(files of folders “c:”) whose (name of it contains “a”)

Returns all files with an “a” in the name that exist on the C: drive.

But this:

files of folder “c:” whose (name of it contains “a”)

Will return “nonexistent object”, because it seems the “it” keyword is now looking for folders, not files. Not only that, but "files of folder “c:” can be viewed as one distinct clause related to each other, so not including them in parentheses is screwing things up.

Finally, because it is not in parentheses, the syntax is looking for the closest reference of an object, which in the second example is folder.

Maybe I’m correct in this or maybe not, but this is about the simplest representation of using parentheses. Getting into more heavy-duty stuff is another matter.

While practice and experience will solve a lot of the comprehension problems, I’m wondering if there’s any documentation, tips and so on, that might help. Using parentheses is clearly one of the building blocks of the language, so understanding them might help to unlock other things.

Thanks for any help!

(imported comment written by jessewk)

Hi Jonesy,

In general parenthesis are used to specify order of evaluation, where the most deeply nested sections are evaluated first, starting at the right side of the expression. Parenthesis tend to be over used and many of the parentheses you see will be unnecessary. Sometimes over use will provide clarity as to exactly what order will be used when evaluating an expression, but other times too many parenthesis can add confusion.

Whose clauses always require parenthesis. You’ll also generally have better luck if you wrap if statements in parenthesis too, like this: ( if () then () else () ) . Another common use of parenthesis is to control when a type cast is applied to an expression.

So back to your example… the behavior you are seeing is in fact due to your use of parenthesis to change the order of evaluation. Take your first expression:

(files of folders “c:”) whose (name of it contains “a”)

The relevance engine will evaluate the expression ‘files of folders “c:”’ first, which will return a list of

file

objects and then apply the whose filter to the list of files. In this case ‘it’ refers to a file object.

In your second expression, the order of evaluation is different:

files of folder “c:” whose (name of it contains “a”)

Here the relevance engine will evaluate ‘folder “c:”’ and then apply the whose filter to the

folder

object. ‘it’ will refer to the list of folders and in this case there is just one folder (which is a special case folder that doesn’t actually have a name) so it doesn’t pass the filter test. The singular expression error is thrown because there is no folder in the provided list of folders that passes the whose test.

Which is all to say, that your evaluation is basically correct and I think you’ll do fine with this stuff after a little more practice.

I hope my explanation adds a little clarity.

Jesse

(imported comment written by jonesy91)

Yes, Jesse, it does help. I’m happy to see I was correct in my thinking, and also the other rules you mentioned I knew for the most part (including the flexibility of their use, which because of the inconsistency isn’t helping).

Your first paragraph in particular I can already see will be useful.

Another quick question:

So far I haven’t found a place that list all the available keywords, operators and so forth. Is there one (hopefully with examples of their use)?

(imported comment written by JasonO91)

jonesy,

You can find all the information you seek here: http://support.bigfix.com/fixlet/

This contains the Relevance Quick Reference, examples, and the inspector guides.

Jason

(imported comment written by jessewk)

The documentation Jason points out is definitely the place to get started. Once you get more advanced, you might start to prefer using our “introspectors”. These are a set of inspectors that inspect the language itself. I virtually never consult the documentation and instead look up language details directly in the relevance/presentation debugger. There aren’t any examples or explaination so the documentation can be more useful, but in most cases I already have an idea what I’m looking for and this way I never have to leave the relevance evaluation tool.

Here are some example queires to try:

properties whose (it as string contains “file”)

properties whose (result type of it = type “file”)

properties of type “file”

casts

unary operators

binary operators

binary operators returning (type “integer”)

properties

If you evalaute the last one, ‘properties’, most of the items at the top of the list are the core types and introspectors.

Jesse

(imported comment written by BenKus)

And don’t forget about:

http://support.bigfix.com/inspectorsearch/inspector_search.html

And also be aware of our training class for relevance:

http://support.bigfix.com/training/course-202.html

Ben