Symbols as Macros

hwholmes

Member
I noticed in some code I was reading, that symbols were (or seemed to be) being defined by other symbols.
This got me to thinking about another proprietary language I used in my work where they where our "symbols" were called "labels" and it turned out were simply text substitution.

Some of us used this to improve self documentation of the code.
Example:
our timer was in interger count of 1/10ths of a sec so code like:
if T3 >= 20.... meant if the timer 3 had been running for more than 2 seconds ....

for documentation we would define a label called sec to be "0"
it worked like this:

sec:0
if T3 >= 2:sec:
which translated to :
if T3 >= 20

I don't think this would work with symbols because I think a space is needed to delineate the difference between the code and symbols.

however:

Some of our engineers saw a serendipity in this and started writing functions and even full lines of code as labels but then started refering to them as macros.

It worked something like this
F1: AO1 'analog output 1 used for deg F output
....
C1: AI5 'analog input 5 used for degC input
....
ToFahrenheight:* 9 / 5 + 2 'formula to be used many times
then code could be written as

:F1: = :C1: :ToFahrenheight:
which translated to :
AO1 = AI5 * 9 / 5 + 2

It looks to me as if symbols might be used the same way although not with the same ":" syntax.

possibly:
symbol TF1 = w0
symbol TC1 = w1
symbol toF = * 9 / 5 + 32

TF1 = TC1 toF
if I am right should compile as
w0 = w1 * 9 / 5 + 32

Sorry, I don't have my compiler handy to try it.
 

westaust55

Moderator
With the PICAXE, symbols can only be used to assign a name/alias to a variable or constant. It cannot be a macro to hold a formula/equation.

An alias can be assigned a value based upon a fixed pre defined value based upon an equation:

so the following is possible

symbol TF1 = w0
symbol TC1 = w1
symbol toF = 90 / 5 ; ten time the ratio

symbol offset = 320 / 10

TF1 = TC1 * toF / 10 + offset
 

hwholmes

Member
Thank you westaust55

Looking back at the manual that makes sense.

Pitty, precompile text substitution was fun to use.
thanks again!
 
Top