2

so... self-referential arrays.
do you know any languages that have them? thoughts?
what I mean is (in pseudo-c# syntax) :
string[] r = new string[]{ "1", "2", self[0] + " and " + self[1] };

which would result in an array with items:
1
2
1 and 2

Comments
  • 2
    No I do not. And I find it silly.
  • 7
    Nope, this would require r containing the indexes before r has been allocated the indexes to do a lookup against 😅

    Quantum arrays anyone?
  • 9
    There are things which should not exist imho...
  • 3
    Any use for this which can't be done in other better ways?
  • 1
    It's probably a bad idea because it masks multi step initialization which will take more time and resources than normal one.
  • 1
    I still don't understand the use case,
    Does "1" and "2" not come from variables?

    Are you literally trying to make a stupidity long 1 liner like:

    x = [(4 * 5), (747.666 * 12), (self[0] + self[1])]

    Wouldn't all these values still be stored in a variable of some kind somewhere resulting in:

    a = 4 * 5
    b = 747.666 * 12
    x = [a, b, ( a + b ) ]

    Simplified for argument sake!

    are you really anti-variable?
  • 0
    @C0D4 much better!
  • 0
    string[] r = new string[]{ "1", "2", null};
    r[2] = r[0] + " and " + r[1];
  • 1
Add Comment