Using INCLAN variables: Difference between revisions
No edit summary |
No edit summary |
||
Line 5: | Line 5: | ||
My name is Cyana. | My name is Cyana. | ||
The operator “:=” assigns a string (“Cyana”) to a variable (“name”). $variable substitutes the value of a variable into the command line. In addition, variables with numeric values can be used in expressions in the same way as in Fortran or other programming languages: | The operator “:=” assigns a string (“Cyana”) to a variable (“name”). $''variable'' substitutes the value of a variable into the command line. In addition, variables with numeric values can be used in expressions in the same way as in Fortran or other programming languages: | ||
cyana> x=7 | cyana> x=7 |
Latest revision as of 12:04, 14 August 2009
In INCLAN, string variables can be used in a similar way as in a Unix shell:
cyana> name:=Cyana cyana> print "My name is $name." My name is Cyana.
The operator “:=” assigns a string (“Cyana”) to a variable (“name”). $variable substitutes the value of a variable into the command line. In addition, variables with numeric values can be used in expressions in the same way as in Fortran or other programming languages:
cyana> x=7 cyana> y=5*x cyana> z=sqrt(y-10.0) cyana> show x y z x = 7 y = 35 z = 5.0
(The INCLAN command show displays the values of variables.) Here a different assignment sign, “=” instead of “:=”, was used. Assignments with “=” have the meaning: “Evaluate the expression on the right hand side and assign the result value to the variable on the left hand side.” Note the difference to a string assignment with “:=”:
cyana> y:=5*x cyana> show y y = 5*x cyana> y=5*x cyana> show y y = 35
Expressions formed according to the rules of Fortran-77 may contain integer, real and complex numbers, logicals (Boolean values), and character strings. Within expressions character strings must be enclosed in single quotes:
cyana> s:=cyana cyana> l=lenstr(s) *** ERROR: Illegal expression "lenstr(s)".
This is an error because the variable s does not contain a quoted string (lenstr is an INCLAN function that returns the length of a string, i. e. the index of its last non-blank character). The correct use of simple, unquoted strings in an expression is:
cyana> l=lenstr('$s') cyana> show l l = 5
Single quotes do not inhibit variable substitutions.