© Tyl Software Foundation 2019-2021
▶ STRINGS
String is a collection of characters.
Consider this program:
name 'Eitan'
print name
Eitan
Tyl identifies a value as string, only if it is enclosed in single quotation
marks (').
First, we assign the string value 'Eitan', to the
First, we assign the string value 'Eitan', to the
name
string variable. As
mentioned earlier, name
variable gets its type upon assignment.
We can print a string directly:
print 'Eitan'
Eitan
If we want to print
So we use the backward quotation mark (`):
name: 'Eitan'
, we can't write
''Eitan'', because the internal quotations will not be interpreted
as quotation marks for printing.
So we use the backward quotation mark (`):
print 'name: `Eitan`'
name: 'Eitan'
The backward quotation mark (`) inside a quoted string, will cause the
system to print a single quotation mark.
Strings can be added by the '+' operator:
Strings can be added by the '+' operator:
fullname 'Eitan' + ' ' + 'Livne'
print fullname
Eitan Livne
Other options of adding variables and string literals:
name 'Eitan'
familyname 'Livne'
fullname1 name + ' ' + 'Livne'
fullname2 name + ' ' + familyname
print fullname1
print fullname2
print name + ' ' + familyname
Eitan Livne
Eitan Livne
Eitan Livne
Eitan Livne
Eitan Livne
Assigning a variable to a new variable:
mycity 'Pucon'
yourcity mycity
print mycity + ', ' + yourcity
print 'Now you are leaving my city...'
yourcity 'Chillan'
print mycity + ', ' + yourcity
Pucon, Pucon
Now you are leaving my city...
Pucon, Chillan
Now you are leaving my city...
Pucon, Chillan
In line '
yourcity mycity
', yourcity
variable gets the value of mycity
variable, so their value is the same. Then, yourcity
variable is assigned
another value. Each time, the values of mycity
and yourcity
are printed.
String concatenation using the '+' operator:
onehun 100
plussym ' + '
print 100 + ' + ' + 200 + ' = ' + 300
print onehun + plussym + 200 + ' = ' + sum 100 200
print '100 + 200 = ' + sum 100 200
sum x y: x + y
100 + 200 = 300
100 + 200 = 300
100 + 200 = 300
100 + 200 = 300
100 + 200 = 300
In the second concatenation statement, we see that the last member of a
concatenation sequence can be a
statement in itself.