On Wednesday, 21 March 2018 at 20:07:09 UTC, tipdbmp wrote:
D's type declarations seem to read right to left.


int an_integer;

int[10] an_array_of_10_integers;
int[10]* a_pointer_to_an_array_of_10_integers = &an_array_of_10_integers;

int*[10] an_array_of_10_pointers_to_integers;
int*[10]* a_pointer_to_an_array_of_10_pointers_to_integers = &an_array_of_10_pointers_to_integers;

int[3][2] an_array_of_2_arrays_of_3_integers;
int[string] a_hashtable_with_string_keys_and_integer_values;

int[3][string][2] an_array_of_2_hashtables_with_string_keys_and_array_of_3_integers_values;

int function(float) a_pointer_to_a_function_that_takes_a_float_and_returns_an_integer; int function(float)[10] an_array_of_10_functions_that_take_floats_and_return_integers;


I think this is a big improvement over C's "spiral" way of reading types: http://www.unixwiz.net/techtips/reading-cdecl.html
I guess it could've been left to right, but... it's okay.

The way I see it, English "of" flips its operands backwards compared to English's [adjective][noun] syntax:

int an_integer;
int* an_integer_pointer;
int[] an_integer_array;
int[3]* an_integer_array(length 3)_pointer;

But granted, in English, "of" is more scalable than [adjective][noun].

Reply via email to