Suggestion for future

There is very useful feature in Clarion language: if a code line begins with the ? character, it compiles in the debug mode only, i.e. if the debug(vid) pragma has value full or min.

I suggest to have another “magic” character in the first source line position to instruct the compiler to compile it if profile mode is turned on and omit if it is off. The profile mode can be turned on by the pragma debug(profile=>on) or define(profile=>on), default value is off.

At the moment it’s need to use OMIT/COMPILE blocks for profiling code as for usual conditionally compiled code. But as a rule profiling code consists of single calls to start/stop particular timer or counter. Usage of OMIT/COMPILE blocks makes the code less readable.

It would be useful to allow that new “magic” character in thee data section too to declare data used for profiling.

How about
?(X)
where the line is conditionally omitted when the pragma X is false

which means
?
would be the equivalent of
?(vid)
hmm, the full/min aspect might need a more elaborate notation

and your suggestion would become
?(profile)

In my opinion, the magic line prefix of length more than 1 is not convenient. Readability of code is very important.

The “>” symbol would be appropriate IMO.

I’m considering > or #

Its a shim which is a hacking risk but is also a handy tool.

Specifies the compiler will invoke a procedure call at the beginning and end of compiling each procedure. This allows you to implement your own profiler. The prototypes for these procedures must be:

EnterProc(UNSIGNED Line,*CSTRING Proc,*CSTRING, File),NAME(‘Profile:EnterProc)
LeaveProc(),NAME(‘Profile:LeaveProc)

The EnterProc is called at the beginning of each procedure and LeaveProc at the end.

Is this to make it easier to include Unicode data types in an app so that Profile can be used to switch from Ansi to Unicode easily?

Col 1 # is a comment in languages like Python, Bash, Ruby, Perl, and R
Col 1 # is a preprocessor command in C/C++
Col 1 > is a preprocessor command in Fortran
Col 1 > is quoted block of text in text formats, markdown, or documentation files

Python is taught the most at Universities in the first year, and in CS courses switch to C/C++ in the second year.

If you are catering for new/future users I would probably go with #.

JMO.

This is too crude mechanism in my opinion. If pragma define(profile) is on, the compiler generates calls to Profile:EnterProc on entry to all functions and routines and calls to Profile:LeaveProc on return. Usually it’s need to do measuring between some points in the source code.

Any character can be potentially used in any position in Forth :slight_smile:

My preference is # because following code is legal

 IF A |
> 0
 ...
 END

Could you use the same character? If debug is off then the profile pragma takes effect (or not)
That assumes that no one does debugging and profiling at the same time though.

I considered ? - lines beginning with ? Could be compilable if debug or profiling modes or both are on. The reason why ? character is not suitable for lines with profiling code is desire to allow such lines in the data section. The compiler allows identifiers beginning with ? character. It’s a side effect of considering controls’ equate labels as EQUATEs.

In part it was readability that I had in mind when I made the suggestion. By referencing the pragma define, it becomes self documenting what condition we’re omitting based on - which makes it readable.

readability and power/flexibility too, Instead of adding some special symbol that is only useful for the single case of profiling, I was suggesting something that could be used for a wide variety of situations.

# is used in the template language to indicate the start of a template command. I dont think reusing it in this way will be helpful.

I do not see problems here:

  • Clarion source code and Clarion template code are different animals
  • It’s oossible to use any characters in embed points
  • The template language has the special construct %# expanding to a single sharp character
    Really, the choice for the new “magic” character is very narrow because it must be a symbol which can’t be a lexeme itself and none valid lexeme can start with it. Plus such character must be confidently determinable being typed using wide range of fonts. Besides mentioned I see only tilda character as a candidate.

Harder to see with old age…

and might be mistaken for a -.

-~#?
#~-?
?~#-
~#?-

As you pointed out, the current ? notation which omits the line in release mode
does not work in code sections

But it would be great if we had a notation that did work in the code section

Say we want one set of variables when compiling in CW11 and another in all others earlier versions
right now we write

    COMPILE('****',_C110_)
SomeVariable LONG
    '****'
    OMIT('****',_C110_)
SomeVariable SHORT
    '****'

now imagine

?(_C110_)SomeVariable   LONG
?(_C110_=0)SomeVariable SHORT

Since the symbols ‘(’ & ‘)’ are not allowed in labels,
it seems possible to implement such a feature in the data section

Please also allow white space inside of the ( ),
so I can vertically align things, which in my opinion improves readability

?(_C110_  )SomeVariable LONG
?(_C110_=0)SomeVariable SHORT

On this point

Something I do is put these sort of commands/directives in another column.

I do something similar when debugging templates.

    Line 67:   #IF(%EditProcedure)											#Call(%grpDebugView,'#IF(%EditProcedure)')
	Line 68:   #CREATE(%EditFilename) 										#Call(%grpDebugView,'#CREATE(%EditFilename)')                                                                                                                                   
	Line 69:   #FIND(%ModuleProcedure,%EditProcedure)                       #Call(%grpDebugView,'#FIND(%ModuleProcedure,%EditProcedure)')                
	Line 70:   #FIX(%Procedure,%ModuleProcedure)                            #Call(%grpDebugView,'#FIX(%Procedure,%ModuleProcedure)')                
	Line 71:   #MESSAGE('Generating Module:    ' & %Module,1)               #Call(%grpDebugView,'#MESSAGE(''Generating Module:    '' & %Module,1)')                
	Line 72:   #MESSAGE('Generating Procedure: ' & %Procedure,2)            #Call(%grpDebugView,'#MESSAGE(''Generating Procedure: '' & %Procedure,2)')                
	Line 73: 																#Call(%grpDebugView,'#GENERATE(%Procedure)')
	Line 74: 															    #Call(%grpDebugView,'*** %Procedure Template Code Start ***')
	Line 75:   #GENERATE(%Procedure)                                        #Call(%grpDebugView,'*** %Procedure Template Code End ***')                
	Line 76:   #COMMENT(80)                                                 #Call(%grpDebugView,'#COMMENT(80)')                
	Line 77:   #CLOSE                                                       #Call(%grpDebugView,'#CLOSE')
	Line 78: 															    #Call(%grpDebugView,'#ABORT')
    Line 79:   #ABORT

So maybe this would an option for readability?

                                                 COMPILE('****',_C110_)
SomeVariable LONG
                                                 '****'
                                                  OMIT('****',_C110_)
SomeVariable SHORT
                                                 '****'

If the problem is in types only, use EQUATE to declare identifier for variables types depending from such condition.

The difference between a single character as the “magic” line prefix and your construct is quite sufficient. A single character prefix requires ~10 lines of code in the scanner only. The construct ?(condition) requires adding several new rules to the language gramma. Not too complex but this is another level of complexity + the syntax analyzer is being need to process these rules for every source line.

IF A |  <-- this "|"is a vertical line seperator not a mispelled C++ Comment which is //
~ 0
 ...
 END

So I think you are sh1t testing cuz the ~ is the NOT symbol and thus would be legal code as well.

Dont use ~ personally for the reason of not being able to see it easily and mistaking it as a - :grinning_face:

Sure the scanner must be a fair bit more complex to change from checking your proposed single character at the start of a line, to my proposed syntax

But I feel you’re making the wrong comparison.
IMO, The correct comparison is to compare it to what is needed for the OMIT/COMPILE parsing code. Which is what it could replace in many instances

While I do use profile from time to time, I’ve never wanted to conditionally omiit/compile code based on profile, apart from conditionally exposing an intentional bug in the module that contains EnterProc / LeaveProc - to avoid infinite loops.

But I do have hundreds if not thousands of other cases where I am using OMIT/COMPILES

In addition to all of that, the new notation might also solve some of the challenges related to nested OMIT/COMPILES which have been painful for me.

I’m taking chances for the feature to be implemented into account.

Implementation of the single character line prefix can be done in 5-10 minutes with full confidence because the new code is practically duplicates one for the ? prefix.

I hadn’t considered that , but I have confidence in your abilities to solidly implement my variation on your suggestion.