Variables [examples]

Display the contents of the current memory variables
LIST_MEMORY
list memory

https://www.lianja.com/doc/index.php/LIST_MEMORY


Display the contents of the current memory variables
DISPLAY_MEMORY
display memory

https://www.lianja.com/doc/index.php/DISPLAY_MEMORY


procedure if(if)
return if
 
if = "hello"
if if = "hello"
    echo if( if )
endif

There are no reserved words in Lianja. Command names can be used as variables names and database field variables.

https://www.lianja.com/doc/index.php/A_Lianja_Primer


private x
x = 10    // x already exists
y = 10    // y does not yet exist so it is created
 
set strict on
z = 10   // error is thrown as z does not exist and STRICT is ON

Variables in Lianja do not need to be explicitly declared, although they should be for better code readability and maintainability. When an expression is assigned to a variable, if the variable does not already exist then it will be created implicitly unless SET STRICT ON is in effect.

Simple Variables

Variable names must begin with a letter (A-Z, a-z) or an underscore (-), followed by any combination of letters, digits or underscores. The variable name can be of any length, but only the first 32 characters are significant, so these must be unique. Lianja ignores the case of letters, so m_var, M_VAR, and m_VaR would all be treated as the same memory variable name. The name given to a variable has no bearing on the type of data that is, or can be, stored in it. In fact, the type of data stored in a particular variable can be changed at any time unless SET STRICT is ON, in which case Lianja will type check variables on assigment to them.

m_var = 1234
m_var = 'a character value'
? m_var + 100

Variables can be declared and optionally initialized before used.

private m_var = 1234
m_var = 'a character value'
? m_var + 100

Variables can optionally be declared as specific datatype.

private m_var as numeric = 1234
m_var = 'a character value'    // throws an error

https://www.lianja.com/doc/index.php/A_Lianja_Primer


Assigment Statements

The assignment statement stores the result of the expression expression into a variable.

variable = expression

If the variable does not exist and STRICT is OFF, then it is created. If the variable already exists, its contents are updated. If the variable does not exist (has not been declared) and STRICT is ON, then an error is thrown. When STRICT is ON, you should pre-declare variables before assigning values to them using the private, public or local commands.

private myvar
 
set strict on
// no error as myvar has already been declared
myvar = "hello world"
 
set strict off
// error as newvar has not been declared
newvar = 10

You can declare and initialize variables in one statement

private myvar = "hello world today is " + cdow( date() )

Lianja automatically performs type conversions for variables. If, for example, an existing variable called name contains a character string, and the command name=10 is executed, the variable will automatically be converted to a numeric variable.

If you explicitly tell Lianja what type of data can be stored in a variable, it will perform data type checking at runtime.

private myvar as character = "hello world today is " + cdow( date() )
 
// an error will be thrown because myvar was declared as a character
myvar = 10

https://www.lianja.com/doc/index.php/A_Lianja_Primer


private nVar as numeric
// Valid assignment
nVar = 1234
// Throws error
nVar = 'a character value'
public cVar1 as character, nVar1
private cVar2, nVar2 as numeric
local cVar3, nVar3, dVar3 as date
public cVar1 as character 
cVar1 = 'start value'
private cVar1 as character 
cVar1 = 'start value'
local cVar1 as character 
cVar1 = 'start value'
store 'new value' to cVar1
cVar1 = 'newer value'
store 'new value' to cVar1, cVar2
nVar = 1234
echo nVar
echo m.nVar
echo m->nVar
if isset(nVar)
  // nVar exists
endif
if isset(nVar)
  unset(nVar)
endif
private cVar as character
cVar = "Hello World"
? type("cVar")
C
? is_string(cVar)
.T.
private nVar as numeric 
nVar = -12.34
? type("nVar")
N
? is_float(nVar)
.T.
? is_int(nVar)
.T.
private dVar as date 
dVar = date()
? type("dVar")
D
private lVar as logical 
lVar = .T.
? type("lVar")
L
private tVar as datetime 
tVar = datetime()
? type("tVar")
T
private yVar as currency 
yVar = $99.99
? type("yVar")
Y

https://www.lianja.com/doc/index.php/Lianja_Variables_and_Constants


Decrement memory variable by one

i=100
do while i > 0
    --i
enddo

https://www.lianja.com/doc/index.php/Decrement


Increment memory variable by one

i=0
do while i <100
    ++ i
enddo

https://www.lianja.com/doc/index.php/Increment


Return scope information about a memory variable or array
VARINFO
function func1
public m_var1
private m_var2
? "m_var1 " + varinfo("m_var1")
? "m_var2 " + varinfo("m_var2")
?
endfunc
 
func1()
m_var1 Public                                                                   
m_var2 Private (FUNC1) 

https://www.lianja.com/doc/index.php/VARINFO()


Delete memory variables and free the storage that they were occupying
UNSET
if isset(m_var)
  unset(m_var)
endif

https://www.lianja.com/doc/index.php/UNSET()


Check whether a variable exists
ISSET
if isset(m_var)
  // m_var exists
endif

https://www.lianja.com/doc/index.php/ISSET()


Declare a memory variable or array local to the current procedure and optionally assign a data type and value
LOCAL
local cTmpbuf
? cTmpbuf
.F.

https://www.lianja.com/doc/index.php/LOCAL


Declare public memory variable and optionally assign a data type and value
PUBLIC
public i as numeric, j as character, k

https://www.lianja.com/doc/index.php/PUBLIC


Delete memory variables and free the storage that they were occupying
RELEASE
release i,j,k
release all like code_*
release all except c?de_*
release all

https://www.lianja.com/doc/index.php/RELEASE


Declare memory variables private to a procedure or program and optionally assign a data type and value
PRIVATE
private i as numeric, j as character, k 
i = 42
? k
.F.

https://www.lianja.com/doc/index.php/PRIVATE


Release all memory variables
CLEAR_MEMORY
clear memory

https://www.lianja.com/doc/index.php/CLEAR_MEMORY


Save the result of an expression in a memory variable
STORE
store "hello " to string1
store string1 + "world" to string2
? string2
hello world
area = length * width
area = "change to a string"

https://www.lianja.com/doc/index.php/STORE


Save the current memory variables to a file
SAVE
save to monday all like mon_*
save to others all except mon_*

https://www.lianja.com/doc/index.php/SAVE


Restore memory variables and arrays previously saved with the SAVE command
RESTORE
restore from monday additive

https://www.lianja.com/doc/index.php/RESTORE


Initializes memory variables corresponding to the current record of the active table
CLEAR_AUTOMEM
use customers
store automem
clear automem

https://www.lianja.com/doc/index.php/CLEAR_AUTOMEM


Generate memory variables corresponding to the current record
STORE_AUTOMEM
set locktype to optimistic
use customer
store automem
@1,1 get m.name
@2,1 get m.address
@3,1 get m.state
read
if not change()
    replace customer.name with m.name,;
    customer.address with m.address,;
    customer.state with m.state
endif

https://www.lianja.com/doc/index.php/STORE_AUTOMEM


Copy the contents of fields to an array or to a series of memory variables
SCATTER
use addresses index add_1
seek "Seymour House"
if found()
    scatter field like add* to aTemp
endif

https://www.lianja.com/doc/index.php/SCATTER


Determines whether dynamically created variables are created as LOCAL
SET_LOCAL
function calledfunc
	if isset(cVar1)  // returns .F.
		? cVar1
	endif
	if isset(cVar2)  // returns .T.
		? cVar2
	endif
endfunc
 
set local on  // default
cVar1 = "I'm local"
private cVar2
cVar2 = "I'm private"
calledfunc()

https://www.lianja.com/doc/index.php/SET_LOCAL


Determines whether variables must be pre-declared
SET_STRICT

 

set strict off
m_var = date()
 
set strict on
private m_var
m_var = date()

https://www.lianja.com/doc/index.php/SET_STRICT


Variables

Variables in Lianja do not need to be explicitly declared, although they should be for better code readability and maintainability. When an expression is assigned to a variable, if the variable does not already exist then it will be created implicitly unless SET STRICT ON is in effect.

private x
x = 10    // x already exists
y = 10    // y does not yet exist so it is created
 
set strict on
z = 10   // error is thrown as z does not exist and STRICT is ON

Simple Variables

Variable names must begin with a letter (A-Z, a-z) or an underscore (-), followed by any combination of letters, digits or underscores. The variable name can be of any length, but only the first 32 characters are significant, so these must be unique. Lianja ignores the case of letters, so m_var, M_VAR, and m_VaR would all be treated as the same memory variable name. The name given to a variable has no bearing on the type of data that is, or can be, stored in it. In fact, the type of data stored in a particular variable can be changed at any time unless SET STRICT is ON, in which case Lianja will type check variables on assigment to them.

m_var = 1234
m_var = 'a character value'
? m_var + 100

Variables can be declared and optionally initialized before used.

private m_var = 1234
m_var = 'a character value'
? m_var + 100

Variables can optionally be declared as specific datatype.

private m_var as numeric = 1234
m_var = 'a character value'    // throws an error

Keywords

There are no reserved words in Lianja. Command names can be used as variables names. At first glance this seems strange, but provides for greater flexibility when declaring and referencing memory variables and database field variables, as you do not need to concern yourself about names that may already be used as commands.

As an extreme example, the following code will compile and run. It will output “hello”

procedure if(if)
return if
 
if = "hello"
if if = "hello"
    echo if( if )
endif

Statements

The statement is the basic unit of programming in any programming language. Statements in Lianja are delimited by a newline.

echo "Hello world"

You can extend statements over multiple lines by placing a ‘;’ at the end of the line:

echo "Hello ;
world" + ;
" this is a multi-line statement"

Assigment Statements

The assignment statement stores the result of the expression expression into a variable.

variable = expression

If the variable does not exist and STRICT is OFF, then it is created. If the variable already exists, its contents are updated. If the variable does not exist (has not been declared) and STRICT is ON, then an error is thrown. When STRICT is ON, you should pre-declare variables before assigning values to them using the private, public or local commands.

private myvar
 
set strict on
// no error as myvar has already been declared
myvar = "hello world"
 
set strict off
// error as newvar has not been declared
newvar = 10

You can declare and initialize variables in one statement

private myvar = "hello world today is " + cdow( date() )

https://www.lianja.com/doc/index.php/A_Recital_Primer


Advertisements

Numeric – trigonometry [examples]

Calculate and return the angle size in radians for any given cosine value
ACOS
set decimal to 4
?acos(0.7071)
    0.7854
set decimals to 2
?rtod(acos(cos(dtor(30))))
     30.00

https://www.lianja.com/doc/index.php/ACOS()


Return the angle size of any given sine value
ASIN
set decimals to 4
?asin(0.7071)
    0.7854
set decimal to 2
?rtod(asin(sin(dtor(30))))
     30.00

https://www.lianja.com/doc/index.php/ASIN()


Return the angle size of a given tangent value
ATAN
set decimals to 4
?atan(.7071)
    0.6155

https://www.lianja.com/doc/index.php/ATAN()


Return the angle size for the specified cosine and sine values of a given point
ATN2
set decimals to 4
?atn2(0.5000,0.8660)
    0.5236

https://www.lianja.com/doc/index.php/ATN2()


Return cosine value
COS
set decimals to 6
? cos(dtor(30))
  0.866025

https://www.lianja.com/doc/index.php/COS()


Convert degrees to radians
DTOR
? dtor(90)
       1.57

https://www.lianja.com/doc/index.php/DTOR()


Return the value of pi
PI
? pi()
 3.1415926

https://www.lianja.com/doc/index.php/PI()


Convert radians to degrees
RTOD
? rtod(3.14159)
    180.00

https://www.lianja.com/doc/index.php/RTOD()


Return the sine of a value
SIN
set decimals to 6
? sin(dtor(45))
  0.707107

https://www.lianja.com/doc/index.php/SIN()


Returns the tangent of the angle
TAN

 

set decimals to 6
? tan(dtor(44))
  0.965689

https://www.lianja.com/doc/index.php/TAN()


Numeric – logarithms [examples]

Return exponential value
EXP
set decimals to 3
? exp(1.000)
     2.718
eval = exp(1.000)
? eval
     2.718
? type("eval")
N

https://www.lianja.com/doc/index.php/EXP()


Return natural logarithm for a specified numeric expression
LOG
set decimals to 5
? log(2.71828)
   1.00000
? type("log(2.71828)")
N

https://www.lianja.com/doc/index.php/LOG()


Return base 10 logarithm for the specified numeric expression
LOG10

 

? log10(300)
      2.48

https://www.lianja.com/doc/index.php/LOG10()


Numeric – financial [examples]

Calculate the payment on a loan
PAYMENT
? payment(100,10,1)
    110.00

https://www.lianja.com/doc/index.php/PAYMENT()


Calculate the payment on a loan
PMT
? pmt(100,10,1)
    110.00

https://www.lianja.com/doc/index.php/PMT()


Calculate the present value of equal regular payments on a loan
PV
? pv(1000,.10,10)
   6144.57

https://www.lianja.com/doc/index.php/PV()


Return future value of a periodic investment
FV
? fv(1000,.10,20)
  57275.00

https://www.lianja.com/doc/index.php/FV()


Calculate compound annual growth rate
CAGR
? cagr(5000,10000,5)
      0.15

https://www.lianja.com/doc/index.php/CAGR()


Prefix numeric value with currency character
CURRENCY
set currency to "$"
? currency(88.00)
    $88.00
? currency(123.4567)
   $123.46
? currency(123.4567,4)
 $123.4567

https://www.lianja.com/doc/index.php/CURRENCY()


Define the currency symbol associated with the CURRENCY() function
SET_CURENCY

 

set currency to ’£’
? currency(5000.00)
 £5,000.00

https://www.lianja.com/doc/index.php/SET_CURRENCY


Numeric – binary [examples]

Convert a binary encoded string to a numeric
BIN2I
? bin2i(i2bin(987))
       987

https://www.lianja.com/doc/index.php/BIN2I()


Convert a binary encoded string to a numeric
BIN2L
? bin2l(l2bin(98765))
     98765

https://www.lianja.com/doc/index.php/BIN2L()


Convert a binary encoded string to a numeric
BIN2W
nVar = bin2w(binVar)

https://www.lianja.com/doc/index.php/BIN2W()


Convert numeric to binary encoded character string
I2BIN
? bin2i(i2bin(987))
       987

https://www.lianja.com/doc/index.php/I2BIN()


Convert numeric to binary encoded string
L2BIN
? bin2l(l2bin(98765))
     98765

https://www.lianja.com/doc/index.php/L2BIN()


Perform bitwise AND operation
BITAND
x = 3   && 0011
y = 6   && 0110
z = 7	&& 0111
? bitand(x,y)
         2     && 0010
? bitand(x,y,z)
         2     && 0010

https://www.lianja.com/doc/index.php/BITAND()


Clear a specified bit in a numeric value
BITCLEAR
x = 6			&& 0110
y = 1
? bitclear(x,y)
         4		&& 0100

https://www.lianja.com/doc/index.php/BITCLEAR()


Shift the bits in a numeric value a specified number of places to the left
BITLSHIFT
x = 6			&& 0110
y = 1
? bitlshift(x,y)
        12		&& 1100

https://www.lianja.com/doc/index.php/BITLSHIFT()


Perform bitwise NOT operation
BITNOT
x = 3			&& 00011
? bitnot(x)
        -4		&& 11100

https://www.lianja.com/doc/index.php/BITNOT()


Perform bitwise OR operation
BITOR
x = 3  && 0011
y = 6  && 0110
z = 7  && 0111
? bitor(x,y)
         7  && 0111
? bitor(x,y,z)
         7  && 0111

https://www.lianja.com/doc/index.php/BITOR()


Shift the bits in a numeric value a specified number of places to the right
BITRSHIFT
x = 6       && 0110
y = 1
? bitrshift(x,y)
         3   && 0011

https://www.lianja.com/doc/index.php/BITRSHIFT()


Set a specified bit in a numeric value
BITSET
x = 6			&& 0110
y = 3
? bitset(x,y)
        14		&& 1110

https://www.lianja.com/doc/index.php/BITSET()


Test the value of a specified bit in a numeric value
BITTEST
x = 6			&& 0110
y = 3
z = 2
? bittest (x,y)
.F.
? bittest (x,z)
.T.

https://www.lianja.com/doc/index.php/BITTEST()


Perform bitwise XOR (exclusive OR) operation
BITXOR

 

x = 3			&& 0011
y = 6			&& 0110
z = 7			&& 0111
? bitxor(x,y)
         5		&& 0101
? bitxor(x,y,z)
         2		&& 0010

https://www.lianja.com/doc/index.php/BITXOR()


Numeric [examples]

Specify the number of decimal places to be used when displaying the results of numeric expressions
SET_DECIMALS
? 285.129 * 4.6
 1311.5934
set decimals to 3
set fixed on
? 285.129 * 4.6
  1311.593

https://www.lianja.com/doc/index.php/SET_DECIMALS


Determines whether a fixed number of decimal places are displayed for numeric output
SET_FIXED
? 285.129 * 4.6
 1311.5934
set decimals to 3
set fixed on
? 285.129 * 4.6
  1311.593

https://www.lianja.com/doc/index.php/SET_FIXED


Change the character used as a decimal point
SET_POINT
set separator to "."
set point to ","
display all ord_value, customer

https://www.lianja.com/doc/index.php/SET_POINT


Change the character used to mark thousands
SET_SEPARATOR
set point to ","
set separator to "."
@1,1 say ord_value picture "999.999.999.99"
1.234.567,89

https://www.lianja.com/doc/index.php/SET_SEPARATOR


Calculate percentage
PERCENT
? percent(10,100)
     10.00

https://www.lianja.com/doc/index.php/PERCENT()


Return rounded numeric
ROUND
? round(3.467)
      3.00
? round(3.467,1)
      3.50
? round(3.467,2)
      3.47

https://www.lianja.com/doc/index.php/ROUND()


Return the smallest integer that is greater than or equal to a given value
CEILING
? ceiling(354.89)
       355
? ceiling(354.19)
       355
? ceiling(-354.89)
      -354

https://www.lianja.com/doc/index.php/CEILING()


Determine the sign of a numeric value
SIGN
? sign(9876.78)
         1
? sign(-87.9)
        -1
? sign(0)
         0

https://www.lianja.com/doc/index.php/SIGN()


Return absolute value
ABS
? abs(-1)
         1
? abs(-5.6)
       5.6
? abs(2.5)
       2.5

https://www.lianja.com/doc/index.php/ABS()


Return the largest integer that is less than or equal to a given number
FLOOR
? floor(354.89)
       354
? floor(354.19)
       354
? floor(-354.89)
      -355

https://www.lianja.com/doc/index.php/FLOOR()


Return integer
INT
? int(2.56)
         2
? int(-2.56)
        -2

https://www.lianja.com/doc/index.php/INT()


Return a numeric value
FIXED
? fixed(2.5)
       2.5

https://www.lianja.com/doc/index.php/FIXED()


Return a numeric value
FLOAT
? float(2.5)
       2.5

https://www.lianja.com/doc/index.php/FLOAT()


Length of a numeric value
LENNUM
? lennum(123456789.123)
        13
? lennum(879)
        10

https://www.lianja.com/doc/index.php/LENNUM()


Return square root
SQRT
? sqrt(9.00)
      3.00

https://www.lianja.com/doc/index.php/SQRT()


Determine whether a specified expression is between two other specified expressions
BETWEEN
? between(date(),date()-10,date()+10)
.T.
? between("A", "A", "Z")
.T.
? between(10,1,9)
.F.

https://www.lianja.com/doc/index.php/BETWEEN()


Return maximum value
MAX
? max(1, 3)
         3
set date british
? max(ctod("15/10/1997"), ctod("14/10/1997"))
15/10/1997

https://www.lianja.com/doc/index.php/MAX()


Return the minimum value
MIN
? min(1, 3)
         1
? min(ctod("01/02/1997"), date())
01/02/1997

https://www.lianja.com/doc/index.php/MIN()


Return division remainder
MOD
? mod(7,3)
       1.00

https://www.lianja.com/doc/index.php/MOD()


Check whether an expression is numeric
IS_FLOAT
? is_float(1)
.T.
? is_float(1.23)
.T.
? is_float(-1)
.T.
? is_float(2.2 ** 3)
.T.

https://www.lianja.com/doc/index.php/IS_FLOAT()


Check whether an expression is numeric
IS_NUMERIC
? is_numeric(1)
.T.
? numeric(1.23)
.T.
? is_numeric(-1)
.T.
? is_numeric(2.2 ** 3)
.T.

https://www.lianja.com/doc/index.php/IS_NUMERIC()


Check whether an expression is numeric
IS_INT
? is_int(1)
.T.
? is_int(1.23)
.T.
? is_int(-1)
.T.
? is_int(2.2 ** 3)
.T.

https://www.lianja.com/doc/index.php/IS_INT()


Determine whether a specified expression is between two other specified expressions
INRANGE
? inrange(date(),date()-10,date()+10)
.T.
? inrange("A", "A", "Z")
.T.
? inrange(10,1,9)
.F.

https://www.lianja.com/doc/index.php/INRANGE()


Return a random number
RAND
? rand(-1)
      0.70
? rand()
      0.61

https://www.lianja.com/doc/index.php/RAND()


Other more specific topics:

Numeric – binary

Numeric – financial

Numeric – logarithms

Numeric – logical

Numeric – trigonometry