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.
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:
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 #.
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
My preference is # because following code is legal
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.
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.
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.
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.