Showing posts with label TCL. Show all posts
Showing posts with label TCL. Show all posts

Wednesday, September 28, 2011

Compile a TCL script into an EXE program

It can be done!

Solution:
How to compile a TCL script into an EXE program

Sunday, April 10, 2011

Project Euler - Problem 2 - Tcl

#Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
#1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
#By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
proc problem2 {} {
 set term  2
 set term-1  1
 set sum  0

 while {$term <= 4000000} {
  if {($term % 2) == 0} {
   incr sum $term
  }

  set tmp  ${term-1}
  set term-1  $term
  set term  [expr $term + $tmp]
 }
 
 return $sum
}
# solution-2: 4613732

Project Euler - Problem 1 - Tcl

# If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
# Find the sum of all the multiples of 3 or 5 below 1000.
proc Problem1 {} {

 set items {}

 for {set idx 3} {$idx<1000} {incr idx 3} {
  lappend items $idx
 }

 for {set idx 5} {$idx<1000} {incr idx 5} {
  if { [lsearch $items $idx] < 0 } {
   lappend items $idx
  }
 }

 set rval 0
 foreach item $items {
  set rval [expr $rval + $item]
 }
  
 return $rval
}
# solution: 233168

Thursday, April 7, 2011

GUIDE: TDD unit testing tools for Tcl

As promised in http://shloemi.blogspot.com/2011/03/tdd-tools-for-tcl.html here is my experience with tcltest package and eclipse.


The story
Suppose we have a function called 'bits_serialize'.

This function should serialize a given data into bits_per_io bits per package (for examples see the tests below and what they return).

This function have the following signature:  bits_serialize {bits_per_io description}, where:
  • bits_per_io
    • How much bits each package have.
  • description
    • a pair of {data bits}, where:
      • data 
        • the data we want to serialize.
      • bits
        • the size, in bits, we want to serialize this data.
let's test this function using tcltest...

Test code
# Generated using http://pygments.org/
source unit-under-test.tcl ;# contains the definition of bits_serealize 

test base--always-ok {This is as simple as it gets.} -constraints {
} -setup {
} -body {
 return TRUE
} -cleanup {
} -result TRUE

test bits_serealize--partial-quanta {description here...} -constraints {
} -setup {
} -body {
 return [bits_serealize 32 " 0x01 16 "]
} -cleanup {
} -result [list 1]

test bits_serealize--full-quanta {description here...} -constraints {
} -setup {
} -body {
 return [bits_serealize 32 " 0xFFFFFFFF 32 "]
} -cleanup {
} -result [list [ format "%u" 0xFFFFFFFF ]]

test bits_serealize--over-quanta {description here...} -constraints {
} -setup {
} -body {
 return [bits_serealize 32 " 0x060504030201 64 "]
} -cleanup {
} -result [list [ format "%u" 0x04030201 ] [ format "%u" 0x0605 ]]

test bits_serealize--way-over-quanta {description here...} -constraints {
} -setup {
} -body {
 return [bits_serealize 32 " 0x060504030201 320 "]
} -cleanup {
} -result [list [ format "%u" 0x04030201 ] [ format "%u" 0x0605 ] 0 0 0 0 0 0 0 0]

test bits_serealize--cross-quanta {description here...} -constraints {
} -setup {
} -body {
 return [bits_serealize 32 "
  0xFF 1
  0xFF 2
  0xFF 3
  0xFF 4
  0xFF 6

  0x04030201 32
 "]
} -cleanup {
} -result [list [ format "%u" 0x201FFFF ] [ format "%u" 0x403 ]]

test bits_serealize--quanta-and-half {description here...} -constraints {
} -setup {
} -body {
 return [bits_serealize 32 "
  0xFFEEDDCCBBAA 48
 "]
} -cleanup {
} -result [list [ format "%u" 0xDDCCBBAA ] [ format "%u" 0xFFEE ]]


eclipse-unit-testing

Results

++++ base--always-ok PASSED
++++ bits_serealize--partial-quanta PASSED
++++ bits_serealize--full-quanta PASSED
++++ bits_serealize--over-quanta PASSED
++++ bits_serealize--way-over-quanta PASSED
++++ bits_serealize--cross-quanta PASSED
++++ bits_serealize--quanta-and-half PASSED

My impression 

I definitely recommend using this unit!! and to my surprise eclipse supports it built in (see picture ==>).

Wednesday, March 30, 2011

Tcl nob, newbie beginners tutorials list.

Just found these good looking tutorials for beginners and thought it will help someone...


I'll update when I find more...

Tcl, Read dynamic variables

I've just solved another Tcl mystery I had from day one in Tcl (around 2 months :)
It was not critical until today!

Example
set qwe.qaz.1 Hello
set qwe.qaz.2 From
set qwe.qaz.3 ShloEmi

set wanted_qaz 3
upvar 0 "qwe.qaz.${wanted_qaz}" wanted_qaz_val
set this_will_be_ShloEmi $wanted_qaz_val

Hope this helps...

Tuesday, March 29, 2011

GUIDE: tclunit/TDD for Tcl, usage and examples.

As promised (tdd-tools-for-tcl.html) here is my humble experience/research with tclunit.

Guides / tutorials found



Research results

Usage example

Have fun...

Friday, March 25, 2011

TDD unit testing tools for Tcl

After committing my first 'big' feature to my current employee, I got a feeling that something was left behind in the heat of the rush. That think was, of course, the new code test coverage.

That lead me to try and find tools / guidance for Tcl TDD.

Here are the things I've found for Tcl:

  1. A very good TDD tutorials found
    1. http://www.agiledata.org/essays/tdd.html
    2. http://geosoft.no/development/unittesting.html
  2. TDD tools for Tcl
    1. Wiki comparison of available tools for Tcl -  http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks#Tcl
    2. tclunit - http://www.tcl.tk/man/tcl8.4/TclCmd/tcltest.htm
      1. Download here - http://sourceforge.net/projects/tclunit/

Thats all, not much. I intend to check tclunit, experience with it and report back later on... see Y'a.

Saturday, March 19, 2011

Tcl documentation

After 2-3 days of research, analyzing the available options and trying to work with some doc tools - here is my conclusion for Tcl documentation:

ROBODoc
Homepagehttp://www.xs4all.nl/~rfsber/Robo/
Wiki          - http://en.wikipedia.org/wiki/ROBODoc


Impressions
  • VERY easy
  • Clean documentation
  • Various output types (PDF, HTML, CHM, ...)
  • Supports many languages (If you manually configure it I believe it can support any language). 

I've also tried Doxygen
Prons
  • After spending 1/2 a day i gave up configuring it with Tcl.
  • The documentation in the code should have special chars 
    • Ugly inline documentation
    • When pressing F2 (function quick help) this ugly characters make the documentation more ugly.
  • At this stage I gave up.

Major resource pages 

Monday, March 14, 2011

Guide: Tcl documentation / manuals for Eclipse

This is very helpful and reduces the time it takes to open IE + open the Tcl help web page + typing the wanted Tcl command +++...

Here are the steps
  1. download the appropriate Tcl manuals from here
  2. unzip the html files to an appropriate location.
    • for our example: 'C:\Tcl\doc\html'
  3. open eclipse, Menu->window->preferances->Click
  4. Tcl->Man Pages->Configure->Add->Click
  5. Alternatively, in the filter type: 'man' t\and select Tcl/Man pages.
  6. Name: Tcl/Mans
  7. Add->Click
  8. Folder: 'C:\Tcl\doc\html'
  9. Ok, Ok, Ok


Test it
press F2 on the 'proc', 'set' or 'lappend' keywords to start using the help...

Enjoy...

Sources
1. Tcl manuals
2. The guide I used to connect eclipse and the Tcl manuals

Saturday, February 26, 2011

Tcl Python converter / interpreter

After searching the guts of the internet - I found that there is not a single working example that can convert Tcl to Python.

This is a major drawback to the industry!!
If one exists (please let me know ASAP) the industry can switch to Python, this move will give it the ability to develop more rapidly and neglect the faults of this very old and nothing oriented language.
The industry will then be able to progress much faster.

Big greedy thoughts came to my mind - 'I can be rich if I could just create such a thing', but it's really a big problem, to my opinion, and I believe that if one could be created it should be distributed almost freely to take the industry to the next level.

I'll attempt to attack this problem on my own (you are welcome to join forces).
Please, let me know if there is any solution to this problem.

I've some ideas on 'how to attack this problem', here they are:
1. Using TCP/IP pipe - HLD schema
2. Create a python script to convert Tcl script to Python (sounds like a hugh work hours).
3. Create a Tcl script to convert Tcl to Python (sound worst than #2)

Tuesday, February 22, 2011

Tcl, FIFO based on a list.

FIFO based on a list... code

Debugging Tcl, advanced way.. (part 1)

DEBUG helpers - code.

Hi,
Here is a nice helper code to make your debug life much much easier.

If you encountered in a bug and the debugger is so slow you wana die, you probabelly puts some messages in the function entry and when the function returns (with it's value).

In the attached code you'll find a very nice surprise.

Sunday, February 20, 2011

Guide: Setting up Eclipse with DLTK and ActiveState to debug TCL.

Let's start working...

Download and install Eclipse SDK
1. Download Eclipse (I used 'Eclipse IDE for Java Developers').
2. Unzip (or install, depends on the download type) to your favorite location.

Download and install DLTK
3. Run Eclipse.exe from that location.
4. Menu->Help->Install new software...
5. Right of 'Work with:' click the 'Add' button.
6. In the name enter 'DLTK'
7. location = 'http://download.eclipse.org/technology/dltk/updates/'
8. Click OK and wait a few seconds for the Eclipse environment to fetch the versions.
9. Select the appropriate version (for 'Helios Eclipse SDK' (version 3.6.1) I used DLTK 2.0v). Note: You can select the minimum for TCL (listed below), I selected all the DLTK.
10. Next.. Next ... Accept the license agreement, Wait for the download to finish.

here is a minimum list i found to install TCL DLTK:
>>> Dynamic Language Toolkit – Core Frameworks
>>> Dynamic Language Toolkit – Core Frameworks SDK
>>> Dynamic Language Toolkit – iTCL Development Tools
>>> Dynamic Language Toolkit – iTCL Development Tools SDK
>>> Dynamic Language Toolkit – TCL Development Tools
>>> Dynamic Language Toolkit – TCL Development Tools SDK
>>> Dynamic Language Toolkit – XOTcl Development Tools
>>> Dynamic Language Toolkit – XOTcl Development Tools SDK

Setting up Eclipse Tcl interpreter
11. Download and install TCL Shell and interpreter.
12. Using Eclipse IDE: Menu->Window->Preferences->TCL->Interpreters
13. click 'Add'
1. Name='TCL'
2. Browse... path to the Tcl interpreter executable (I've installed it at '')

Setting up Eclipse Tcl debugger
14. Install 'Komodo remote debugger'
15. Using Eclipse IDE: Menu->->Window->Preferences->TCL->Debug->Engines->Active State
16. Under 'Paths' tab->'External debugger engine'->Path->...->Select the debugger path and file ('dbgp_tcldebug.exe' for windows).


Now you are all set. You should be able to choose new TCL project, write your Tcl code and debug your programs.

Other posts used to create this instalation guide:
* http://blogsai.wordpress.com/2009/10/15/configuring-eclipse-as-tcltk-ide/
*

Have fun...

Monday, February 7, 2011

TCL debug tools.

I've run a search on Google 'how to debug TCL' and found these good articles:

1. What debugging tools are available to a Tcl programmer
* Use puts 'debug $message here'.
* Other strange looking ways to solve the TCL debug problem.
2. Buy 'Tcl Solutions' by 'ActiveState'
3. Try 'Dynamic Languages Toolkit' by Eclipse

As a start-up freelancer solution provider I should provide with as low cost solutions as i can, so... let's start testing these solutions.

'puts' in your code


Already using this solution - very chip, no money spend, but if you consider the work-hours spent: it's not chip at all!!

Eclipse support for dynamic language


I've started with #3: Eclipse support for dynamic language, like TCL and Python.
Very soon found this great looking presentation - Dynamic Languages Toolkit (DLTK) , Looks promising...

After a little struggle I've managed to bring up a working station with Eclipse and DLTK.

In the next post I'll describe how to setup Eclipse with DLTK and a debugger.

TCL first impression.


I've just started to do some freelance work.
First job is to do performance improvement to a legacy scripting program written in TCL. Never touched TCL.


TCL Compared to Python


There are lot's of rules in TCL to load to the mind, lot's and lot's and... Python is very simple.

OK, so... let's debug it. 'NO DEBUG for you', I'm still working on a debug platform, so far debug looks like this:
1. Write the code.
2. Run the application.
3. Wait for the right moment, be patient, wait, not yet... now
5. Missed it? go-to (2) OMG - time spender.
6. See what's happened.
7. Close the application
8. Write some debug messages ( AKA: trace print outs ).
9. Go-to (2) until you finally found the right code to make it work.
10. Refactor, code review... the rest...

I've debugged Python using Iron-Python and Eclipse, it was reasonable for the pilot I did to Python.


Conclusion so far


TCL was probably good in it's glorious days, I can see it in my mind - compared to VB script i've worked with those days, but those days are long gone, for both of them.

TCL - Frustrating, BIG time consumer in maintenance AND in development phases, no suitable DEBUG platform (so far).

WIKI - http://en.wikipedia.org/wiki/Tcl


If you can port to Python, do so, ASAP. I'm calculating the time I’m going to spend on this tool compared to building a new one in Python. It might take a month or so, but the total maintenance of the TCL might take longer.

If your stuck with TCL, like I probably am, well... read the flowing posts to see how to handle the TCL maintenance problem.