++ is a macro. It would originally expand (++ "abcd" rest) to(cons 97 (cons 98 (cons 99 (cons 100 rest))) which is correct, quite reasonable and also allowed it to be used in patterns. However there was one serious problem with this, if the literal string was long then it would really slow the compiler down. A user was getting compile times of 5-10 mins for a reasonably sized file but with much appending of strings.
So that expansion went. Which was a shame because it is practical to use in patterns. It now expands to (call 'erlang '++ "abcd" rest). I have two suggestions to allow it in patterns, both hacky:
- Allow the call to erlang:++ expansion in patterns and at compile time expand it to cons. This would work even if it does add a special case.
- Do the expansion using cons if the literal string is "short". This would work as well and probably be enough to catch the pattern cases, but you wouldn't be sure.
So both feel a bit hacky and I don't know which one, if any, to use.
A third solutions would be to have a different macro which always expands to the cons version. Or a fourth alternative have ++ as a special form and do the expansion at compile time. These also feel hacky.
Anyway, food for thought,
Robert