문제

Some languages have a . operator for string concatenation. The oldest language I could find that supports it is Perl. Was Perl the first to use it? Why was it chosen?

도움이 되었습니까?

해결책

If you want to stick with a single non-alphanumeric non-whitespace ASCII character for operators, there really aren't that many. I can only see a couple of alternative choices: !, ~, #, ,, and $. Of those, only . and , can be reached without on a US keyboard, # is the comment character. Comma makes kind of sense, but it is already used for a different purpose in C and C-like languages, with which a lot of Perl programmers would also be familiar, and so has the same meaning in Perl.

This leaves you only with the dot. Note that a middle dot (·) is used in maths to denote function composition (and Haskell uses the ASCII dot as an approximation for that), which can be kinda-sorta related to concatenation.

There is, in fact, no standard operator symbol for concatenation in maths, some suggestions are the double plus (Haskell uses ++ for concatenation) or the frown .

Some languages use + for concatenation, which is a terrible choice, because concatenation lacks several of the properties that we normally associate with an addition-like operation. Most importantly, concatenation is noncommutative.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 softwareengineering.stackexchange
scroll top