Choking on Syntactic Sugar

Raimo Niskanen <>
Tue Mar 13 10:20:23 CET 2001


Maurice Castro wrote:
> 
> Hi All,
>         When writing a parser for Erlang we discovered an interesting
> construction in regexp.erl (line 121 in our somewhat older distribution).
> 
> reg4([$.|S]) -> {{comp_class,"\n"},S};
> reg4("[^" ++ S0) ->
>     case char_class(S0) of
>         {Cc,[$]|S1]} -> {{comp_class,Cc},S1};
>         {Cc,S} -> throw({error,{unterminated,"["}})
>     end;
> 
> It appears as if the ++ append operator has developed a new trick, it
> can be used to divide a string into 2 parts (just like Prolog).
> 
> My question is in 3 parts:
> 
>         1) is this behaviour desirable
>                 - note it is pure syntactic sugar for [$[, $^ | S0]
>         2) is this behaviour intended
>         3) is it documented

Check out 
	http://www.erlang.se/doc/doc-5.0.2/doc, 
	Link "Erlang Extensions Since 4.4",
	Section 7.8 "Literal string prefix in patterns"

/ Raimo Niskanen, Ericsson UAB, Erlang/OTP



More information about the erlang-questions mailing list