TYL PROGRAMMING LANGUAGE
▶ WORKING WITH MODULES
Setting a Modules Tree
Modules can call other sub modules in their turn. For ex., these textmod and sqlmod modules:
!
!     textmod.tyl
!
!     textual functionalities
!
q '`'
commaspc ', '
dbconnmsg 'Connected to database successfully.'
inputclientmsg 'type client information (name family-name age phone):'
p v: v ? print v \ print
pl v:
p v
print
qt text: q + text + q
qtc text: q + text + q + commaspc
nqc text: text + commaspc
!
!     sqlmod.tyl
!
!     SQL related functionalities
!
crmconnstr 'data source=(LocalDb)\MSSQLLocalDB;initial catalog=crmdb;integrated security=true;connection timeout=60;'
connect:
mssqldb.connect
mssqldb.connected ? %% \t
print 'Connection failed!' + newline
print mssqldb.sqlerror
 \f
execute cmd successmsg:
mssqldb.execute cmd ?
  print successmsg
  \
  print mssqldb.sqlerror
^
And the modified versions of crm.dal and crm.app will be:
!
!     CRM.DAL MODULE
!
!     this module acts as the data access layer for
!     crmdb database
!
!==== module statements section =================
! libraries
#mod textmod
#mod sqlmod
! variables
mssqldb crmconnstr
clientinfo { name '' fname '' age 0 phone '' }
! init
isconnected connect
!==== module functions section =================
insertclientbystr infostr: insertclient getclientinfo infostr
insertclient info:
clientinfo info
cmd 'insert into client (name, fname, age, phone) values('
cmd ++ qtc clientinfo.name
cmd ++ qtc clientinfo.fname
cmd ++ nqc clientinfo.age
cmd ++ qt clientinfo.phone
cmd ++ ')'
msg 'Client '
msg ++ qt clientinfo.name + ' ' + clientinfo.fname
msg ++ ' was inserted successfully.'
execute cmd msg
getclientinfo str:
words string.words str
result { name '' fname '' age 0 phone '' }
ind -1
result k v ~ result k words ( ind ++ )
result
!
!     CRM.APP MODULE
!
!     this module acts as the application running
!     program for handling client resources management
!
#mod crm.dal
isconnected ?
    pl dbconnmsg
    p inputclientmsg
    input clientinfostr
    p
    insertclientbystr clientinfostr
^
So if we run crm.app, and input client information string: 'Tony Manzanillo 22 010-90000222', we'll see this screen:


All these modules construct a modules tree:


Each module that is upper in the tree, is either calling directly, or have access to other modules in its section of the tree.
PART 1
PART 3