? gets the value of the last expression evaluated.
Tokens of the form "id", where id is a LYMB identifier are assumed to be the names of objects that return numbers in response to "?" messages (typically scalar or logic objects).
Tokens of the form "id[expression]" are assumed to reference vector elements and are evaluated as if "[id @ expression ?]" had been typed. End_of_message is sent to the "id" object to reset the from and to indices.
Tokens of the form "id:iv" are assumed to reference an object ("id") and an instance variable of that object that returns a scalar ("iv").
Finally, tokens of the form "id(expression[,expression...])" are assumed to reference functions from the C math library. The supported functions are sin, cos, tan, fabs, abs (same as fabs), log, ln, log10, pow, rand, drand48, exp, sqrt, asin, acos, atan, and atan2.
scalar messages.
scalar new: tmp; scalar new: s = 57; scalar new: t mod= [tmp = s * 2 ?]; -- using a temporary scalar new: u mod= [s push! * 2 pop?]; -- using push/pop scalar new: v mod= [expr = `s * 2' ?]; -- using expr
Referencing scalar or vector instance variables is easier using expr, as is applying the value of complex expressions to scalar instance variables. To perform the following assignment without expr, a temporary scalar object is required because the tot_slider class does not have a slip/ message.
tot_slider new: t1 slip= [expr = `verbose_window_controller:x / 2' ?] ;
scalar new: tmp = [verbose_window controller x?] / 2; tot_slider new: t2 slip= tmp ;
LYMB's message/argument protocol makes its arithmetic precedence counterintuitive. For instance, if you want to assign "47 + (2 * 8)" to a scalar, you must first rearrange the expression to be "2 * 8 + 47":
Lymb> scalar new: s; Lymb> s = 47 + 2 * 8 print:value; s: value= (392.000000) Lymb> s = [expr = `47 + 2 * 8' ?] print:value; s: value= (63.000000)
Using complex expressions as the index of a vector are much easier using expr:
vector new: v = (15,12,47,-900,6,22); scalar new: s = [expr = `v[rand() v:dimension + 1]' ?];
The examples here are simple and have easy workarounds. More complex problems occur often enough to often make it easier to use the expr class to do arithmetic, however.