i.e.
set test [abs -20]
this returns the value of 20 for $test... as I would expect.
If I try this exact situation in a wish script, the interepter
generates an error message saying that abs is an invalid command.
Any ideas?
-Derick
Please respond to:
username: d e r i c k
domain: b f t r . c o m
FWIW, It fails for me in tclsh AND wish for tcl 8.0 on HP-UX 10.20.
Chris
--
Rens-se-LEER is a county. RENS-se-ler is a city. R-P-I is a school in
Troy!
: i.e.
: set test [abs -20]
: this returns the value of 20 for $test... as I would expect.
: If I try this exact situation in a wish script, the interepter
: generates an error message saying that abs is an invalid command.
: Any ideas?
Try instead:
set test [expr {abs(-20)}]
Explantion:
If you invoke an unknown command in an interactive Tcl shell, it will
(finally) try to exec this command; thus executing a system program
or command; you probably have a program abs that does the right
thing on your system, and this is doing the real work.
From a script, this path is not tried, and you must explicitely use
the exec command to execute external programs.
In your case it is better to use the abs function that is available through
the Tcl expr command.
--
Peter De Rijk der...@uia.ua.ac.be
<a href="http://rrna.uia.ac.be/~peter/personal/peter.html">Peter</a>
To achieve the impossible, one must think the absurd.
to look where everyone else has looked, but to see what no one else has seen.
:If I try this exact situation in a wish script, the interepter
:generates an error message saying that abs is an invalid command.
:Any ideas?
Here's what I tried. First I grepped thru the man pages to see
where I could find the phrase 'absolute value' - you of course could
use tkman to do an even better job ;-).
Anyways, I found it in the expr.n man page. When I read that
page, it talks about
expr abs()
so I started up tclsh and typed in
expr abs(-20)
and got back a 20.
Then I exited tclsh and started wish. I typed in expr abs(-20) and
again got back a 20.
Now on the other hand, you were typing something a bit different.
Try the above format and see if you still have problems. If so,
then let us know the version of tk, the OS you are using, what
patches you have applied, what compiler you are using, etc.
--
<URL:mailto:lvi...@cas.org> Quote: In heaven, there is no panic,
<*> O- <URL:http://www.teraform.com/%7Elvirden/> only planning.
Unless explicitly stated to the contrary, nothing in this posting
should be construed as representing my employer's opinions.
I don't know why it *would* work at all - there is no abs function in Tcl.
The only thing I can think of is that it's exec'ing a program in the
path (?), which would make the behavoir particular to your system.
What you *should* be doing is:
set test [expr abs(-20)]
... as abs() is an "expr" subcommand (RTFM on "expr").
******************************************************************************
Steve McAndrewSmith HTTP: www.niftytech.com/~stevemc
Drummer - Hacker - Minor Deity PGP: finger ste...@niftytech.com
------------------------------------------------------------------------------
On the sixth day God created man
On the seventh day, man returned the favor.
******************************************************************************
ste...@turbonet.com (Steve McAndrewSmith) writes:
> nos...@here.com wrote:
> : I'm trying to use the absolute value function in tcl/tk 8.0 from a
> : wish script and it doesn't appear to work. I can use the 'abs'
> : function from a tclsh shell:
> :
> : If I try this exact situation in a wish script, the interepter
> : generates an error message saying that abs is an invalid command.
> : Any ideas?
>
> I don't know why it *would* work at all - there is no abs function in Tcl.
> The only thing I can think of is that it's exec'ing a program in the
> path (?), which would make the behavoir particular to your system.
Just checked.
TclX provides several math functions usually part of 'expr' as
separate commands, including 'abs'. Maybe his tclsh is linked with
TclX, but not his wish.
--
Sincerely,
Andreas Kupries <a.ku...@westend.com>
<http://www.westend.com/~kupries/>
-------------------------------------------------------------------------------
set test [expr abs(-20)]
Of course, noting prevent you from defining
proc abs x {
expr abs($x)
}
which would provide such a command for you,
: >
: > If I try this exact situation in a wish script, the interepter
: > generates an error message saying that abs is an invalid command.
: > Any ideas?
: FWIW, It fails for me in tclsh AND wish for tcl 8.0 on HP-UX 10.20.
It fails under linux with both tclsh8.0p2 and tclsh7.6 as it should.
Considering strange behavoir of this command I can only imagine
that you have separate program abs, which prints absolute value of its
argument to stdout. In such case it would indeed work from interactive
tclsh but fail from script.
: Chris
: --
: Rens-se-LEER is a county. RENS-se-ler is a city. R-P-I is a school in
: Troy!
--
--------------------------------------------------------
I have tin news and pine mail...
Victor Wagner @ home = vitus @ orc . ru