© Tyl Software Foundation 2019-2021
▶ WORKING WITH MODULES
Scoping in Modules Tree
In this chapter the main running program will be referred to as the
program and subsequent modules will be referred to as modules.
With this definition, every Tyl application is composed of program
and modules. running the application means running the
program, that will run all subsequent modules according to
their appearance order in the code.
With this in mind let's start with an
app
program and app.data
and
app.func
modules:

First,
app.data
is run and pi
is assigned value 3.1416, then app.func
is run and area
function is declared. Though pi
is not in app.func
tree,
it will be seen by area
function, because pi
is a global variable
of app.data
and essentially of app
iteself. In this case app.data
acts
as application repository and holds all application data that is used by the
program and all modules. so in line print 'pi is ' + pi
, pi
will have already its value, and it will be printed.
Flipping modules call order, and updating
app.func
:

Line
print '[app.func] pi is ' + pi
, will be the first statement that will be
run, so pi
will be declared with a value of NULL. The next statement that will
be run is pi 3.1416
which will be merely a variable assignment. In order to
avoid such errors it is needed to call the modules in an order that for each
running statement, its variables are defined properly on the spot or are
already defined.
Variables that are not global behave the same as described in variables scope page, regrading to their containing module.
Module Location Search & Relative Paths
All the above program and modules where on the same directory
'app', therefore the plain call #mod app.data
, casused the system to
look for file 'app.data.tyl' in the same directory that the calling module
'app.tyl' resides. plain call means that the relative path of
the module in the calling statement is not relative, but merely a file
name, with or without the file extention.
Examples of module relative paths:
! examples of module calls, and the way their relative
! paths are written. in all calls except the first call
! the extention '.tyl' is omitted
! if the relative path has spaces, it must be enclose
! in quotation marks (')
! 'app.tyl' in full path (without spaces, with file extention)
#mod C:/tylprojects/app/app.tyl
! 'app.tyl' in full path (with spaces, without file extention)
#mod 'C:/tylprojects/happy app/app'
! 'app.tyl' in adjacent directory 'app2'
#mod ../app2/app
! 'app.tyl' in other relative directory (with spaces)
#mod '../../web apps/app'
! 'textmod.tyl' in the current working directory or in
! global modules repository
#mod textmod
! 'happy mod.tyl' in the current working directory or in
! global modules repository (with spaces)
#mod 'happy mod'
This is a scenario of a plain call to a global module 'textmod.tyl':

In line
#mod textmod
, Tyl system will search for file 'textmod.tyl' in
directory 'app', if not found it will look for it in Tyl global modules
reository.