Prev: www.prevayler.org anyone do an in ram data base with transactionlog in tcl?
Next: accessing GUI with TWAPI (was: Accessing GUI of CAD through Tcl/Tk)
From: tom.rmadilo on 16 Dec 2009 23:09 On Dec 16, 2:04 pm, Rodericus <sc...(a)web.de> wrote: > Having a goto command, you could also have the possibility of writing > like FORTRAN and the combinations, a total of 31 possibilities. Yes, one would "think" that Tcl does not have a goto. A few months back I ran a few experiments: translate C code into a Tclish equivalent. The experiment consisted of finding fast algorithms for solving sudoku and translating them directly into Tcl code. I didn't even try to "understand" the algorithm. This meant that I had to follow the naming conventions and the algorithms steps as closely as possible. On example used a single C function with goto:. You can compare the results: http://www.junom.com/gitweb/gitweb.perl?p=sd.git;a=tree;f=test basic-exact-cover.tcl is the Tcl version of ec.c. If you read my notes in the tcl file, you will find that I originally thought that the code didn't work all the time. But when I compiled the original c code, it gave exactly the same answers, even when it appeared to not find a solution. I later discovered that the original algorithm searched for every possible solution and I was printing out the final state of the algorithm, not the found solutions. Turned out to be a pretty good check on the goals of the experiment. The basic idea is to use a while loop and a switch statement. The switch arms are the goto points, and [continue] is the [goto]. The code could have been made to look even more like the C code by defining a proc [goto point], which set the switch variable and did a [return -code continue]. I also use something like a [goto], I call it a pipeline, used to jump to the end of a code block: while {1} { (conditional statements which might break) ... break } Turns out this pipeline idea is just a special case of the new goto example. Tcl lends itself to this type of experimentation. Nobody set out to create a [goto] in Tcl. You also might notice that I simulate a two dimensional array to hold the sudoku puzzle, using the same basic syntax as in the original C code.
From: Rodericus on 17 Dec 2009 07:06 On 17 Dez., 05:09, "tom.rmadilo" <tom.rmad...(a)gmail.com> wrote: > Tcl lends itself to this type of experimentation. Nobody set out to > create a [goto] in Tcl. You also might notice that I simulate a two > dimensional array to hold the sudoku puzzle, using the same basic > syntax as in the original C code. Thanks! Now I know how to program with goto in Tcl. :) By the way, the proof that everything you can program with "goto" can also be programmed without it, is like that, with an exterior "while". It is a complicated way of circumscribing something very simple: set the program counter to something different instead of increasing it by one. I think no one wanted the goto because of style: structured programming was the spirit of that time, as today is object orientation. Rodrigo.
From: Rodericus on 17 Dec 2009 07:14 Georgios Petasis ÎγÏαÏε: > I didn't understand the relation with perl. Perl also has OO. > And the difference in sizes of the involved dlls is about 60K. > Do you compare with perl because perl is a "slim" language, or you are > considering perl also as fat? Perl does not claim to be minimalistic. We are equating the language with that, what the interpreter does, so that the language is growing like perl as the interpreter gets new cool features that people want. There is no definition, no concept of the languge, perhaps only the syntax is the whole concept. Rodrigo.
From: tom.rmadilo on 17 Dec 2009 11:00 On Dec 17, 4:06 am, Rodericus <sc...(a)web.de> wrote: > On 17 Dez., 05:09, "tom.rmadilo" <tom.rmad...(a)gmail.com> wrote: > > > Tcl lends itself to this type of experimentation. Nobody set out to > > create a [goto] in Tcl. You also might notice that I simulate a two > > dimensional array to hold the sudoku puzzle, using the same basic > > syntax as in the original C code. > > Thanks! Now I know how to program with goto in Tcl. :) > > By the way, the proof that everything you can program with "goto" can > also be programmed without it, is like that, with an exterior "while". > It is a complicated way of circumscribing something very simple: set > the program counter to something different instead of increasing it by > one. I think no one wanted the goto because of style: structured > programming was the spirit of that time, as today is object > orientation. Something you can do with this "Tclish" goto that you can't with a regular goto: you can replace the code following the label, that is you can substitute in a new set of switch case bodies. (Actually you can do this in C by using a function pointer in place of a function name, but then you have left the original execution environment.) But it should be pointed out that this particular form of goto isn't in any way unstructured, the original code in C and my use are designed as an efficient loop contained within a single procedure (so many function calls and variable passing are avoided). In Tcl this is probably more of a help than in C in terms of speed. Not every use of goto will fall into this category, so don't expect this example to settle any arguments against using goto. Something else we have in Tcl that is similar to a goto (execution within a fixed environment) is [namespace eval], or also using [namespace code]. I once called these named stacks, but was corrected. A namespace is like a named stack level. At any time, you can "goto" that label and execute arbitrary code, not fixed code. But the fact that code can shift under your feet in Tcl means that you can't implement a [goto] which is implemented anything like your program counter.
From: J R Houck on 17 Dec 2009 12:08
Shin wrote: <snip> > IMO Tcl is more like a meta-language for creating problem oriented scripting languages > and so doesn't pull every new concept into a syntactically predictable > form. It's pure freedom ;) Well said... :) |