Tool Command Language, aka Tool Command Language, is an actively used programming language created in 1988. Tcl (pronounced "tickle" or tee cee ell, ) is a high-level, general-purpose, interpreted, dynamic programming language. It was designed with the goal of being very simple but powerful. Tcl casts everything into the mold of a command, even programming constructs like variable assignment and procedure definition. Read more on Wikipedia...

31Years Old 600Users 2Jobs

Example code from the Hello World Collection:

#!/usr/local/bin/tclsh
# Hello World in Tcl

puts "Hello World!"

Example code from Linguist:

# XDG Base Directory Specification handling
#
# Copyright (C) 2013 Lawrence Woodman
#
# Licensed under an MIT licence.  Please see LICENCE.md for details.
#
# For XDG Base Directory Specification
#   http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
#
package require Tcl 8.5

namespace eval XDG {
  variable DEFAULTS ""
  namespace export DATA_HOME CONFIG_HOME CACHE_HOME
  namespace export RUNTIME_DIR DATA_DIRS CONFIG_DIRS
}

proc XDG::SetDefaults {} {
  variable DEFAULTS
  if {$DEFAULTS ne ""} return
  set DEFAULTS [list \
    DATA_HOME   [file join $::env(HOME) .local share] \
    CONFIG_HOME [file join $::env(HOME) .config] \
    CACHE_HOME  [file join $::env(HOME) .cache] \
    DATA_DIRS   [list [file join /usr local share] [file join /usr share]] \
    CONFIG_DIRS [list [file join /etc xdg ]]
  ]
}

proc XDG::XDGVarSet {var} {
  expr {[info exists ::env(XDG_$var)] && $::env(XDG_$var) ne ""}
}

proc XDG::Dir {var {subdir ""} } {
  variable DEFAULTS
  SetDefaults
  set dir [dict get $DEFAULTS $var]

  if {[XDGVarSet $var]} {
    set dir $::env(XDG_$var)
  }

  return [file join $dir $subdir]
}

proc XDG::Dirs {var {subdir ""} } {
  variable DEFAULTS
  SetDefaults
  set rawDirs [dict get $DEFAULTS $var]

  if {[XDGVarSet $var]} {
    set rawDirs [split $::env(XDG_$var) ":"]
  }

  set outDirs {}
  foreach dir $rawDirs {
    lappend outDirs [file join $dir $subdir]
  }
  return $outDirs
}

# The remaining procs reference the environmental variables XDG_
# followed by the proc name.
proc XDG::DATA_HOME {{subdir ""}} {Dir DATA_HOME $subdir}
proc XDG::CONFIG_HOME {{subdir ""}} {Dir CONFIG_HOME $subdir}
proc XDG::CACHE_HOME {{subdir ""}} {Dir CACHE_HOME $subdir}

proc XDG::RUNTIME_DIR {{subdir ""}} {
  if {![XDGVarSet RUNTIME_DIR]} { return {} }
  return [file join $::env(XDG_RUNTIME_DIR) $subdir]
}

# The following procs returning the directories as a list with the most
# important first.
proc XDG::DATA_DIRS {{subdir ""}} {Dirs DATA_DIRS $subdir}
proc XDG::CONFIG_DIRS {{subdir ""}} {Dirs CONFIG_DIRS $subdir}

Example code from Wikipedia:

oo::class create fruit {
    method eat {} {
        puts "yummy!"
    }
}
oo::class create banana {
    superclass fruit
    constructor {} {
        my variable peeled
        set peeled 0
    }
    method peel {} {
        my variable peeled
        set peeled 1
        puts "skin now off"
    }
    method edible? {} {
        my variable peeled
        return $peeled
    }
    method eat {} {
        if {![my edible?]} {
            my peel
        }
        next
    }
}
set b [banana new]
$b eat               → prints "skin now off" and "yummy!"
fruit destroy
$b eat               → error "unknown command"

Trending Repos

repo stars description

Last updated October 14th, 2019