When naming variables or macros (that are to be used as functions), Tinyfugue only allows the use of AlphaNumeric characters and underscores. This patch enables the dot, ".", as a valid character in variable and function names. Even though Tinyfugue doesn't recognize scripts as classes, enabling "dot notation" allows for a style of coding that reflects an object oriented approach to script organization.
Instructions for compiling
- Download the Tinyfugue source (http://tinyfugue.sourceforge.net/#source)
- Download the dotnotation.patch file into the newly created tf-50b8/src directory. A directory listing of this directory should show multiple files ending in .h and .c
- Open a command prompt and "cd" into the tf-50b8/src directory.
- Run "patch < dotnotation.patch" without the quotes.
- Run "cd .." to go up to the parent folder
- Run "./configure" to run the configuration program
- Run "make" to compile the program
- Assuming you are an admin (either by group membership or through sudo), run "make install" to install the newly created "tf" executable
Instructions for testing
Once the executable has been compiled, the following script should test the "dot notation" functionality.
/def dotnotation.test=/return Testing dot notation: %*
/eval /echo -aCred - $[dotnotation.test("Hello World")]
If the patch is working, then this should print "Testing dot notation: Hello World" out to the screen in red. If the patch isn't working, then you'll get a message stating "% EVAL: expression syntax error: expected operator or ']', found '.'."
Caveats
With this patch, Tinyfugue doesn't see any difference between the dot and any other valid characters. This means that it is possible to use dots in such a way that they are valid in a Tinyfugue sript, but would be invalid in most object oriented languages.
These are all perfectly legal: like is perfectly legal. Other items that are perfectly legal are:
- /def ...=/return "All dots for a function name and would be called as ...()"
- /def a.b.=/return "function name ends in a dot and would be called as a.b.()"
- /def .a.b=/return "function name begins with a dot and would be called as .a.b()"
- /def a..b=/return "function name has two consecutive dots and would be called as a..b()"
- /set ..a.b=1
- /set ...=1
- /set ..=1
- /set a..=1
The addition of the dot as a valid charact for variables also makes the behavior of some current scripts change.
For example, "/set myname=David%;/eval /echo My name is %myname." would not work as expected and would instead print out "My name is".
From Tinyfugue's (new) view, the variable starts at % and continues until it hits an invalid character for a variable name. In this case, the dot is a valid character, so Tinyfugue sees the variable name as "myname.", looks it up, doesn't find it and puts a blank in its space. This is actually already covered by "/help substitution" with the text "The brackets are recommended for clarity, but may be omitted if there is no default and the text following it can not be misinterpreted as part of the selector.".
In this case, the dot could be misinterpreted as part of the variable name and thus brackets should be used. The fix for this is to use proper variable enclosures. A working copy of the above example would be "/eval /echo My name is %{myname}." This unambiguously tells Tinyfugue that the variable name is "myname" and not "myname.".
Comparison to currently available naming options
As this patch does not provide any enforcement of commonly used dot notation restrictions, the patch is only useful in helping make scripts more readable. It provides for a less ambiguous method of providing object oriented-like naming schemes in Tinyfugue.
The only non-AlphaNumeric character currently available is the underscore. The underscore can be used as a way to organize scripts, but its meaning can be ambiguous as the underscore is also commonly used to specify a space character. It is not always easy to tell whether an underscore's logical meaning is to specify a space in a proper name or if its meaning is to specify a member value or function.
By providing two special characters, the dot and the underscore, function and variable names can be formulated in such a way that the logical meaning of the name is clearer. For example, with /def a_b.c_d it is easy to that this function represents a logical member of the a_b object called c_d whereas with /def a_b_c_d that same logical meaning is not readily apparent.
dotnotation.patch (2.77 kb)