oh cool! :) hehe, I thought you would say "it was boring".. anyways, glad it would help newcomers.
p.s.: I didn't "lie", I just said I *thought*.. KKRT On Mon, Jun 04, 2007 at 10:36:55PM +0200, Philippe Valembois - Phil wrote: > hey I don't let you lie :p > I read it from top to bottom and was really interesting ;) > Phil > > Youness Alaoui a écrit : > > oh great! thanks! :) > > I thought noone read that huge mail, lol.. > > > > KKRT > > > > On Mon, Jun 04, 2007 at 06:08:13PM +0100, Tom Hennigan wrote: > >> Okay I've got round to putting it on the wiki > >> (http://amsn-project.net/wiki/Dev:TclTk_Tutorial). I didn't put > >> anything about multiline commands yet. But I think everything else is > >> there! > >> > >> - Tom > >> > >> On 5/31/07, Youness Alaoui <[EMAIL PROTECTED]> wrote: > >>> Yeah, you reminded me of something... > >>> Most 'common problems' with tcl/tk are the "lists theory", substitution > >>> theory, and command theory. > >>> In short, the 'lists theory' is that everything is a list, and tcl works > >>> a lot with list manipulations. > >>> substitution theory is that, if I do "function $arg" the $arg will be > >>> substituted, and if it had a space, the > >>> 'function' will get two arguments, if I do {function $arg} (the {} means > >>> it's a list) the $arg will not be > >>> substituted and the argument will be the same as if I wrote "function > >>> \$arg". If I do [list function $arg] then > >>> $arg will be substituted but if it had a space in it, it will still count > >>> as one argument (not two like > >>> before).. actually $arg will become a list element. > >>> Example : > >>> set file "c:\My documents\file.txt" > >>> if you do > >>> button .b -command "open $file" > >>> then it will fail because it would be the same as doing : > >>> button .b -command "open c:\My documents\file.txt" > >>> (this is what will be stored), so once evaluated, it will evaluate > >>> "C:\My" as the first argument and > >>> "documents\file.txt" as the second argument. > >>> If you do : > >>> button .b -command {open $file} > >>> then it will fail because it will say "$file : file not found" unless you > >>> create a file named "$file" > >>> if you do : > >>> button .b -command [list open $file] > >>> then it will work because Tcl will store the callback as : {open {C:\My > >>> documents\file.txt}} (a list with two > >>> elements, the first being the command, the second being the argument). > >>> and finally, about the 'command theory', it's to say that EVERYTHING is a > >>> command. even 'if'.. so the if is a > >>> command which takes : > >>> if expression body ?elseif body? ?elseif body? ... ?else body? > >>> so if you do : > >>> if $a return > >>> it works, if you want to do : > >>> if $a == $b return > >>> it won't work because you sent "$a" as one argument "==" as a second > >>> argument (the body '==' is invalid, it > >>> would say that '==' is not a valid command) and $b as the third argument > >>> (again error because it only accepts > >>> else and elseif) and return as the 4th argument. So you group them into a > >>> list : > >>> if {$a == $b} return > >>> the {$a == $b} becomes a list. You could have also done : > >>> if [list $a == $b] return > >>> but it's better to put braces, and the 'if' command will evaluate the > >>> expression and *substitute in the parent > >>> namespace* (which is why it works, even if { } will disable substitution). > >>> Also, you CAN'T do : > >>> if {$a == $b} { > >>> return 0 > >>> } > >>> else > >>> { > >>> return 1 > >>> } > >>> > >>> because it will say "else : invalid command". The commands are delimited > >>> by either a ';' or by a newline, so > >>> when you close the brace after the if and go to the next line, it means > >>> that you finished with the 'if'. This > >>> means you HAVE to put the 'else' on the same line as the closing brace of > >>> the body, like this : > >>> if {$a == $b} { > >>> return 0 > >>> } else { > >>> return 1 > >>> } > >>> The same applies for the 'else' you can't put a newline after the 'else', > >>> otherwise it will say "{ : invalid > >>> command". > >>> You can put newlines inside the body of the if only because we do a { } > >>> (if you do [list] you'll need to put a > >>> backslash at the end of each line otherwise it will say "missing close > >>> bracket", like this : > >>> if {$a == $b} [list \ > >>> return 0 \ > >>> ] else [list \ > >>> return 1 > >>> ] > >>> but you DON'T WANT TO DO THIS because... well, remember { } allows you to > >>> disable substitution, so if you do for > >>> example : > >>> if {$a == $b} [list return [exit]] > >>> then when evaluation the 'if', the [list return [exit]] will be evaluated > >>> (to go as an argument of the if) and > >>> 'exit' will be called even if $a != $b. > >>> So to continue, when you do the { }, nothing is evaluated, so if you do > >>> if { $a == $b } { > >>> return 0 > >>> } > >>> then if will get 2 arguments, the first being the expression and the > >>> second being a list containing multiple > >>> elements : a newline, a series of spaces, a 'return', a '0' and a > >>> newline. When the 'if' will evaluated that > >>> list, it will be evaluated as code and the variables/commands will be > >>> substituted/evaluated and the newlines > >>> will be interpreted as command delimiters. > >>> You can also do something like this : > >>> set body { whatever_function $arg > >>> return 0 > >>> } > >>> if {$a == $b} $body > >>> and since $body is not between { } it will be replaced by the code > >>> above... > >>> beware, if you did : > >>> if {$a == $b} {$body } > >>> then $body will only be substituted AFTER the if is entered and will be > >>> evaluated as one command, it will say > >>> that : > >>> {whatever_function $arg > >>> return 0 > >>> } : invalid command > >>> > >>> oh and yes, if you were meant to ask, yes, you can put newlines and put > >>> spaces in a command, so if you do : > >>> proc {a > >>> b > >>> c} { } {puts 'abc called'} > >>> > >>> a command called {a > >>> b > >>> c} will be created. And you can call it with > >>> {a > >>> b > >>> c} > >>> or with : > >>> set command "a\nb\nc" > >>> $command > >>> > >>> it's fun Tcl, right ? you just need to understand those three basics, > >>> anything is a command getting executed.. > >>> the tcl keywords are just 'built-in' commands (like if), understand lists > >>> and substitutions... and once you get > >>> that, you can do a lot of fancy stuff (like commands with spaces or > >>> newlines in them :p) > >>> > >>> Finally, here are three interesting links in the forums in which I > >>> explained what I just explained in this mail, > >>> a bit differently, maybe better, with other examples, and probably with a > >>> bit more info. So please read them > >>> too. > >>> http://www.amsn-project.net/forums/viewtopic.php?p=17467 > >>> http://www.amsn-project.net/forums/viewtopic.php?p=5801#5801 > >>> http://www.amsn-project.net/forums/viewtopic.php?p=4461#4461 > >>> > >>> and I would REALLY love it if someone could summarize all this (or just > >>> copy/paste it?) to the wiki in a page > >>> like Dev:Tcl/Tk_Tutorials > >>> > >>> > >>> > >>> p.s.: I never tried/tested the commands with newlines, but I'm guessing > >>> they will work,I know that if I had put > >>> $body, it will tell me an error trying to execute a command containing > >>> the newline, but I never created one in > >>> itself. > >>> > >>> Thanks and have fun! > >>> KaKaRoTo > >>> > >>> > >>> On Thu, May 31, 2007 at 12:05:49AM +0200, Mirko Hansen wrote: > >>>> Wow thanks a lot everybody for this nice welcome. It's a real pleasure to > >>>> me. I think I should introduce myself roughly. Well, I think you all > >>>> already > >>>> know, but my name is Mirko. ;) I'm 24 years old, living in Germany, and > >>>> actually I'm studying computer science at university. It's sometimes > >>>> really > >>>> time-consuming, especially if we have those really nice homeworks like > >>>> the > >>>> last two days, but I hope I'll be of use for the team, anyway I'll give > >>>> my > >>>> best to. As Youness said, I'm very new to TCL, I never had to deal with > >>>> it > >>>> before, so I would be really grateful if you advise me of my possibly > >>>> made > >>>> mistakes, to be able to learn from them. :) > >>>> > >>>> I think you'll hear from me soon. To a great teamwork! :) > >>>> > >>>> Bye, > >>>> Mirko > >>>> > >>>> 2007/5/30, Youness Alaoui <[EMAIL PROTECTED]>: > >>>>> yeah, sounds intriguing right ? > >>>>> well, baaazen is the username of Mirko. And this mail is to announce > >>>>> that > >>>>> he's been added as part of the team. > >>>>> So everyone, please welcome Mirko into the team, and please be helpful. > >>>>> Mirko, if you need anything, don't hesitate to ask. I think you've been > >>>>> following the ML for a little while now > >>>>> so you should know how we work. in short ; > >>>>> 1 - a bugfix, you can commit > >>>>> 2 - a change to the UI should be discussed > >>>>> 3 - a change of behavior should be discussed > >>>>> 4 - a new feature should be discussed. > >>>>> > >>>>> Mirko is still studying and won't have much time (like everyone else) > >>>>> but > >>>>> he promised to do his best to try and > >>>>> help. He doesn't know much Tcl but from the patches he sent, it shows > >>>>> that > >>>>> he's very skilled and I'm sure he'll > >>>>> learn it all pretty soon. > >>>>> > >>>>> KaKaRoTo > >>>>> > >>>>> ------------------------------------------------------------------------- > >>>>> This SF.net email is sponsored by DB2 Express > >>>>> Download DB2 Express C - the FREE version of DB2 express and take > >>>>> control of your XML. No limits. Just data. Click to get it now. > >>>>> http://sourceforge.net/powerbar/db2/ > >>>>> _______________________________________________ > >>>>> Amsn-devel mailing list > >>>>> Amsn-devel@lists.sourceforge.net > >>>>> https://lists.sourceforge.net/lists/listinfo/amsn-devel > >>>>> > >>>> ------------------------------------------------------------------------- > >>>> This SF.net email is sponsored by DB2 Express > >>>> Download DB2 Express C - the FREE version of DB2 express and take > >>>> control of your XML. No limits. Just data. Click to get it now. > >>>> http://sourceforge.net/powerbar/db2/ > >>>> _______________________________________________ > >>>> Amsn-devel mailing list > >>>> Amsn-devel@lists.sourceforge.net > >>>> https://lists.sourceforge.net/lists/listinfo/amsn-devel > >>> > >>> ------------------------------------------------------------------------- > >>> This SF.net email is sponsored by DB2 Express > >>> Download DB2 Express C - the FREE version of DB2 express and take > >>> control of your XML. No limits. Just data. Click to get it now. > >>> http://sourceforge.net/powerbar/db2/ > >>> _______________________________________________ > >>> Amsn-devel mailing list > >>> Amsn-devel@lists.sourceforge.net > >>> https://lists.sourceforge.net/lists/listinfo/amsn-devel > >>> > >> ------------------------------------------------------------------------- > >> This SF.net email is sponsored by DB2 Express > >> Download DB2 Express C - the FREE version of DB2 express and take > >> control of your XML. No limits. Just data. Click to get it now. > >> http://sourceforge.net/powerbar/db2/ > >> _______________________________________________ > >> Amsn-devel mailing list > >> Amsn-devel@lists.sourceforge.net > >> https://lists.sourceforge.net/lists/listinfo/amsn-devel > > > > ------------------------------------------------------------------------- > > This SF.net email is sponsored by DB2 Express > > Download DB2 Express C - the FREE version of DB2 express and take > > control of your XML. No limits. Just data. Click to get it now. > > http://sourceforge.net/powerbar/db2/ > > _______________________________________________ > > Amsn-devel mailing list > > Amsn-devel@lists.sourceforge.net > > https://lists.sourceforge.net/lists/listinfo/amsn-devel > > > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Amsn-devel mailing list > Amsn-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/amsn-devel ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ Amsn-devel mailing list Amsn-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/amsn-devel