Open GhbSmwc opened 2 years ago
Those two code snippets are identical. You copypasted something incorrectly.
Oops, thanks. Fixed.
I do think this behavior is documented in the manual. Specifically, I think it's documented that defining with = does not evaluate a define immediately, while defining with := does. Considering this, I'd say the behavior here is exactly what one would expect.
Looking at the manuel:
equal to the standard =, but resolves all defines in the text to assign before actually assigning it. This makes recursive defines possible.
So it is indirectly mentioned. Also this is backwards, = is the one that resolves the entire document before assigning it, :=
is the one that does not look ahead in the document when assigning to a define that isn't defined yet.
=
does not "resolve the entire document" before assigning. for example, this doesn't work:
!a = !b
print "!a"
!b = 2
=
simply sets the contents of the define equal to exactly what you specify, which may contain more defines. the value of !a in that example literally is "!b", not "2". using a define recursively evaluates all defines in it, so in this example:
!a = 2
!b = !a
print "!b"
print "!b"
gets expanded to print "!a"
, which then gets expanded to print "2"
.
on the other hand, :=
replaces all defines in the right-hand side at the time of definition, so in this example:
!a = 2
!b := !a
!a = 3
in the 2nd line, the value of !a
is still 2, so !b
becomes 2
, (literally the number 2, not "!a"
), and modifying !a after that won't affect !b
.
@randomdude999 Thanks for the info. I sould take the time to explore more on the document.
Was wondering how asar processes the defines in order:
And I am not sure if this is documented in the help section. The above code does not error out saying
define2
is not defined (yet) since the first linedefine1
was being set bydefine2
before that was being defined.However this does error out:
So it seems like the
print
command does not "look ahead" on the code and evaluate things orderly, but defines themselves when a value isn't given will look ahead to find that define on what its being set to.