Inline return values



On Jul 1, 7:44 pm, Kaitzschu
<kaitzs...@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
On Tue, 1 Jul 2008, dave.joub...@xxxxxxxxxxxxxx wrote:
On Jun 30, 12:35 pm, Kaitzschu
set tl [lrange [split [read $in] \n end-[incr n -1] end]

As an aside, I found myself shocked at the thought that one could use
incr that way!

<snip>

There has been some tangential discussion using "inline return values" on
tclcore mailing list regarding [chan pipe], but I guess this doesn't
really apply since using a "mutator" command this way is most likely going
to result in an error, as you point out with your scenario.

But I like it! Even if it is going to put a nail to my foot sometimes :)


Ah yes, for "casual" programming tasks I also like (ab)using return
values of commands. I especially like that [set] always returns a
value. My favourite (ab)use is the "slurp" one-liner:

set data [read [set f [open $filename]]][close $f]

Of course, in production code it's not a good idea to do this.
.



Relevant Pages

  • Re: Inline return values
    ... incr that way! ... There has been some tangential discussion using "inline return values" on tclcore mailing list regarding, but I guess this doesn't really apply since using a "mutator" command this way is most likely going to result in an error, as you point out with your scenario. ...
    (comp.lang.tcl)
  • Re: Great SWT Program
    ... These lines are the output of a directory-listing command and are ... With typical Windows tools, one can select a block of ... the editor you don't even have the benefit of whatever autocomplete ...
    (comp.lang.java.programmer)
  • Re: Name change
    ... nearly impossible to uninstall, so I'm a bit wary about giving it a go. ... hard to scrape off the walls if the uninstall or make uninstall command ... when it shuts down - startup's quick (RAM check aside), ...
    (uk.people.support.depression)
  • Re: (some) Old Templars do not die/Long and Speculative
    ... but the leadership was composed entirely of (French) knights.... ... But not inventors. ... in command of the strategy in Outremer. ...
    (soc.history.medieval)
  • Re: Great SWT Program
    ... a line of the display for showing a search command in progress ... search turns up some references to Chinese and vim that makes me ... (repeat command) ...
    (comp.lang.java.programmer)