

  <section markdown="1">
### What Is This?

**TempleScript** is a programming language for and with semantic networks. It is currently
developed to help with asset management, cloud storage and processing, and procurement in
commercial settings.
  </section>

  <section markdown="1">
    
### Hello World Example

*  expressions evaluate from left to right. always.
*  the pipe operator `|` passes a tuple of values (or even a block of tuples) to further processing downstream
*  `io:write2stderr` is the QName for a predefined function (a topic itself)
*  the incoming tuple is used as parameters for the function to evaluate
*  `<blank>#` introduces comments (until the end of line)

.

    ( "Hello World" ) |->> io:write2stderr   \# write a string to STDERR


  </section>

  <section markdown="1">
    
### Real World Example

* maintain a local CPAN mirror (Perl archive of distributions)
* `mc` is the prefix of an ontology holding minicpan functionality
* `fs` is the prefix of a file-system ontology (move, copy, etc.)
* `cpandb` is the prefix of an ontology for a SQL database backend for CPAN data (modules, distros, ..)
* `web:mirror` is a stream to mirror web contents locally
* junctions are (*very* generalized) for-loops to introduce variables
* string interpolation is using { ... } to embed dynamic content

.

    fork-mirroring isa ts:stream                      \# streams run concurrently within the process
    return
       <+ 10 mins +>                                  \# we wait for 10 mins to not overload the startup
       |-{                                            \# start junction (generalized transaction)
           (1, mc:mirror-cpan ~[templescript/map]~>,  \# find code of this function
               mc:mirror-cpan / log_info )            \# find logging color for this function
         |->> ts:fusion (ts:forks) => $bg             \# create background (forked) process
        ||><||                                        \# do do not wait for that below to terminate
           <<- never | @ $bg                          \# which it never will
       }-                                             \# effectively we started a background process

    mc:mirror-cpan isa ts:function                    \# code we mentioned above
    log_info : "{ color => 'red' }" ^^ lang:perl      \# will evaluate to a Perl HASH
    return {                                          \# function code is itself a topic map

       RECENT-mirror isa web:mirror                   \# shortcut for a stream to poll for changes
         = file:/tmp/cpan/RECENT                      \# this makes sure that there is a local copy
         ~ http://mirror.easyname.at/cpan/RECENT      \# remote copy on CPAN server, any will do
       holds
           at most every 600 secs                     \# frequency of polling, not faster than this

       mc:watch-to-mirror-packages isa ts:stream      \# another local stream
       return
             <+ file:/tmp/cpan/RECENT +>              \# whenever this file changes
           |->> mc:mirror-packages ( remote-cpan =,   \# run this function (it will copy new distros)
                                   "{ local-cpan = }minicpan/" )
           | ( "{ $0 } changes in minicpan" )
           |->> io:write2log                          \# report in the log

       mc:watch-minicpan isa ts:stream                \# and another stream
       return
             <+ file:/tmp/cpan/minicpan/ +>           \# if the contents of the distro directory changes
           | ( $1 )                                   \# we are only interested in the file name
           |-{ ( "dbi:SQLite:dbname=/tmp/cpandb.sql", 
                 "{ $0 }../cpandb.sql", 
                 "{ $0 }/modules/02packages.details.txt.gz" )
                          => $dbi, $final, $packages  \# compute these for the transaction below
           }-{
              ->> fs:file-remove ( "/tmp/cpandb.sql" )\# make sure any old tmp is removed
             | ( $dbi )       |->> cpandb:assert      \# create a new one from scratch

            \# stream the packages file after skipping first 9 lines, in batches of 10000 lines
             | ( $packages )  | ~~[text/plain;blocksize=10000;skip=9]~~>
             |->> cpandb:add-modules ( $dbi )         \# add a block of modules
           |_| count                                  \# here we wait until ALL blocks have been added

             | ( $dbi )       |->> cpandb:index-up    \# CREATE INDEX ... in the underlying SQL database
                              |->> cpandb:detach      \# commit and disconnect
             | ( "cpandb reindexed" )
             |->> io:write2log                        \# report in log
            \# overwrite current database with updated version
             |->> fs:file-atomic-move ( "/tmp/cpandb.sql", $final )
           }-| ( "cpandb run finished" ) 
             |->> io:write2log                        \# report in log
    }


  </section>

  <section markdown="1">
    
### Language Paradigms

* knowledge-based using semantic networks (Topic Maps)
* tuple sequence processing, functional, with possible side effects
* reactive processing, causality or data driven
* asynchronous processing, reacting to signals, clocks and other events
* virtualized storage techniques (memory, databases, file systems)
* virtualized processing techniques (processor cores, clusters, clouds)

.


  </section>

