This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* json-encode.c -- | |
* | |
* Small module to get native json escape in tcl. | |
* | |
* Compile: | |
* mingw: gcc -O2 -DUSE_TCL_STUBS=1 -I$tcl/win -I$tcl/generic json-encode.c -shared -o json.dll libtclstub87.a | |
* *nix: gcc -O2 -DUSE_TCL_STUBS=1 -I$tcl/unix -I$tcl/generic json-encode.c -shared -o json.so libtclstub87.a | |
* | |
* Usage: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## ------------------------------------------------------------------------------- | |
## ::uuid -- Generate UUID | |
## | |
## Example illustrating how simple one can create C-binding within tcl using ffidl | |
## ------------------------------------------------------------------------------- | |
# ::uuid creator (with on demand binding): | |
proc ::uuid {args} { | |
# create _fdl_uuid binding to UuidCreate : | |
ffidl::callout ::_fdl_uuid {pointer-var} int [ffidl::symbol rpcrt4.dll UuidCreate] stdcall |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# IMPORTANT: | |
# note to get correct results you should warm up Tcl and Python, | |
# so better execute it 3 times before you take results for | |
# the comparison | |
## ============================================================ | |
## Tcl | |
## ============================================================ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ------------------------------------------------------------------------------- | |
# ldeclare -- multi-line list declaration with simple substitution (and comments) | |
# ------------------------------------------------------------------------------- | |
proc ldeclare l { | |
uplevel "list [string map [list \n "\\\n"] \ | |
[regsub -all -line {^\s*\#[^\n]*} $l {}] | |
]" | |
} | |
# ------------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if {[namespace which -command ::tcl::mathfunc::strincr] eq ""} { | |
proc ::tcl::mathfunc::strincr {v {increment}} { | |
string trimleft [binary format I* [expr {"0b[binary scan $v B* v; set v]" + $increment}]] \x00 | |
} | |
} | |
proc range args { | |
set op "<"; set step 1 | |
switch -exact -- [llength $args] \ | |
1 { lassign $args to; set from [expr {$to*0}] } \ | |
2 { lassign $args from to; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# collatz-conjecture-iter.py -- simplest Collatz conjecture iterator in python | |
# Author: Serg G. Brester aka sebres | |
import math | |
f = lambda x: 3*x+1 if x & 1 else x/2 | |
def fcci(x): | |
"""single collatz conjecture iteration starting by given x | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# task params for all threads | |
tsv::array set params {one 1 two 2} | |
# worker task: | |
set th_task { | |
if {[catch { | |
# do some work (here sum of params): | |
set res [expr {[tsv::get params one] + [tsv::get params two]}] | |
# provide result to master: | |
thread::send -async $master [list lappend th_res $res] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env tclsh | |
package require Thread | |
array set in {-max-threads 4 -single-set 0 -max-ips 255 -iterations 3 -debug 0} | |
array set in $::argv | |
set commoncode { | |
if {$in(-single-set)} { | |
proc thipset {n} {return "f2b-test"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if {[namespace which -command ::lpop] eq {}} { | |
proc ::lpop {listvar {index end} args} { | |
upvar $listvar l | |
if {![info exists l]} { | |
return -code error "can't read \"$listvar\": no such variable" | |
} | |
if {![llength $args]} { | |
if {$index eq "end"} { | |
if {![llength $l]} { | |
return -code error -errorcode {TCL VALUE INDEX OUTOFRANGE} "index \"$index\" out of range" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#************************************************************************** | |
# parse | |
# Internally used proc to parse PO files (Portable Object) (GNU gettext | |
# format). | |
# Parameters: | |
# f_ -- | |
#************************************************************************** | |
proc parse { f_ } { | |
## TODO [SB]: file should be read partially, possible with other RE (non greedy ".*?" - could be slow by big files) : | |
set text_ [read $f_] |
OlderNewer