tyllang
New Coder
Tyl Programming Language 2.2 released!
Tyl (pronounced TEEL) is a general-purpose programming language that is intended for intermediate and experienced programmers, as well as, for totally beginners.
Some of Tyl features:
• Clean code
• Symbolized keywords
• Modularity
• Dynamic program structure
• One line statements
• System modules & functions
• Multiple variables declaration
• Automatic type inference
• Internal framework
Tyl Software includes the following modules:
• Tyl Scanner
• Tyl Parser
• Tyl Statement Generator
• Tyl Runtime
• Tyl Launcher
• Tyl Runner
• Web Files Generator & Automation
Here is an example of a database project. It is composed of three programs in Tyl:
program: geodb.create.tyl
____________________________________________________________________________________________________
! =========== GEODB SETUP (MS SQL) ===========
!
! To setup geodb database, first run geodb.create.tyl,
! then run geodb.build.tyl
! To check if geodb database and tables were created
! successfully, run geodb.show.tyl
! set dropdb variable to determine whether to delete and
! create geodb database.
! if false and geodb database exists, only countries and
! mountains tables will be dropped
dropdb \t
dbexistcmd 'select count(*) from sys.databases where name=`geodb`'
tablesexistcmd 'SELECT count(*) FROM geodb.INFORMATION_SCHEMA.TABLES '
tablesexistcmd ++ 'WHERE TABLE_TYPE = `BASE TABLE` '
tablesexistcmd ++ 'AND (TABLE_NAME = `countries` OR TABLE_NAME = `mountains`)'
! perform 'clean' connection, in order to handle databases
mssqldb 'data source=(LocalDb)\MSSQLLocalDB;integrated security=true;connection timeout=60;'
mssqldb.connect
! if geodb database does not exist, force db drop
result mssqldb.value dbexistcmd
not result ? dropdb \t
dropdb ?
print 'dropping database `geodb`...'
mssqldb.execute 'DROP DATABASE geodb'
~
pause 1
result mssqldb.value dbexistcmd
not result ? %
^
print 'dropped ok.' + newline
print 'creating database `geodb`...'
mssqldb.execute 'CREATE DATABASE geodb;'
~
pause 1
result mssqldb.value dbexistcmd
result ? %
^
print 'created ok.' + newline
^
mssqldb.sqlerror ? print mssqldb.sqlerror
! connect to geodb database
mssqldb 'data source=(LocalDb)\MSSQLLocalDB;initial catalog=geodb;integrated security=true;connection timeout=60;'
mssqldb.connect
not dropdb ?
print 'dropping tables: `mountains`, `countries`...'
mssqldb.execute 'DROP TABLE mountains; DROP TABLE countries;'
~
pause 1
num mssqldb.value tablesexistcmd
not num ? %
^
print 'dropped ok.' + newline
^
mssqldb.sqlerror ? print mssqldb.sqlerror
! ATTENTION: MS SQL accepts only apostrophe symbols ('), as
! quotation marks. Do replace all apostrophe
! symbols with backtick symbols (`).
cmd ''
cmd ++ 'CREATE TABLE [dbo].[countries] ('
cmd ++ ' [id] INT IDENTITY (1, 1) NOT NULL,'
cmd ++ ' [name] NVARCHAR (20) DEFAULT (``) NOT NULL,'
cmd ++ ' PRIMARY KEY CLUSTERED ([id] ASC)'
cmd ++ ');'
cmd ++ 'CREATE TABLE [dbo].[mountains] ('
cmd ++ ' [id] INT IDENTITY (1, 1) NOT NULL,'
cmd ++ ' [name] NVARCHAR (20) DEFAULT (``) NOT NULL,'
cmd ++ ' [country] INT NOT NULL,'
cmd ++ ' [height] INT NOT NULL,'
cmd ++ ' PRIMARY KEY CLUSTERED ([id] ASC),'
cmd ++ ' CONSTRAINT [FK_mountains_countries] FOREIGN KEY ([country]) REFERENCES [dbo].[countries] ([id])'
cmd ++ ');'
mssqldb.execute cmd
pause 1
num mssqldb.value tablesexistcmd
num 2 ?
print 'tables created successfully.'
\
print 'tables creation failed!' + newline
print mssqldb.sqlerror
^
program: geodb.build.tyl
____________________________________________________________________________________________________
countries 'Chile' 'Japan' 'Russia' 'Tanzania' 'Tibet'
mountains 'Villarrica' 'Fuji' 'Elbrus' 'Kilimanjaro' 'Chomolungma' 'Kita' 'Llullaillaco'
mcinds 0 1 2 3 4 1 0
heights 2860 3776 5642 5895 8848 3193 6739
countrieslen len countries
mountainslen len mountains
rowsinserted 0
mssqldb 'data source=(LocalDb)\MSSQLLocalDB;initial catalog=geodb;integrated security=true;connection timeout=60;'
mssqldb.connect
! ATTENTION: MsSql accepts only apostrophe symbols ('), as
! quotation marks. Do replace all apostrophe
! symbols with backtick symbols (`).
! clear DB tables
mssqldb.execute 'delete from mountains; delete from countries;'
pause 0.2
! ensure tables are clear
countriesnum mssqldb.value 'select count(*) from countries'
mountainsnum mssqldb.value 'select count(*) from mountains'
num countriesnum + mountainsnum
num 0 ?
print 'countries and mountains tables cleared successfully.'
\
print mssqldb.sqlerror
pause 3
exit
^
! build countries table
rowsinserted 0
countries c ~
cmd 'insert countries (name) values (`' + c + '`)'
mssqldb.execute cmd ? rowsinserted ++ \ %
^
! if not all rows inserted, print the last SQL error
rowsinserted < countrieslen ? print mssqldb.sqlerror
print rowsinserted + ' rows inserted to countries database'
! exit if no row inserted
rowsinserted 0 ?
pause 3
exit
^
! build mountains table
cids mssqldb.list 'select id from countries'
rowsnum mountainslen
rowsinserted 0
i rowsnum ~
mcind mcinds i
cid cids mcind
cmd 'insert mountains (name, country, height) values ('
cmd ++ '`' + mountains i
cmd ++ '`, ' + cid
cmd ++ ', ' + heights i
cmd ++ ')'
mssqldb.execute cmd ? rowsinserted ++ \ %
^
! if not all rows inserted, print the last SQL error
rowsinserted < rowsnum ? print mssqldb.sqlerror
print rowsinserted + ' rows inserted to mountains mssqldb'
program: geodb.show.tyl
____________________________________________________________________________________________________
mssqldb 'data source=(LocalDb)\MSSQLLocalDB;initial catalog=geodb;integrated security=true;connection timeout=60;'
mssqldb.connect
! declare records that will be used for
! countries and mountains rows that are
! fetched from geodb database
! country record items will be accessed indirectly
c { }
! mountain record is declared with all expected keys,
! and items can be accessed directly (dot-notation).
! cname key is declared for use in method 3
m { id 0, name '', height 0, country 0, cname '' }
print 'countries' + newline + '--------------------'
countries mssqldb.all 'select * from countries'
cmax len countries
ci cmax ~
c countries ci
text c 'id'
text ++ ': ' + c 'name'
print text
ᐤ
≡ method 1 demonstrates how to search data in referenced table
≡ using the countries list.
≡ for direct approach use method 3
print
print 'mountains (method 1)' + newline + '--------------------'
mountains mssqldb.all 'select * from mountains'
mmax len mountains
mi mmax ~
m mountains mi
text m.id
text ++ ': ' + m.name
text ++ ' (' + m.height
text ++ '), '
≡ search country name by id
mcid m.country
cname ''
ci cmax ~
c countries ci
cid c 'id'
cid mcid ? ✖ cname c 'name'
ᐤ
print text + cname
ᐤ
≡ method 2 demonstrates how to search data in referenced table
≡ using countries record that is built from countries list.
print
print 'mountains (method 2)' + newline + '--------------------'
countriesrecord { }
ci cmax ~
c countries ci
k c 'id'
v c 'name'
countriesrecord <- k v
ᐤ
mountains mssqldb.all 'select * from mountains'
mi mmax ~
m mountains mi
≡ get country name from countries record by
≡ mountain country id
cid m.country
cname countriesrecord cid
text m.id
text ++ ': ' + m.name
text ++ ' (' + m.height
text ++ 'm), ' + cname
print text
ᐤ
≡ method 3 uses SQL statement that gets the referenced data
≡ by joining the two tables
print
print 'mountains (method 3)' + newline + '--------------------'
cmd ''
cmd ++ 'select m.id, m.name, m.height, c.name cname '
cmd ++ 'from mountains m join countries c '
cmd ++ 'on m.country=c.id '
cmd ++ 'order by m.id'
mountains mssqldb.all cmd
mi mmax ~
m mountains mi
text m.id
text ++ ': ' + m.name
text ++ ' (' + m.height
text ++ '), ' + m.cname
print text
ᐤ
More details about the programming language at tyl-lang [DOT] dev
I'll appreciate too any critical advice and also technical proposals regarding the language usability.
Tyl (pronounced TEEL) is a general-purpose programming language that is intended for intermediate and experienced programmers, as well as, for totally beginners.
Some of Tyl features:
• Clean code
• Symbolized keywords
• Modularity
• Dynamic program structure
• One line statements
• System modules & functions
• Multiple variables declaration
• Automatic type inference
• Internal framework
Tyl Software includes the following modules:
• Tyl Scanner
• Tyl Parser
• Tyl Statement Generator
• Tyl Runtime
• Tyl Launcher
• Tyl Runner
• Web Files Generator & Automation
Here is an example of a database project. It is composed of three programs in Tyl:
program: geodb.create.tyl
____________________________________________________________________________________________________
! =========== GEODB SETUP (MS SQL) ===========
!
! To setup geodb database, first run geodb.create.tyl,
! then run geodb.build.tyl
! To check if geodb database and tables were created
! successfully, run geodb.show.tyl
! set dropdb variable to determine whether to delete and
! create geodb database.
! if false and geodb database exists, only countries and
! mountains tables will be dropped
dropdb \t
dbexistcmd 'select count(*) from sys.databases where name=`geodb`'
tablesexistcmd 'SELECT count(*) FROM geodb.INFORMATION_SCHEMA.TABLES '
tablesexistcmd ++ 'WHERE TABLE_TYPE = `BASE TABLE` '
tablesexistcmd ++ 'AND (TABLE_NAME = `countries` OR TABLE_NAME = `mountains`)'
! perform 'clean' connection, in order to handle databases
mssqldb 'data source=(LocalDb)\MSSQLLocalDB;integrated security=true;connection timeout=60;'
mssqldb.connect
! if geodb database does not exist, force db drop
result mssqldb.value dbexistcmd
not result ? dropdb \t
dropdb ?
print 'dropping database `geodb`...'
mssqldb.execute 'DROP DATABASE geodb'
~
pause 1
result mssqldb.value dbexistcmd
not result ? %
^
print 'dropped ok.' + newline
print 'creating database `geodb`...'
mssqldb.execute 'CREATE DATABASE geodb;'
~
pause 1
result mssqldb.value dbexistcmd
result ? %
^
print 'created ok.' + newline
^
mssqldb.sqlerror ? print mssqldb.sqlerror
! connect to geodb database
mssqldb 'data source=(LocalDb)\MSSQLLocalDB;initial catalog=geodb;integrated security=true;connection timeout=60;'
mssqldb.connect
not dropdb ?
print 'dropping tables: `mountains`, `countries`...'
mssqldb.execute 'DROP TABLE mountains; DROP TABLE countries;'
~
pause 1
num mssqldb.value tablesexistcmd
not num ? %
^
print 'dropped ok.' + newline
^
mssqldb.sqlerror ? print mssqldb.sqlerror
! ATTENTION: MS SQL accepts only apostrophe symbols ('), as
! quotation marks. Do replace all apostrophe
! symbols with backtick symbols (`).
cmd ''
cmd ++ 'CREATE TABLE [dbo].[countries] ('
cmd ++ ' [id] INT IDENTITY (1, 1) NOT NULL,'
cmd ++ ' [name] NVARCHAR (20) DEFAULT (``) NOT NULL,'
cmd ++ ' PRIMARY KEY CLUSTERED ([id] ASC)'
cmd ++ ');'
cmd ++ 'CREATE TABLE [dbo].[mountains] ('
cmd ++ ' [id] INT IDENTITY (1, 1) NOT NULL,'
cmd ++ ' [name] NVARCHAR (20) DEFAULT (``) NOT NULL,'
cmd ++ ' [country] INT NOT NULL,'
cmd ++ ' [height] INT NOT NULL,'
cmd ++ ' PRIMARY KEY CLUSTERED ([id] ASC),'
cmd ++ ' CONSTRAINT [FK_mountains_countries] FOREIGN KEY ([country]) REFERENCES [dbo].[countries] ([id])'
cmd ++ ');'
mssqldb.execute cmd
pause 1
num mssqldb.value tablesexistcmd
num 2 ?
print 'tables created successfully.'
\
print 'tables creation failed!' + newline
print mssqldb.sqlerror
^
program: geodb.build.tyl
____________________________________________________________________________________________________
countries 'Chile' 'Japan' 'Russia' 'Tanzania' 'Tibet'
mountains 'Villarrica' 'Fuji' 'Elbrus' 'Kilimanjaro' 'Chomolungma' 'Kita' 'Llullaillaco'
mcinds 0 1 2 3 4 1 0
heights 2860 3776 5642 5895 8848 3193 6739
countrieslen len countries
mountainslen len mountains
rowsinserted 0
mssqldb 'data source=(LocalDb)\MSSQLLocalDB;initial catalog=geodb;integrated security=true;connection timeout=60;'
mssqldb.connect
! ATTENTION: MsSql accepts only apostrophe symbols ('), as
! quotation marks. Do replace all apostrophe
! symbols with backtick symbols (`).
! clear DB tables
mssqldb.execute 'delete from mountains; delete from countries;'
pause 0.2
! ensure tables are clear
countriesnum mssqldb.value 'select count(*) from countries'
mountainsnum mssqldb.value 'select count(*) from mountains'
num countriesnum + mountainsnum
num 0 ?
print 'countries and mountains tables cleared successfully.'
\
print mssqldb.sqlerror
pause 3
exit
^
! build countries table
rowsinserted 0
countries c ~
cmd 'insert countries (name) values (`' + c + '`)'
mssqldb.execute cmd ? rowsinserted ++ \ %
^
! if not all rows inserted, print the last SQL error
rowsinserted < countrieslen ? print mssqldb.sqlerror
print rowsinserted + ' rows inserted to countries database'
! exit if no row inserted
rowsinserted 0 ?
pause 3
exit
^
! build mountains table
cids mssqldb.list 'select id from countries'
rowsnum mountainslen
rowsinserted 0
i rowsnum ~
mcind mcinds i
cid cids mcind
cmd 'insert mountains (name, country, height) values ('
cmd ++ '`' + mountains i
cmd ++ '`, ' + cid
cmd ++ ', ' + heights i
cmd ++ ')'
mssqldb.execute cmd ? rowsinserted ++ \ %
^
! if not all rows inserted, print the last SQL error
rowsinserted < rowsnum ? print mssqldb.sqlerror
print rowsinserted + ' rows inserted to mountains mssqldb'
program: geodb.show.tyl
____________________________________________________________________________________________________
mssqldb 'data source=(LocalDb)\MSSQLLocalDB;initial catalog=geodb;integrated security=true;connection timeout=60;'
mssqldb.connect
! declare records that will be used for
! countries and mountains rows that are
! fetched from geodb database
! country record items will be accessed indirectly
c { }
! mountain record is declared with all expected keys,
! and items can be accessed directly (dot-notation).
! cname key is declared for use in method 3
m { id 0, name '', height 0, country 0, cname '' }
print 'countries' + newline + '--------------------'
countries mssqldb.all 'select * from countries'
cmax len countries
ci cmax ~
c countries ci
text c 'id'
text ++ ': ' + c 'name'
print text
ᐤ
≡ method 1 demonstrates how to search data in referenced table
≡ using the countries list.
≡ for direct approach use method 3
print 'mountains (method 1)' + newline + '--------------------'
mountains mssqldb.all 'select * from mountains'
mmax len mountains
mi mmax ~
m mountains mi
text m.id
text ++ ': ' + m.name
text ++ ' (' + m.height
text ++ '), '
≡ search country name by id
mcid m.country
cname ''
ci cmax ~
c countries ci
cid c 'id'
cid mcid ? ✖ cname c 'name'
ᐤ
print text + cname
ᐤ
≡ method 2 demonstrates how to search data in referenced table
≡ using countries record that is built from countries list.
print 'mountains (method 2)' + newline + '--------------------'
countriesrecord { }
ci cmax ~
c countries ci
k c 'id'
v c 'name'
countriesrecord <- k v
ᐤ
mountains mssqldb.all 'select * from mountains'
mi mmax ~
m mountains mi
≡ get country name from countries record by
≡ mountain country id
cid m.country
cname countriesrecord cid
text m.id
text ++ ': ' + m.name
text ++ ' (' + m.height
text ++ 'm), ' + cname
print text
ᐤ
≡ method 3 uses SQL statement that gets the referenced data
≡ by joining the two tables
print 'mountains (method 3)' + newline + '--------------------'
cmd ''
cmd ++ 'select m.id, m.name, m.height, c.name cname '
cmd ++ 'from mountains m join countries c '
cmd ++ 'on m.country=c.id '
cmd ++ 'order by m.id'
mountains mssqldb.all cmd
mi mmax ~
m mountains mi
text m.id
text ++ ': ' + m.name
text ++ ' (' + m.height
text ++ '), ' + m.cname
print text
ᐤ
More details about the programming language at tyl-lang [DOT] dev
I'll appreciate too any critical advice and also technical proposals regarding the language usability.