It logically follows from how arrays in C works, so I don't really know if it qualifies for weird/suprising, but the old array[i] / i[array] thing is fun to show to people who haven't seen it before. The most amusingly weird thing I can think of is INTERCAL's COMEFROM: http://en.wikipedia.org/wiki/COMEFROM
Strangest Programming Language Feature?
21–30 of 66 posts
Re: Strangest Programming Language Feature?
#22Earlier quoted context omitted.
This line in MUMPS is not only valid, it also actually does something potentially useful: s:foo'="" foo(foo)=foo It's actually a bit tricky to explain what it does. Everything in MUMPS is effectively a tree. Each tree has a value in the "root node" and you can set it like this: set foo="hello" You can also put data deeper into the tree: set foo("fizz")="buzz" So if something is passed to you and you want to know if y…
It is amazing that MUMPS will be 50 years old in 2 years -- and it still alive and kicking. An emergency MUMPS project is still my highest billing project (per hour) ever.
Re: Strangest Programming Language Feature?
#23It logically follows from how arrays in C works, so I don't really know if it qualifies for weird/suprising, but the old array[i] / i[array] thing is fun to show to people who haven't seen it before. The most amusingly weird thing I can think of is INTERCAL's COMEFROM: http://en.wikipedia.org/wiki/COMEFROM
Can you explain your array[i] / i[array] reference? I can't find it on Google.
a[10] 10[a]
This is because a[10] is equivalent to (a + 10), and 10[a] is equivalent to (10 + a), as the first comment on this answer explains.
[1] http://stackoverflow.com/questions/1995113/strangest-languag...
Re: Strangest Programming Language Feature?
#24It logically follows from how arrays in C works, so I don't really know if it qualifies for weird/suprising, but the old array[i] / i[array] thing is fun to show to people who haven't seen it before. The most amusingly weird thing I can think of is INTERCAL's COMEFROM: http://en.wikipedia.org/wiki/COMEFROM
Can you explain your array[i] / i[array] reference? I can't find it on Google.
Re: Strangest Programming Language Feature?
#25Fun fact, this is also the reason why 'i' is commonly used as a name for the loop counter variable.
In early FORTRAN, integers were present primarily to be used as array subscripts. The INteger mnemonic doesn't appear in any of the early papers or manuals.
As a side note, on the topic of features that would currently seem ‘strange’, some early languages that were intended to be programmed using teletypewriters rather than FORTRAN's Hollerith cards used half-line motions to write array subscripts as actual subscripts.
Re: Strangest Programming Language Feature?
#26It logically follows from how arrays in C works, so I don't really know if it qualifies for weird/suprising, but the old array[i] / i[array] thing is fun to show to people who haven't seen it before. The most amusingly weird thing I can think of is INTERCAL's COMEFROM: http://en.wikipedia.org/wiki/COMEFROM
Can you explain your array[i] / i[array] reference? I can't find it on Google.
> The definition of the subscript operator [] is that E1[E2] is identical to (* ((E1)+(E2))).
Since * (E1 + E2) is commutative, E1[E2] == E2[E1].
Re: Strangest Programming Language Feature?
#27It logically follows from how arrays in C works, so I don't really know if it qualifies for weird/suprising, but the old array[i] / i[array] thing is fun to show to people who haven't seen it before. The most amusingly weird thing I can think of is INTERCAL's COMEFROM: http://en.wikipedia.org/wiki/COMEFROM
Can you explain your array[i] / i[array] reference? I can't find it on Google.
It's confusing because array[i] makes sense but i[array] doesn't (how the hell can you use an array as an index on an integer?)
It works because array is a pointer to a memory address and i (or index) is an offset. array[i] will add the index to the memory address and return the value there, where as i[array] will add the memory address to the index. Since array+index == index+array, they point to the same memory and return the same value.
Re: Strangest Programming Language Feature?
#28Re: Strangest Programming Language Feature?
#29It logically follows from how arrays in C works, so I don't really know if it qualifies for weird/suprising, but the old array[i] / i[array] thing is fun to show to people who haven't seen it before. The most amusingly weird thing I can think of is INTERCAL's COMEFROM: http://en.wikipedia.org/wiki/COMEFROM
Can you explain your array[i] / i[array] reference? I can't find it on Google.
By definition, the subscript operator [] is interpreted in such a
way that ‘‘E1[E2]’’ is identical to ‘‘*((E1) + (E2))’’. Because
of the conversion rules which apply to +, if E1 is an array and
E2 an integer, then E1[E2] refers to the E2th member of E1.
Therefore, despite its asymmetric appearance, subscripting is a
commutative operation.¹
¹ Dennis M Ritchie, C Reference Manual, 1975 http://cm.bell-labs.com/cm/cs/who/dmr/cman.pdf (A revised version of this became Appendix A to K&R.)Re: Strangest Programming Language Feature?
#30Weird. or dutch.