|
![](/i/fill.gif) |
On 6/10/2011 8:18, Invisible wrote:
> I think Smalltalk will also let you accidentally redefine 3 to mean
> something else.
I think anything the parser sees is hard-coded, but I could be wrong there.
> Haskell will definitely let you define, say, 2+2=5. You'd be hard pressed to
> do this "by accident" though...
And what does this result in? Is it just that the expression "2+2" matches
before "<integer> + <integer>" or some such, so 2+2=5 but 2+3=5 also?
"By accident" is pretty easy in fortran. All values, including literals, are
passed by reference to a subroutine, so if the subroutine assigns to
something that's a literal, you probably just changed the global value of
that literal. (I.e., in most fortran implementations, "3" refers to an
anonymous global variable that holds the value "3".)
In FORTH, you just write
: 2 3 ;
So, "the subroutine named 2 now returns 3". The way the parser works is
that if it can't find the name of a routine, it then tries to parse it as a
literal. But if it finds the name of a function, it uses it. Not something
you're likely to do by accident unless you mess up some metaprogramming.
--
Darren New, San Diego CA, USA (PST)
"Coding without comments is like
driving without turn signals."
Post a reply to this message
|
![](/i/fill.gif) |