Suggestion: = as synonym for == in expr 
Author Message
 Suggestion: = as synonym for == in expr

 A suggestion for Tcl: make '=' a synonym for '==' in expr.

 Yesterday I was running a computer lab session in which students
 were learning Tcl. They were typing in = instead of == every so
 often, like new C programmers.

 My explanation for why the interpreter was complaining was "it's
 just like C" but today it occurred to me that there's no actual
 need for it, since Tcl doesn't use = for assignment.

 Accepting = as well as == will make Tcl easier to learn and use
 for the large number of people who don't use C but do use script
 languages, and it's fully compatible with existing code.

 Implementation only requires changing a couple of lines in the
 expression lexical analyzer. (As far as I know, anyway.) Below
 is the patch for Tcl7.6p2 if you want to try it.

        Hugh Fisher
        DCS, ANU
        My opinions only

--- generic/tclExpr.c   Wed May 28 10:26:51 1997
***************
*** 624,635 ****
            return TCL_OK;

        case '=':
!           if (p[1] == '=') {
                infoPtr->expr = p+2;
!               infoPtr->token = EQUAL;
!           } else {
!               infoPtr->token = UNKNOWN;
!           }
            return TCL_OK;

        case '!':
--- 624,632 ----
            return TCL_OK;

        case '=':
!           if (p[1] == '=')
                infoPtr->expr = p+2;
!           infoPtr->token = EQUAL;
            return TCL_OK;

        case '!':



Sun, 14 Nov 1999 03:00:00 GMT  
 Suggestion: = as synonym for == in expr


Quote:

> Yesterday I was running a computer lab session in which students
> were learning Tcl. They were typing in = instead of == every so
> often, like new C programmers.

Ack, no no no.  This is a common error in C, and we don't want to introduce
it into Tcl as well.  == is the equality operator, while = is the set
operator, yet you are suggesting we make them identical in Tcl?

--

  Software Engineer, Oregon R&D        office: 541.683.7891
  CADIX International, Inc.            fax:    541.683.8325
             URL: http://www.cs.uoregon.edu/~jhobbs/



Sun, 14 Nov 1999 03:00:00 GMT  
 Suggestion: = as synonym for == in expr



Quote:
> Ack, no no no.  This is a common error in C, and we don't want to
introduce
> it into Tcl as well.  == is the equality operator, while = is the set
> operator, yet you are suggesting we make them identical in Tcl?

I would prefer that too. I do use C++, but I like languages which use just
= even more!

Another improvement would be simple statements like a = $a * 2  or customer
= $name + ", Mister"
--

bye, Boris Ottlewski - SystemSoft

*** Please remove nospam for a reply ***



Sun, 14 Nov 1999 03:00:00 GMT  
 Suggestion: = as synonym for == in expr

Quote:
> Ack, no no no.  This is a common error in C, and we don't want to introduce
> it into Tcl as well.  == is the equality operator, while = is the set
> operator, yet you are suggesting we make them identical in Tcl?

There is no "set" operator in TCL, just a set command.  The "=="
construct
is just hysterical compliance with C, which by the way is about the only
language that doesn't determine the difference between assignement and
equality operators by context (Not that I'm complaining).

-Ron



Sun, 14 Nov 1999 03:00:00 GMT  
 Suggestion: = as synonym for == in expr


Quote:
>...C, which by the way is about the only
>language that doesn't determine the difference between assignement and
>equality operators by context...

Pascal:         := vs =
fortran:        = vs .EQ.
APL:            (now where did I put that special font?)
--



Sun, 14 Nov 1999 03:00:00 GMT  
 Suggestion: = as synonym for == in expr


Quote:
>Ack, no no no.  This is a common error in C, and we don't want to introduce
>it into Tcl as well.  == is the equality operator, while = is the set
>operator, yet you are suggesting we make them identical in Tcl?

Since = is not the set operator, or any operator at all in Tcl, where's
the confusion? Tcl isn't a superset or subset of C, and has many other
syntactic differences. (My C compiler hates it when I absent-mindedly put
curly brackets around if tests, for example.)

If C programmers want to use == in Tcl, fine. But for those people whose
preferred development language is Visual Basic, HyperCard, Bourne Shell,
or English, '=' is the equality operator. There are a lot more of them,
and they seem to be the intended target audience for Tcl as a scripting
language gluing components together, so why not remove this particular
banana-skin from the road?

        Hugh Fisher
        DCS, ANU
        My opinions only



Mon, 15 Nov 1999 03:00:00 GMT  
 Suggestion: = as synonym for == in expr

Quote:

> Another improvement would be simple statements like a = $a * 2  or customer
> = $name + ", Mister"

This is not the spirit of Tcl. Every Tcl "statement" is a command, starting
with a keyword, followed by "meaningless" words. Period. In your assignment,
the keyword is missing. It would break the whole Tcl processing chain.
Remember that Tcl (Tool Command Language) is NOT a programming language in
the traditional sense---it has almost no grammar, unlike most other
languages. You can add a new "when" construction yourself. Try that in C.
This has advantages and disadvantages, but you choose for it when you pick
Tcl. I vote for keeping it this way.

Moreover, I think that

  set customer "$name, Mister"

is simpler than the "+" concatenation operation, but that's personal taste.
I use [expr ...] very, very little---apparently I can circumvent most
numerical calculations in my programs. Tcl isn't suitable for number
crunching anyway.

Quote:
> I would prefer that too. I do use C++, but I like languages which use just
> = even more!

I can live with "=" next to "==", as long as they both keep their meaning
as equivalence operator. However, since we also have !=, <=, >= etc. I
think that the == isn't bad at all.

I seem to remember having seen a language (Clipper??) where "=" between
strings meant "compare up to the length of the left string" ("abc"="abcde"),
and "==" meant an exact compare ("abc"=="abc"). But this is not really
mnemonic, I'm afraid.

Simplest reasoning: Tcl has always used "==", so keep it that way.

--
Jeroen Hoppenbrouwers, Senior Researcher at     |  Stop connecting computers;
Infolab, Tilburg University, The Netherlands    |  start connecting people!
             http://infolabwww.kub.nl:2080/infolab/people/hoppie



Mon, 15 Nov 1999 03:00:00 GMT  
 Suggestion: = as synonym for == in expr


Quote:


>> Another improvement would be simple statements like a = $a * 2  or customer
>> = $name + ", Mister"

>This is not the spirit of Tcl. Every Tcl "statement" is a command, starting
>with a keyword, followed by "meaningless" words. Period.

        To make this even a littl more clear, each command in Tcl has its own
        syntax, which it is in charge of.  This is a little like a DOS command,
        The command gets tis arguements and decides what to do with them.  To
        do something like what you want is very easily added simply be writing
        your own Tcl command (which you can do in Tcl), which we might call
        "let"

        let a = $a * 2

        proc let {parameter method left to reader} {
            global $target
            set $target [expr ... ]
        }

        let becomes your command, you control the syntax.

        Tcl was designed as an extension language.  It is easy to extend
        itself, and is pretty easy to incorporate into another package.

        [snip]

Quote:
>Tcl. I vote for keeping it this way.

        me, too

Quote:

>Moreover, I think that

>  set customer "$name, Mister"

>is simpler than the "+" concatenation operation, but that's personal taste.
>I use [expr ...] very, very little---apparently I can circumvent most
>numerical calculations in my programs. Tcl isn't suitable for number
>crunching anyway.

        I do a fair amount of numerical work in Tcl.  When the application is
        fairly interactive, I don't have too much problem.  When it is batch
        and fairly computational I call a perl script.  This lets me use the
        right tool for the each job.  I have other tools where they are
        appropriate.  None-the-less, I have been very successful in using
        Tcl in appropriate number crunching situations.

Quote:

>I can live with "=" next to "==", as long as they both keep their meaning
>as equivalence operator. However, since we also have !=, <=, >= etc. I
>think that the == isn't bad at all.

>Simplest reasoning: Tcl has always used "==", so keep it that way.

        All the important modern languages (C++, Java, Tcl, perl, too
        many to list all here)  use the == and programming classes especially
        should promote this usage.  I teach both Tcl and perl at North Harris
        College, primarily to geoscientists and geo-oriented sysadmins, and
        I don't find them to have a problem learning this.

Quote:

>--
>Jeroen Hoppenbrouwers, Senior Researcher at     |  Stop connecting computers;
>Infolab, Tilburg University, The Netherlands    |  start connecting people!
>             http://infolabwww.kub.nl:2080/infolab/people/hoppie

Will

--
# Copyright 1997 Will Morse.  Internet repost/archive freely permitted.
# Hardcopy newspaper, magazine, etc. quoting requires permission.
#
#      Gravity,                    #    Will Morse
#      not just a good idea,       #    Houston, Texas

#
#   These are my views and do not necessarly reflect anyone else/



Mon, 15 Nov 1999 03:00:00 GMT  
 Suggestion: = as synonym for == in expr

There actually is/was an extension that allowed inline assignment.
Check the FAQ if you like it.

Dave

On 28 May 1997 16:24:12 GMT, "Boris Ottlewski"

<snip>

Quote:
>Another improvement would be simple statements like a = $a * 2  or customer
>= $name + ", Mister"
>--

>bye, Boris Ottlewski - SystemSoft

>*** Please remove nospam for a reply ***



Mon, 15 Nov 1999 03:00:00 GMT  
 Suggestion: = as synonym for == in expr

Quote:
> All the important modern languages (C++, Java, Tcl, perl, too
> many to list all here)  use the == and programming classes especially
> should promote this usage.  

Well, I don't buy this argument.  You're defining modern as derived
from C or written in C by C programmers.  Plenty of "modern" languages
out there from Visual Basic all the way up to REXX that determine
equality from assignment by context.


Mon, 15 Nov 1999 03:00:00 GMT  
 Suggestion: = as synonym for == in expr


Quote:


>> Another improvement would be simple statements like a = $a * 2  or customer
>> = $name + ", Mister"

>This is not the spirit of Tcl. Every Tcl "statement" is a command, starting
>with a keyword, followed by "meaningless" words. Period.

Actually, "a = $a * 2" makes perfect sense in an object-oriented context
like Tk or [incr tcl] uses, where each object becomes its own command.
If each variable were its own object, there could be an '=' method on it
which assigned a value.  In fact you can do exactly this with [incr tcl]
right now.  For example:

itcl_class variable {

  method = { args } {
    global $this
    set $this [expr $args]
  }

Quote:
}

% variable a
a
% a = 2
2
% a = $a * 2
4

You could even have subclasses of variable to create your own types of
variables with type checking, range checking, etc.

--
Steve Kanefsky



Fri, 19 Nov 1999 03:00:00 GMT  
 Suggestion: = as synonym for == in expr


Quote:


>> I would prefer that too. I do use C++, but I like languages which use just
>> = even more!

> I can live with "=" next to "==", as long as they both keep their meaning
> as equivalence operator. However, since we also have !=, <=, >= etc. I
> think that the == isn't bad at all.

This is a particularly good idea if we keep "=" as an undefined
operator so that anyone using it will get told pretty sharpish that it
isn't any good.  If we have to have assignment in expressions (and I'm
against it for many reasons voiced by others) at least let it be
denoted by ":=" since "=" would be confusing to many.  It is much
harder to confuse ":=" and "==" :^)

Quote:
> Simplest reasoning: Tcl has always used "==", so keep it that way.

I'd agree with that.  So much code would be broken unless the
double-symbol was also kept, and having two ways of writing the same
thing is adding cruft for cruft's sake...

Donal.
--
Donal K. Fellows   http://r8h.cs.man.ac.uk:8000/  (SAY NO TO COMMERCIAL SPAMS!)

    The at symbol in my email address has been shifted one word right
    to deter spam-bots.  Sorry for any inconvenience this causes you.



Fri, 19 Nov 1999 03:00:00 GMT  
 Suggestion: = as synonym for == in expr


Quote:
>> All the important modern languages (C++, Java, Tcl, perl, too
>> many to list all here)  use the == and programming classes especially
>> should promote this usage.  

>Well, I don't buy this argument.  You're defining modern as derived
>from C or written in C by C programmers.  Plenty of "modern" languages
>out there from Visual Basic all the way up to REXX that determine
>equality from assignment by context.

Well, it's not that problem actually. It's actually that C and "C"-ist
languages have = be a function rather then a procedure. Both return a
value.  So it's not a failing, it's a feature. :)

        <anytype> =( <anytype> &dest, <anytype> value )
        int =( <anytype> left, <anytype> right )

Can't really tell those apart.



Sun, 21 Nov 1999 03:00:00 GMT  
 
 [ 22 post ]  Go to page: [1] [2]

 Relevant Pages 

1. expr suggestion

2. Tcl "expr" command change suggestion

3. X != [expr tan([expr atan(X)])] ????

4. Looking for a short SYNONYM

5. common type synonyms (haskell)

6. type synonyms

7. X86 opcode synonyms

8. english synonyms

9. Synonyms

10. braces and expr: use expr with if and for?

11. newbie: print dest-expr

12. Call for new function ? expr()

 

 
Powered by phpBB® Forum Software