home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!think.com!ames!agate!sprite.Berkeley.EDU!ouster
- From: ouster@sprite.Berkeley.EDU (John Ousterhout)
- Newsgroups: comp.lang.tcl
- Subject: Advice wanted on math functions for Tcl 7.0
- Date: 22 Dec 1992 01:09:34 GMT
- Organization: U.C. Berkeley Sprite Project
- Lines: 50
- Distribution: world
- Message-ID: <1h5pseINNkvu@agate.berkeley.edu>
- NNTP-Posting-Host: tyranny.berkeley.edu
-
-
- I'm about to start in earnest on the Tcl 7.0 release (first I'll
- probably put out a Tk 3.1 release to fix all the bugs people are
- finding with 3.0). Thanks for all the input that many of you
- provided in response to my draft of possible changes for 7.0.
- There's still one issue I haven't been able to resolve, having to
- do with the implementation of math functions like sin and cos. This
- message explains the issue and then asks for a vote from those of
- you that care.
-
- There are two possible ways to implement math functions: embedded into
- expr or as separate commands, and I can't make up my mind about which
- way to do it.
-
- In the embedded implementation, the syntax of expressions gets extended
- with functional notation for all the math functions so that you can say
- things like
- expr {$x*sin(2*$theta) + $y*cos(2*$theta)}
-
- In the command implementation, each math function becomes a separate
- command. These commands would allow not only numbers but arbitrary
- expressions as arguments, and produce floating-point string results,
- so the expr command above would look like this instead:
- expr {$x*[sin 2*$theta] + $y*[cos 2*$theta]}
-
- Here are the tradeoffs between the two approaches, as I see them:
-
- 1. The embedded approach avoids having to add a lot of commands (10-20)
- to the command name space and uses the normal functional syntax that
- people are used to in expressions in other languages like C.
- 2. By putting the functions into expr, there is less conversion to and
- from ASCII, which is more efficient (ASCII conversion is pretty slow
- on most machines). In the second example above, the results of the
- sin and cos commands have to be printed in ASCII, then reparsed by
- expr; in the first example the only conversion to ASCII is when expr
- creates its result.
-
- 3. The command approach avoids adding additional syntax to the expr
- command and uses the normal command-substitution mechanism that
- people are used to in Tcl.
- 4. In the command approach it's possible to use the individual math
- functions separately without having to go through expr. For example,
- you could say "set a [cos $x]", whereas in the embedded approach
- you'd have to say "set a [expr cos($x)]"
-
- If you have a preference between these two schemes, please send me a
- message with your vote. All it needs to say is "Embedded" or
- "Separate commands". If there is a strong sentiment one way or the
- other then I'll go with the majority. Otherwise I may have to flip
- a coin.
-