|
|||
|
Hi all,
I just wanted to know the pros and cons of TCL. Just now I tried to return an array from proc it is not returning. Even I had a doubt, as we have array concept in TCL what is the need of keylist? and We can return a keyList fron proc but we cannot return array. So, I thought I better to know the pros and cons of TCL... Thanks in advance! -Anil A Kumar |
|
|
||||
|
||||
|
|
|
|||
|
On Sep 30, 10:58 am, Anil A Kumar <401a...@gmail.com> wrote:
> Hi all, > > I just wanted to know the pros and cons of TCL. Just now I tried to > return an array from proc it is not returning. Even I had a doubt, as > we have array concept in TCL what is the need of keylist? and We can > return a keyList fron proc but we cannot return array. So, I thought I > better to know the pros and cons of TCL... > > Thanks in advance! > > -Anil A Kumar Asking for pros and cons of Tcl is like asking which notes in a song are too loud or too soft. Without knowing what you consider "loud" or "soft" we can't give a good answer. And what is too loud for one type of song (lullaby, for example) might be too soft for another (heavy metal rock). Similarly with software, what you call a pro might be a con for someone else, and what is a pro for one type of application might be a con for another. What you need to know about Tcl is this: it is different. Don't expect it to work like other languages. This isn't a bad thing, it's what gives Tcl its strength. There are things you can do in Tcl that are virtually impossible in other languages. Of course, the opposite is true as well, there are things you can do in other languages that you can't easily do in Tcl. |
|
|||
|
On Sep 30, 5:58*pm, Anil A Kumar <401a...@gmail.com> wrote:
> Hi all, > > I just wanted to know the pros and cons of TCL. Just now I tried to > return an array from proc it is not returning. Even I had a doubt, as > we have array concept in TCL what is the need of keylist? and We can > return a keyList fron proc but we cannot return array. So, I thought I > better to know the pros and cons of TCL... > key value lists can have duplicate keys..., arrays cannot About pros and cons, it depends on what you want to do and with what you compare. Lets try a comparision of the mainstream Python 2.6 with the upcoming Tcl 8.6. Tcl's pro points there (compared to Python) - Nicer Unicode and encoding support - Better Threading support (especially for Embedding in multithreaded C/C++ code) - Nicer event based programming (unless you add the Twisted package to Python) - Better Metaprogramming abilities / write your own DSL stuff - Better Tk integration - Better x-platform abilities (e.g. symlinks/reparse points on all big platforms...) - Better single file deployment options - Safe Interpreters - Better packaging system (but you can argue here) Tcl's con points (compared to Python) - More verbose syntax - fewer 3rd party libraries available - No good UDP or IPv6 support on all platforms - Often slower - No access to much platform specific stuff in the core language ( which is a consquence of better x-platform abstraction, you cannot have both) - Not so many books I guess i forgot a lot of other pro/con things that might interest one or the other. Michael |
|
|||
|
On Sep 30, 9:16*pm, Bryan Oakley <oak...@bardo.clearlight.com> wrote:
> On Sep 30, 10:58 am, Anil A Kumar <401a...@gmail.com> wrote: > > > Hi all, > > > I just wanted to know the pros and cons of TCL. Just now I tried to > > return an array from proc it is not returning. Even I had a doubt, as > > we have array concept in TCL what is the need of keylist? and We can > > return a keyList fron proc but we cannot return array. So, I thought I > > better to know the pros and cons of TCL... > > > Thanks in advance! > > > -Anil A Kumar > > Asking for pros and cons of Tcl is like asking which notes in a song > are too loud or too soft. Without knowing what you consider "loud" or > "soft" we can't give a good answer. And what is too loud for one type > of song (lullaby, for example) might be too soft for another (heavy > metal rock). Similarly with software, what you call a pro might be a > con for someone else, and what is a pro for one type of application > might be a con for another. > > What you need to know about Tcl is this: it is different. Don't expect > it to work like other languages. This isn't a bad thing, it's what > gives Tcl its strength. There are things you can do in Tcl that are > virtually impossible in other languages. Of course, the opposite is > true as well, there are things you can do in other languages that you > can't easily do in Tcl. Sorry, I was supposed to ask limitations.... |
|
|||
|
On Sep 30, 9:28*pm, schlenk <schl...@uni-oldenburg.de> wrote:
> On Sep 30, 5:58*pm, Anil A Kumar <401a...@gmail.com> wrote:> Hi all, > > > I just wanted to know the pros and cons of TCL. Just now I tried to > > return an array from proc it is not returning. Even I had a doubt, as > > we have array concept in TCL what is the need of keylist? and We can > > return a keyList fron proc but we cannot return array. So, I thought I > > better to know the pros and cons of TCL... > > key value lists can have duplicate keys..., arrays cannot > > About pros and cons, it depends on what you want to do and with what > you compare. > > Lets try a comparision of the mainstream Python 2.6 with the upcoming > Tcl 8.6. > > Tcl's pro points there (compared to Python) > - Nicer Unicode and encoding support > - Better Threading support (especially for Embedding in multithreaded > C/C++ code) > - Nicer event based programming (unless you add the Twisted package to > Python) > - Better Metaprogramming abilities / write your own DSL stuff > - Better Tk integration > - Better x-platform abilities (e.g. symlinks/reparse points on all big > platforms...) > - Better single file deployment options > - Safe Interpreters > - Better packaging system (but you can argue here) > > Tcl's con points (compared to Python) > - More verbose syntax > - fewer 3rd party libraries available > - No good UDP or IPv6 support on all platforms > - Often slower > - No access to much platform specific stuff in the core language > ( which is a consquence of better x-platform abstraction, you cannot > have both) > - Not so many books > > I guess i forgot a lot of other pro/con things that might interest one > or the other. > > Michael Thanks, |
|
|||
|
On Sep 30, 9:16*am, Bryan Oakley <oak...@bardo.clearlight.com> wrote:
> What you need to know about Tcl is this: it is different. Don't expect > it to work like other languages. This isn't a bad thing, it's what > gives Tcl its strength. There are things you can do in Tcl that are > virtually impossible in other languages. Of course, the opposite is > true as well, there are things you can do in other languages that you > can't easily do in Tcl. This is something that I have generally agreed with over the years, but as time goes on, I have found fewer things which fall into the category of "things you can't easily do in Tcl". What we have, IMHO, is a lack of evangelism and experimentation in Tcl, and a general inferiority complex in certain areas: objects, design patterns, algorithm support, data structure support. I was forced to revise my own misconceptions when I translated two C programs into Tcl without understanding either the datamodel or the algorithm in either program. The first was a brute force sudoku solver. I used an identical algorithm and data structure. The second was an exact cover algorithm (dancing links) that used a single non- recursive compact algorithm with goto jumps. Again, without the slightest understanding of the algorithm, I had no problem with the translation. Code lines for each version were similar to the original. |
|
|||
|
Anil A Kumar wrote:
> Hi all, > > I just wanted to know the pros and cons of TCL. Just now I tried to > return an array from proc it is not returning. Even I had a doubt, as > we have array concept in TCL what is the need of keylist? and We can > return a keyList fron proc but we cannot return array. So, I thought I > better to know the pros and cons of TCL... > > Thanks in advance! > > -Anil A Kumar No one has yet answered your first question on arrays. Yes, you can return an array from a proc, just not by value. proc foo {varName} { upvar $varName local set value 0 foreach name {a b c d} {set local($name) [incr value]} } array set bar {} % foo bar % parray bar bar(a) = 1 bar(b) = 2 bar(c) = 3 bar(d) = 4 If you really want by value, flatten it to a list for the return call with 'return [array get <name>]' -- -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkrDnpkACgkQlZadkQh/RmFPPgCgofnaAICMt1RdHHm1CH3P0FCY ZsIAmwWfsDn/nF42oQNgpDobVJDydgeb =Lb+p -----END PGP SIGNATURE----- |
|
|||
|
On Sep 30, 11:58*am, Anil A Kumar <401a...@gmail.com> wrote:
> I just wanted to know the pros and cons of TCL. They are similar to the pros and cons of any other programming language. Cons: 1. you have to learn how to design and implement algorithms in general to be able to write useful complex programs (in any language) 2. you have to learn the language well not to get bit by language pecularities 3. you have to learn the language by writing code if you want to be comfortable writing programs that tend to work. 4. you have to learn where the resources are to look up "how to ..." and "why did ..." type questions Pros: 1. you can write all sorts of programs, of all sizes, in Tcl. 2. once you are comfortable reading and writing tcl, as well as how to design and implement an algorithm, you can expect to get the job done 3. you have access to real-time IRC chat areas, wikis, and web discussion groups where questions are typically answered without too much grief. |
|
|||
|
On Sep 30, 2:08*pm, David Gravereaux <davyg...@pobox.com> wrote:
> No one has yet answered your first question on arrays. *Yes, you can > return an array from a proc, just not by value. > > proc foo {varName} { > * *upvar $varName local > * *set value 0 > * *foreach name {a b c d} {set local($name) [incr value]}} > > array set bar {} > > % foo bar > % parray bar > bar(a) = 1 > bar(b) = 2 > bar(c) = 3 > bar(d) = 4 > > If you really want by value, flatten it to a list for the return call > with 'return [array get <name>]' > Well, technically speaking, you are not returning an array. Instead, you are directly modifying the array. And of course, another method of doing that would be to build the array within a namespace (even if only the global namespace) and then just modify it directly. At least in the way you do it, the same proc can easily be used for multiple arrays - in the case of the global array situation, to make it "generic" you would have to pass in the array name and then use a variable holding the name or some such thing. |
|
|||
|
On Sep 30, 11:24*am, "Larry W. Virden" <lvir...@gmail.com> wrote:
> On Sep 30, 2:08*pm, David Gravereaux <davyg...@pobox.com> wrote: > > > > > No one has yet answered your first question on arrays. *Yes, you can > > return an array from a proc, just not by value. > > > proc foo {varName} { > > * *upvar $varName local > > * *set value 0 > > * *foreach name {a b c d} {set local($name) [incr value]}} > > > array set bar {} > > > % foo bar > > % parray bar > > bar(a) = 1 > > bar(b) = 2 > > bar(c) = 3 > > bar(d) = 4 > > > If you really want by value, flatten it to a list for the return call > > with 'return [array get <name>]' > > Well, technically speaking, you are not returning an array. Instead, > you are directly modifying the array. And of course, another method of > doing that would be to build the array within a namespace (even if > only the global namespace) and then just modify it directly. > > At least in the way you do it, the same proc can easily be used for > multiple arrays - in the case of the global array situation, to make > it "generic" you would have to pass in the array name and then use a > variable holding the name or some such thing. Can you return an actual data structure in any language? Probably you return a pointer to the start of the structure. In Tcl, you usually pass in the name of the array, the procedure then uses the array name to create/update the array, but just like in most languages, the structures created inside a function (local variables, and the associated storage) disappear once the function returns, so persistent structures must be created somewhere else. |
|
|||
|
On Sep 30, 11:40*pm, "tom.rmadilo" <tom.rmad...@gmail.com> wrote:
> On Sep 30, 11:24*am, "Larry W. Virden" <lvir...@gmail.com> wrote: > > > > > > > On Sep 30, 2:08*pm, David Gravereaux <davyg...@pobox.com> wrote: > > > > No one has yet answered your first question on arrays. *Yes, you can > > > return an array from a proc, just not by value. > > > > proc foo {varName} { > > > * *upvar $varName local > > > * *set value 0 > > > * *foreach name {a b c d} {set local($name) [incr value]}} > > > > array set bar {} > > > > % foo bar > > > % parray bar > > > bar(a) = 1 > > > bar(b) = 2 > > > bar(c) = 3 > > > bar(d) = 4 > > > > If you really want by value, flatten it to a list for the return call > > > with 'return [array get <name>]' > > > Well, technically speaking, you are not returning an array. Instead, > > you are directly modifying the array. And of course, another method of > > doing that would be to build the array within a namespace (even if > > only the global namespace) and then just modify it directly. > > > At least in the way you do it, the same proc can easily be used for > > multiple arrays - in the case of the global array situation, to make > > it "generic" you would have to pass in the array name and then use a > > variable holding the name or some such thing. > > Can you return an actual data structure in any language? Probably you > return a pointer to the start of the structure. In Tcl, you usually > pass in the name of the array, the procedure then uses the array name > to create/update the array, but just like in most languages, the > structures created inside a function (local variables, and the > associated storage) disappear once the function returns, so persistent > structures must be created somewhere else. Larry, you are correct. I just wanted to return the array from the proc directly. And keyed lists are also similar to arrays. As we are using hash arrays in tcl infact we can use the same facility with keyedlists. But we can easily return keyedlists from proc. Any I have few more doubts like we have sleep and after both do the same thing, they wait by specified by the amount of time mentioned. But difference is after is in msec but sleep takes seconds. Why do we have these duplicate commands. In C we can call procs by references but in TCL we cannot. Just wanted to list out the things like these. I will be happy if we can figure out the duplicate commands, or atleast the main purpose of these kinds of similar commands. Thanks in advance! -Anil A Kumar |
|
|||
|
On Sep 30, 12:45*pm, Anil A Kumar <401a...@gmail.com> wrote:
> On Sep 30, 11:40*pm, "tom.rmadilo" <tom.rmad...@gmail.com> wrote: > > > > > On Sep 30, 11:24*am, "Larry W. Virden" <lvir...@gmail.com> wrote: > > > > On Sep 30, 2:08*pm, David Gravereaux <davyg...@pobox.com> wrote: > > > > > No one has yet answered your first question on arrays. *Yes, you can > > > > return an array from a proc, just not by value. > > > > > proc foo {varName} { > > > > * *upvar $varName local > > > > * *set value 0 > > > > * *foreach name {a b c d} {set local($name) [incr value]}} > > > > > array set bar {} > > > > > % foo bar > > > > % parray bar > > > > bar(a) = 1 > > > > bar(b) = 2 > > > > bar(c) = 3 > > > > bar(d) = 4 > > > > > If you really want by value, flatten it to a list for the return call > > > > with 'return [array get <name>]' > > > > Well, technically speaking, you are not returning an array. Instead, > > > you are directly modifying the array. And of course, another method of > > > doing that would be to build the array within a namespace (even if > > > only the global namespace) and then just modify it directly. > > > > At least in the way you do it, the same proc can easily be used for > > > multiple arrays - in the case of the global array situation, to make > > > it "generic" you would have to pass in the array name and then use a > > > variable holding the name or some such thing. > > > Can you return an actual data structure in any language? Probably you > > return a pointer to the start of the structure. In Tcl, you usually > > pass in the name of the array, the procedure then uses the array name > > to create/update the array, but just like in most languages, the > > structures created inside a function (local variables, and the > > associated storage) disappear once the function returns, so persistent > > structures must be created somewhere else. > > Larry, > > you are correct. I just wanted to return the array from the proc > directly. And keyed lists are also similar to arrays. As we are using > hash arrays in tcl infact we can use the same facility with > keyedlists. But we can easily return keyedlists from proc. Any I have > few more doubts like we have sleep and after both do the same thing, > they wait by specified by the amount of time mentioned. But difference > is after is in msec but sleep takes seconds. Why do we have these > duplicate commands. Basically you are speculating. Do you really think we have two identical commands? > In C we can call procs by references but in TCL we cannot. Just wanted > to list out the things like these. Not sure what you mean here. You can store a procedure name in a variable, and then place the variable where a command should go: % set a puts % $a hi hi % $a $a puts Tcl has a more general concept of call by reference, we have named references which you don't even need to pass around in order to use (assuming you agree on the name ahead of time). But it seems the same as with C, if you ask me. > I will be happy if we can figure out the duplicate commands, or > atleast the main purpose of these kinds of similar commands. The main purpose is that they are different commands. One difference is that [after] works with the event loop and sleep just halts the execution of the current script for the specified time. |
|
|||
|
On Oct 1, 1:58*am, "tom.rmadilo" <tom.rmad...@gmail.com> wrote:
> On Sep 30, 12:45*pm, Anil A Kumar <401a...@gmail.com> wrote: > > > > > > > On Sep 30, 11:40*pm, "tom.rmadilo" <tom.rmad...@gmail.com> wrote: > > > > On Sep 30, 11:24*am, "Larry W. Virden" <lvir...@gmail.com> wrote: > > > > > On Sep 30, 2:08*pm, David Gravereaux <davyg...@pobox.com> wrote: > > > > > > No one has yet answered your first question on arrays. *Yes, you can > > > > > return an array from a proc, just not by value. > > > > > > proc foo {varName} { > > > > > * *upvar $varName local > > > > > * *set value 0 > > > > > * *foreach name {a b c d} {set local($name) [incr value]}} > > > > > > array set bar {} > > > > > > % foo bar > > > > > % parray bar > > > > > bar(a) = 1 > > > > > bar(b) = 2 > > > > > bar(c) = 3 > > > > > bar(d) = 4 > > > > > > If you really want by value, flatten it to a list for the return call > > > > > with 'return [array get <name>]' > > > > > Well, technically speaking, you are not returning an array. Instead, > > > > you are directly modifying the array. And of course, another methodof > > > > doing that would be to build the array within a namespace (even if > > > > only the global namespace) and then just modify it directly. > > > > > At least in the way you do it, the same proc can easily be used for > > > > multiple arrays - in the case of the global array situation, to make > > > > it "generic" you would have to pass in the array name and then use a > > > > variable holding the name or some such thing. > > > > Can you return an actual data structure in any language? Probably you > > > return a pointer to the start of the structure. In Tcl, you usually > > > pass in the name of the array, the procedure then uses the array name > > > to create/update the array, but just like in most languages, the > > > structures created inside a function (local variables, and the > > > associated storage) disappear once the function returns, so persistent > > > structures must be created somewhere else. > > > Larry, > > > you are correct. I just wanted to return the array from the proc > > directly. And keyed lists are also similar to arrays. As we are using > > hash arrays in tcl infact we can use the same facility with > > keyedlists. But we can easily return keyedlists from proc. Any I have > > few more doubts like we have sleep and after both do the same thing, > > they wait by specified by the amount of time mentioned. But difference > > is after is in msec but sleep takes seconds. Why do we have these > > duplicate commands. > > Basically you are speculating. Do you really think we have two > identical commands? > > > In C we can call procs by references but in TCL we cannot. Just wanted > > to list out the things like these. > > Not sure what you mean here. You can store a procedure name in a > variable, and then place the variable where a command should go: > > % set a puts > % $a hi > hi > % $a $a > puts > > Tcl has a more general concept of call by reference, we have named > references which you don't even need to pass around in order to use > (assuming you agree on the name ahead of time). But it seems the same > as with C, if you ask me. > > > I will be happy if we can figure out the duplicate commands, or > > atleast the main purpose of these kinds of similar commands. > > The main purpose is that they are different commands. One difference > is that [after] works with the event loop and sleep just halts the > execution of the current script for the specified time. can u give more details on event loops... |
|
|||
|
tom.rmadilo wrote:
> On Sep 30, 12:45 pm, Anil A Kumar <401a...@gmail.com> wrote: ... >> I will be happy if we can figure out the duplicate commands, or >> atleast the main purpose of these kinds of similar commands. > > The main purpose is that they are different commands. One difference > is that [after] works with the event loop and sleep just halts the > execution of the current script for the specified time. Like Tom says, they are different. These two forms do the same thing: sleep 1 after 1000 But [after] does more when a script is placed at the end. set count1 0 set count2 100 proc refresh1 {} { puts [incr ::count1] after 1000 {refresh1} } proc refresh2 {} { puts [incr ::count2] if {$::count2 == 120} {set ::done 1; return} after 1200 {refresh2} } refresh1; refresh2 vwait done puts finished exit Paste that into tclsh. In the above, background activity (sockets, pipes, Tk, etc..) would be allowed due to entering the event loop. A blocking [sleep] is not the same. -- -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkrD3h8ACgkQlZadkQh/RmEKcwCeNs1bM9t0i9Zp2Ii9LvsnuHAH NJEAnAsbcOaTFhEjrtOeovV2FkqL9ym6 =nzHn -----END PGP SIGNATURE----- |
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|