[index] [home]

Tweet

Tcl, Perl, Ruby, ...

Welcome back to the 90s!

Recently I'm playing a bit with Tcl, and for now I find it a very pretty and honest language.

If it still looks nice after the novelty wears off, I might use it for general purpose 'small scale' script language, e.g. for text-processing. For bigger or more serious things, perhaps Ruby is better suited - we will see.

Compared to Perl - which is what I used earlier, brute power of Tcl is less, that is, Tcl is less concise as Perl (few things are!), but I notice that Tcl is more fun to read and write.

Furthermore, Tcl can be embedded into a C-application pretty easily, using e.g. Jim Tcl (repo or GitHub mirror), which makes interfacing from C (C calls Tcl) as well as to C (Tcl calls C) pretty easy.

What's life like for a Tcl parser?

The actual Tcl syntax is very small (or even smaller, and smaller still), but I think fundamentally necessary to understand completely in order to be able to write programs.

To get to know it, I 'play parser' for e.g. the following snippet, trying to predict what the result would be - it works quite well.

    #!/usr/bin/env tclsh



    proc p exp {
        puts ---[ uplevel expr $exp ]---
    }



    set a 10

    puts ---[ expr       $a       ]---   ;# ---10---
    puts ---[ expr     { $a }     ]---   ;# ---10---
    puts ---[ expr   { { $a } }   ]---   ;# --- $a ---
    puts ---[ expr { { { $a } } } ]---   ;# --- { $a } ---

    p       $a                           ;# ---10---
    p     { $a }                         ;# ---10---
    p   { { $a } }                       ;# ---10---
    p { { { $a } } }                     ;# --- $a ---



    set b 20

    puts ---[ expr       $a + $b       ]---   ;# ---30---
    puts ---[ expr     { $a + $b }     ]---   ;# ---30---
    puts ---[ expr   { { $a + $b } }   ]---   ;# --- $a + $b ---
    puts ---[ expr { { { $a + $b } } } ]---   ;# --- { $a + $b } ---

    #p      $a + $b                            (error: #arg mismatch)
    p     { $a + $b }                         ;# ---30---
    p   { { $a + $b } }                       ;# ---30---
    p { { { $a + $b } } }                     ;# --- $a + $b ---



    set c "foo bar baz"

    #puts  ---[ expr       $c       ]---      (error: bareword 'foo')
    puts   ---[ expr     { $c }     ]---   ;# ---foo bar baz---
    puts   ---[ expr   { { $c } }   ]---   ;# --- $c ---
    puts   ---[ expr { { { $c } } } ]---   ;# --- { $c } ---

    #p      $c                                (error: bareword 'foo')
    #p    { $c }                              (error: bareword 'foo')
    p   { { $c } }                         ;# ---foo bar baz---
    p { { { $c } } }                       ;# --- $c ---


Delivered to you by Vim, GNU Make, MultiMarkdown, bozohttpd, NetBSD, and 1 human.