Why can variables be used without definition?

Dear LAMMPS Users,

In script “in.elastic”, I found that variables like pxx1,pyy1,pzz1,pyz1,pxz1,pxy1 are used without prior definition
The file path is lammps/examples/ELASTIC. Part of the script is as follows

#These formulas define the derivatives w.r.t strain components

Constants uses $, variables use v_

variable d1 equal -(v_pxx1-{pxx0})/(v_delta/v_len0)*{cfac}
variable d2 equal -(v_pyy1-{pyy0})/(v_delta/v_len0)*{cfac}
variable d3 equal -(v_pzz1-{pzz0})/(v_delta/v_len0)*{cfac}
variable d4 equal -(v_pyz1-{pyz0})/(v_delta/v_len0)*{cfac}
variable d5 equal -(v_pxz1-{pxz0})/(v_delta/v_len0)*{cfac}
variable d6 equal -(v_pxy1-{pxy0})/(v_delta/v_len0)*{cfac}

Although these variables are defined in file “displace.mod”, I think the order sames to be wrong.
The correct order should be: define the variable first and then use it.
How to explain this? Or can you tell me the grammar rules?

Thanks for your help

The variables are defined in displace.mod. That file is included after the variables you refer to are defined. However, if uses the “reference”-syntax for pxx1, delta_v and len0. That means that those variables will only be expanded when the resulting variables, d1…d6, are actually evaluated. The ${…}-syntax variables are expanded when they are encountered. Therefore, pxx0, pyy0, pzz0, pxy0, pxz0 and pyz0 and cfac need to be defined before the variables d1…d6 are expanded and they are because they are defined in init.mod or in in.elastic before these variables are defined.

Does all of this make sense? So variables with v_… are delayed-evaluated, meaning you can technically use them before they are defined because they will not be expanded until needed. ${…} on the other hand, has to be defined when it is encountered.