File: example1.tcl

package info (click to toggle)
tcl-sugar 0.1-1.1
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 176 kB
  • sloc: tcl: 647; sh: 13; makefile: 2
file content (32 lines) | stat: -rw-r--r-- 548 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Sugar example 1 - simple "command macros".

package require sugar

sugar::macro first {cmd list} {
    list lindex $list 0
}

sugar::macro second {cmd list} {
    list lindex $list 1
}

sugar::macro last {cmd list} {
    list lindex $list 1
}

sugar::macro rest {cmd list} {
    list lrange $list 1 end
}

sugar::proc testit {} {
    set list [list 1 2 3]
    puts [first $list]
    puts [second $list]
    puts [rest $list]
    puts [first [rest $list]]
}

puts "The body of 'testit' procedure is:"
puts [info body testit]
puts "Output:"
testit