Tintware Documentation : Tint Programming Language : Tint Tutorial : Source FilesSource FilesBeing able to evaluate a single line is nice, but to do anything interesting, there needs to be a way to define procedures. There is a compiler which converts one or more source files (containing definitions of strings, dictionaries, and procedures) into a binary file. For historical reasons, the binary file is called a Tint string library (tsl). The string library can then be loaded into Tint using tint.load or it can be added to an executable as a resource. A dictionary is defined using Def:Dict: and the name. For example, some of the dictionaries used by emacs are defined as follows. Def:Dict:emacs.util Def:Dict:emacs.user A string is defined using Def:String: and the name. This must be followed by [*] at the beginning of a line. Anything between the end of the Def: line and the [*] is a comment and is ignored. The value of the string is everything between the [*] and the following [*] including newlines. Def:String:a-string This is a comment, presumably about this string. [*]value of a string[*] A procedure is like a string, except that it allows named parameters as well. These follow the name of the procedure, with all of them enclosed by parameters and commas between the parameters. By convention, the names of parameters begin with %, but this is not a requirement. Def:Proc:swap(%a,%b) This procedure will swap its arguments. [*] %b%a [*] Here is a bigger example: a procedure which returns a list of numbers. Def:Proc:counter(%start,%end,%seperator) Return a list of numbers between %start and %end, seperated by %seperator. For example, #(counter,1,10,.) will return 1.2.3.4.5.6.7.8.9.10 [*] #(=,%start,%end,( <* Are we at the end yet? *> %end ),( <* Nope, recurse to the next one. *> %start%seperator #(counter,#(+,%start,1),%end,%seperator) )) [*] The newlines and tabs used to format the code are discarded when the procedure is evaluated. Also, anything between <* and *> is a comment and is discarded. Each procedure contains a dictionary, so other objects can be defined in the procedure just as if the procedure were a dictionary. For example, to define a counter which starts from one and goes up to some maximum, the following would work. Def:Proc:counter(%max) Return a list of numbers between one and %max, seperated by by periods. For example, #(counter,10) will return 1.2.3.4.5.6.7.8.9.10 [*] #(>,%max,1,( 1#(counter.do,2,%max) )) [*] Def:Proc:counter.do(%idx,%max) [*] #(>,%idx,%max,,( .%idx#(counter.do,#(+,%idx,1),%max) )) [*] To evaluate something immediately, use Def:Eval:. It is like procedure except the text between [*] and [*] is evaluated immediately and no name or parameters are necessary. For example, the following is the canonical Hello World program. Def:Eval: Canonical Hello World Program [*] #(#(tint.console).put,Hello World!) [*] Regular expressions can be defined using Def:RegEx: and the name. Regular expressions are defined like strings: [*] at the beginning of a line marks the start of the regular expression and includes everything up to the following [*]. The Carp regular expression syntax is used. Def:RegEx:digits-only The particular regular expression matches lines containing only digits. [*]^<digit>+$[*] |