For Programmers: Free Programming Magazines  


Home > Archive > Tcl > January 2006 > interp use question









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author interp use question
Earl Grieda

2006-01-30, 7:04 pm

In another thread a poster said that he prefers to use interp versus a proc,
at least for some purposes. This is the example given.

> More practical example: The Img package can capture widgets into
> a photo widget. You can wrap it like this:
>
> interp alias {} capture {} image create photo -format window -data
>
> or like that:
> proc capture {w} {
> return [image create photo -format window -data $w]
> }
> As they are roughly equivalent, I like simpler better :)
>


Although I have been using Tcl for a few years I have never used the interp
command. So, I am unsure just exactly what is being done in the above
example. Specifically, I am unsure how the example command, capture, is
used when defined by interp.

An example use of the proc defined capture command would be:
set image1 [capture $w]

How is the interp capture command used in a program? Is it written the same
way as the proc version and -data "knows" that the $w contains its data?



Bryan Oakley

2006-01-30, 7:04 pm

Earl Grieda wrote:
> In another thread a poster said that he prefers to use interp versus a proc,
> at least for some purposes. This is the example given.
>
>
>
>
> Although I have been using Tcl for a few years I have never used the interp
> command. So, I am unsure just exactly what is being done in the above
> example. Specifically, I am unsure how the example command, capture, is
> used when defined by interp.
>
> An example use of the proc defined capture command would be:
> set image1 [capture $w]
>
> How is the interp capture command used in a program? Is it written the same
> way as the proc version and -data "knows" that the $w contains its data?
>


It is used the same way:

set image1 [capture $w]

interp aliases are just that -- aliases. It says to the interpreter
"when you see 'capture', replace with 'image create photo -format window
-data'" (without the quotes, of course...).

Thus, from the interpreters perspective the following two are synonymous:

capture $w
image create photo -format window -data $w

Note that any arguments you give to the capture alias are appended to
the command, so aliases only work when they are a prefix to a longer
command. That is, you can't use an alias if you want arguments to appear
in the middle of the invocation.


--
Bryan Oakley
http://www.tclscripting.com
Earl Grieda

2006-01-30, 7:04 pm


"Bryan Oakley" <oakley@bardo.clearlight.com> wrote in message
news:LmtDf.23213$F_3.4020@newssvr29.news.prodigy.net...
> Earl Grieda wrote:
proc,[color=darkred]
interp[color=darkred]
same[color=darkred]
>
> It is used the same way:
>
> set image1 [capture $w]
>
> interp aliases are just that -- aliases. It says to the interpreter
> "when you see 'capture', replace with 'image create photo -format window
> -data'" (without the quotes, of course...).
>
> Thus, from the interpreters perspective the following two are synonymous:
>
> capture $w
> image create photo -format window -data $w
>
> Note that any arguments you give to the capture alias are appended to
> the command, so aliases only work when they are a prefix to a longer
> command. That is, you can't use an alias if you want arguments to appear
> in the middle of the invocation.
>


Thanks. Now I understand, and will keep my eye open for using this.


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com