© Tyl Software Foundation 2019-2021
▶ TYL STATEMENT COMPOSITION
Terminology
one line
a section of (or all) line of code
statement
one line code that constructs a programming functionality
In this chapter we'll refer to statements that are one line and
non compound. For compound
statements see Compound Statements
Structure page.
Tyl statement structure:variable, function or scalar value
the rest of the statement after removing
Let's start with a basic variable assignment:
Tyl statement structure:
[ENTITY] [REST]
ENTITY
REST
ENTITY
REST
is interpreted by ENTITY
:
Entity
Rest
a statement that will be the source of a variable assignment
list operations components
record operations components
function parameters components
dynamic system module parameters components
Let's start with a basic variable assignment:
num 11
num
is the entity, and rest is 11.
So the code will read:
num gets the value 11
Using len
system function,
we can calculate the length of the string 'Kilimanjaro':
len 'Kilimanjaro'
Again,
So the code will read:
The above statement will do nothing with the result 11.
So let's assign that result to
len
is the entity, and rest is 'Kilimanjaro'
.
So the code will read:
len calculates the length of the value 'Kilimanjaro', and returns the result
The above statement will do nothing with the result 11.
So let's assign that result to
num
variable:
num len 'Kilimanjaro'
num
is the entity, and rest is len 'Kilimanjaro'.
So the code will read:
num gets the result of len 'Kilimanjaro'
To print num
:
num len 'Kilimanjaro'
print num
11
print
function can print strings, numbers, and even the result of other
statements.
To print the result of a statement:
print len 'Kilimanjaro'
11
Now,
So the code will read:
print
is the entity, and rest is again len 'Kilimanjaro'
.
So the code will read:
print the result of len 'Kilimanjaro'
Or, assuming we know the meaning of len
:
print the length of 'Kilimanjaro'
And why not combine the assignment and the printing:
print num len 'Kilimanjaro'
11
First, the length of string 'Kilimanjaro', will be assigned to
Is there a limit to these one line statements?
Well, as long as the line can be interpreted correctly, it's all fine. But, there are some cases where it is not that simple.
Consider this
num
, and
than will be printed.
Is there a limit to these one line statements?
Well, as long as the line can be interpreted correctly, it's all fine. But, there are some cases where it is not that simple.
Consider this
pkv
function:
pkv key value: print key + ': ' + value
We want to print '
Kilimanjaro: 11
':
pkv 'Kilimanjaro' 11
pkv
is the entity, and rest is 'Kilimanjaro' 11
,
which are the two parameters of pkv
function
Or using
len
system funcion:
pkv 'Kilimanjaro' len 'Kilimanjaro'
pkv
function has two parameters, and the parameters code is 'Kilimanjaro' len 'Kilimanjaro'
The first parameter gets the string 'Kilimanjaro', the second gets the rest of the parameters code
len 'Kilimanjaro'
.
In Tyl, if a parameter is the sole or last parameter of a function, it gets all the last section of a statement as its contained statement. So the second parameter will be the result of
len 'Kilimanjaro'
.
But, what if we switch
pkv
parameters?
pkv value key: print key + ': ' + value
Using
len
system funcion as before:
pkv len 'Kilimanjaro' 'Kilimanjaro'
The system will take
In this case, enclose the first parameter code in parentheses:
len
system funcion without parameters, as pkv
first parameter, which does not meet our intentions.
In this case, enclose the first parameter code in parentheses:
pkv ( len 'Kilimanjaro' ) 'Kilimanjaro'
Thus causing the system to take all the enclosed code
len 'Kilimanjaro'
, as pkv
first parameter.