placement of condition in count command

This forum is meant for questions about the Visual FoxPro Language support in X#.

Post Reply
User avatar
kevclark64
Posts: 127
Joined: Thu Aug 15, 2019 7:30 pm
Location: USA

placement of condition in count command

Post 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.
User avatar
robert
Posts: 4518
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

placement of condition in count command

Post 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.
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
lumberjack
Posts: 727
Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa

placement of condition in count command

Post 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.> ;
               )
______________________
Johan Nel
Boshof, South Africa
User avatar
robert
Posts: 4518
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

placement of condition in count command

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
robert
Posts: 4518
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

placement of condition in count command

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
lumberjack
Posts: 727
Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa

placement of condition in count command

Post 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.
______________________
Johan Nel
Boshof, South Africa
Post Reply