xsharp.eu • placement of condition in count command
Page 1 of 1

placement of condition in count command

Posted: Thu Oct 21, 2021 2:25 pm
by kevclark64
In Foxpro either of the following is valid:

COUNT FOR state="CA" TO statecount
COUNT TO statecount FOR state="CA"

The X# compiler currently only allows the second construction in which the variable is named before the condition. I haven't tested it, but I wonder whether this is a general issue that might affect commands similar to COUNT.

placement of condition in count command

Posted: Thu Oct 21, 2021 3:16 pm
by robert
Kevin,
The X# compiler allows to freely change the order of optional clauses in user defined commands.
The COUNT command is declared as

Code: Select all

#command COUNT TO <var>    ;
         [FOR <for>]       ;
         [WHILE <while>]   ;
         [NEXT <next>]     ;
         [RECORD <rec>]    ;
         [<rest:REST>]     ;
         [ALL]             ;
         ;
      => <var> := 0 ;
       ; DbEval( ;
                 {|| <var> := <var> + 1}, ;
                 <{for}>, <{while}>, <next>, <rec>, <.rest.> ;
               )
As you can see: the TO <var> is not optional (not between brackets) and therefore not optional.
I will see if I can tweak the command to allow TO <var> to be at the end of the command.
Making the TO <var> clause optional would technically work and allow to swap the TO and FOR clauses.
But if TO is missing then it would need to generate a compiler error.

Robert

Edit:
Maybe we can add a special notation to indicate that the "optional" clause is not really optional but can be moved around freely.
Something like this:

Code: Select all

#command COUNT [^TO <var> ]   ;
         [FOR <for>]       ;
etc
where the ^ character would tell the preprocessor that the TO <var> clause has to be matched.

placement of condition in count command

Posted: Fri Oct 22, 2021 7:38 am
by lumberjack
Robert,
robert wrote:Kevin,
The X# compiler allows to freely change the order of optional clauses in user defined commands.
I created quickly a new count command and it seems according to the .ppo file it creates the correct output.

Code: Select all

#command COUNT ;
         [FOR <for>]       ;
         [WHILE <while>]   ;
         [NEXT <next>]     ;
         [RECORD <rec>]    ;
         [<rest:REST>]     ;
         [ALL]             ;
         TO <var>    ;  // Note where the TO <var> is positioned
      => <var> := 0 ;
       ; DbEval( ;
                 {|| <var> := <var> + 1}, ;
                 <{for}>, <{while}>, <next>, <rec>, <.rest.> ;
               )

placement of condition in count command

Posted: Fri Oct 22, 2021 7:47 am
by robert
Johan,
Yes that works. And it matches both

Code: Select all

COUNT TO Var FOR SomeCondition
and

Code: Select all

COUNT FOR SomeCondition TO Var 
Why did I not think of that myself?
I will adjust the UDC in our header file
Robert

placement of condition in count command

Posted: Fri Oct 22, 2021 7:48 am
by robert
Robert,
I created quickly a new count command and it seems according to the .ppo file it creates the correct output.
I use the (new) UDC Tester for this. That works very well !

Robert

placement of condition in count command

Posted: Fri Oct 22, 2021 8:00 am
by lumberjack
Robert,
robert wrote: I use the (new) UDC Tester for this. That works very well !
I have to apologize was not focusing on computer work the last couple of months due to my eyes, but I am feeling ready to start again.
Have downloaded the new version and will next week install and see how the next article in the Data-driven series progress.