Why is the syntax of Crystal macros for iteration different from the rest of Crystal

From the Ruby world, I immediately understood why Crystal decided not to use the method for. But then I was surprised to see that Crystal implements a method forfor macros. I was even more surprised to find that macros do not allow an enumerable ( .eachetc.) syntax (i.e., is {% ["one", "two", "three"].each do |value| %}not a valid macro syntax).

Is there a logical reason for this difference in syntax? Perhaps the answer is simply “because the developers decided that the macro syntax looks like x and the non-macro syntax looks like y,” but I assume there is something else in it (arbitrary syntax inconsistency seems to be a drawback).

Thank!

+4
source share
1

, foo.bar do |arg| ... end, |arg|, %}, . , , ( ). for - , , , , ( ).

, each , while until? , for , . ... , run .

, , each, each_with_index .., , , for . , , .

+6

Source: https://habr.com/ru/post/1691553/


All Articles