Fog Creek Software
Discussion Board




Knowledge Base
Documentation
Terry's Tips
Darren's Tips

I've got the (conditional (blues))

Problem: I want to include a specific selection of articles in a forfach x loop.

These articles should include the keywords "(html)" and "(design)" and either "(hints)" or "(nielsen)", but not "(css)" nor "(faq)". So I formed the following boolean hairball:

(and
      (keywordContains "(html)")
      (keywordContains "(design)")
      (or
            (keywordContains "(hints)")
            (keywordContains "(nielsen)")
      )
      (not (keywordContains "(css)")
      (not (keywordContains "(faq)")
)

However, this doesn't work as planned.

I have several articles which contain both (html) and (design) and (hints) in the keywords, yet they won't show up.

So far I've been at this for an hour and a half. Before I go into "crazy troubleshooting 'til dawn" mode, I wish to ask the following questions to the assembled experts:

1) Is the boolean clause above syntactically correct? I.e. should it work as intended? Does CD2 accept this kind of boolean nesting?

2) Does (not (condition)) only accept a single condition? Why?

3) Can anybody possibly point me at the egregious mistake I'm possibly making? I mean, aside from obsessing over this?

I can feel my mind going...

[P.S.: A Neat Thing I found out while doing this: You can do nice formatting within {$ .brackets $} including tab stops, CD won't mind. Thanks, Big Joel.]

geraldH
Monday, January 19, 2004

The two 'not' clauses need an extra ')' on the end.

Darren Collins
Monday, January 19, 2004

Thanks, but that was just an error in my transcript of the actual code. CD is really intolerant about these things, i.e. it warns you consistently when you forgot a bracket.

Other than that, would the above be accurate syntax?

geraldH
Monday, January 19, 2004

I haven't had any luck coming up with a solution for you; I keep getting stuck in parenthesis Hell!

David Burch
Monday, January 19, 2004

Alright it's getting late so it's entirely possible I've slipped a cog here but don't you need two more ands like so....
(and
  (and
      (and
        (keywordContains "(html)")
        (keywordContains "(design)")
        (or
              (keywordContains "(hints)")
              (keywordContains "(nielsen)")
          )
      )
      (not (keywordContains "(css)"))
      )
  (not (keywordContains "(faq)"))
  )
)

Ken McKinney
Monday, January 19, 2004

Actually, I just found out where my error lay. If I have an OR statement nested within an AND statement, one of the OR conditions must be met.

The articles that weren't caught by my boolean hairball met the first two AND conditions, but neither of the OR conditions. So it was an error within my keywords, not within my boolean syntax.

Ken: Your nested AND statements turned out to be unnecessary. The code works as is, with the two closing brackets mentioned by Darren.

Summing up:
AND needs at least two conditions. So does OR.
NOT can only contain one condition.
AND allows for nested NOT and OR statements.
CityDesk allows you to structure conditional clauses with tabulators (which is good to keep track of braces).

geraldH
Tuesday, January 20, 2004

*  Recent Topics

*  Fog Creek Home