Using INCLAN variables: Difference between revisions
 (Created page with '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…')  | 
				No edit summary  | 
				||
| (3 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
In INCLAN, string variables can be used in a similar way as in a Unix shell:  | 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."  |  cyana> name:=Cyana  | ||
My name is Cyana.  |  cyana> print "My name is $name."  | ||
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:  |  My name is Cyana.  | ||
cyana> x=7  | |||
cyana> y=5*x  | 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> z=sqrt(y-10.0)  | |||
cyana> show x y z  |  cyana> x=7  | ||
 cyana> y=5*x  | |||
 cyana> z=sqrt(y-10.0)  | |||
 cyana> show x y z  | |||
(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 “:=”:  |      x = 7  | ||
cyana> y:=5*x  |      y = 35  | ||
cyana> show y  |      z = 5.0  | ||
cyana> y=5*x  | (The INCLAN command [[INCLAN: show|'''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> show y  | |||
 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:  | 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)  |  cyana> s:=cyana  | ||
*** ERROR: Illegal expression "lenstr(s)".  |  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:  | 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  |  cyana> l=lenstr('$s')  | ||
 cyana> show l  | |||
     l = 5  | |||
Single quotes do not inhibit variable substitutions.  | Single quotes do not inhibit variable substitutions.  | ||
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.