Comment by WalterBright
3 years ago
> Expressions in APL are evaluated right-to-left
I find it more natural to evaluate left-to-right, because that's the order we read things in. For example, to read a file and sort its lines (in D):
auto sortedLines = File("file.txt").byLineCopy.array.sort;
Isn't the assignment operator evaluated last, though? I don't know of any language that would support "true" left to right evaluation, though it would be neat! I suppose it would look like:
File("file.txt").byLineCopy.array.sort = sortedLines;
...which by first blush, seems bananas, but if you were to read it as English, would make sense: "Load the file 'file.txt' into an array of lines, sort them, then assign it to sortedLines"
> Isn't the assignment operator evaluated last, though?
Yes. Though one could use the . operator and a sink to make it completely left-to-right.
It's the symmetry of the '=' symbol which creates the difficulty. Replace it by an arrow in the direction of the assignment and it doesn't look strange anymore. File("file.txt").byLineCopy.array.sort -> sortedLines;
Especially if you add the |> operator (from Erlang I believe) to 'pipe' the data.
File("file.txt") |> readlines |> sort -> sortedLines;
I think it would be roughly like this:
Anyway I wouldn't want to munge strings in it, but that is not really its niche. Right-to-left can be nicer in different contexts, one is not really better or worse than the other.