Skip to content
Prev 165133 / 398503 Next

Is = now the same as <- in assigning values

Kenn Konstabel wrote:
as far as i can see, this does precisely what i expect -- it assigns 2
to x and then passes x as the argument a to foo.  did you mean there is
something else happening here?
yes, i think the last one should be the only valid version.  unless you
invent some more complicated syntax...
who said = is more intuitive for assignments?  i said i prefer it, and
that's because of aesthetics, silly me.  in an earlier post, someone
said it is more natural for his students [1].  argue to the contrary.

it depends on how you program, mostly.  if you're doing functional
programming with no reassignments, = is just perfect.

how on earth can x equal x+1?  there is a solution, guess yourself.  but
in r, the semantics of 'x = x + 1'is *not* that x equals x + 1, so
where's the problem.  in a language where = means comparison (e.g., f#),
the expression evaluates to false, no problem.  in a language where =
means unification (e.g., oz), the expression gives a unification
failure.  but there is a long tradition in programming languages of
using = for assignment -- e.g., in fortran.

but even where = means comparison, x = x + 1 may actually evaluate to
true, just as x = x may evaluate to false.  (have you never seen x == x
evaluate to false in java or c, for example?)

vQ



[1] http://tinyurl.com/4o4ha4