[erlang-questions] examples for erlang with joins

Zvi exta7@REDACTED
Mon Mar 9 09:40:18 CET 2009


actualy I simplified my example from mochiweb. When I wrote the message was
thinking about this:

tokenize_script(Bin, S=#decoder{offset=O}, Start) ->   
   case Bin of        
        %% Just a look-ahead, we want the end_tag separately
        <<_:O/binary, $<, $/, SS, CC, RR, II, PP, TT, _/binary>>        
                  when (SS =:= $s orelse SS =:= $S) andalso             
                          (CC =:= $c orelse CC =:= $C) andalso
                          (RR =:= $r orelse RR =:= $R) andalso
                          (II =:= $i orelse II =:= $I) andalso
                          (PP =:= $p orelse PP =:= $P) andalso
                          (TT=:= $t orelse TT =:= $T) -> ...

i.e. match ignoring case "</script" closing tag:

<<_:O/binary, $<, $/, $s^$S, $c^$C, $r^$R, $i^$I, $p^$P, $t^$T, _/binary>> 

but off-course binaries do not allow nested patterns.
Maybe special notation for matching character ignoring case. Off-course
fully going in this direction will bridge Erlang pattern matching with
regex.

In my code I usualy just convert everyting to lower case before matching,
but this is less efficient.

Zvi


Richard O'Keefe wrote:
> 
> 
> On 9 Mar 2009, at 1:04 am, Zvi wrote:
> {mochiweb has}
>>
> 
>> -define(IS_WHITESPACE(C),
>>    (C =:= $\s orelse C =:= $\t orelse C =:= $\r orelse C =:= $\n)).
>>
>> f(C) when IS_WHITESPACE(C) -> ...
> 
> Given that we have '=:=' and 'orelse' and 'length',
> it wouldn't be much of a change to Erlang to allow
> member(C, " \t\r\n") in a guard.
>>
>> I would suggest some better syntax/operator instead of "and"  
>> keyword, like:
>>
>> f(C = ($\s ^ $\t ^ $\r ^ $\n) ) -> ...
> 
> Syntax we _already_ have would be even better.
> I looked at the Mochiweb code recently.  My first reaction
> was to ask for member/2 in guards; my second reaction was
> that character classification predicates would probably be
> more to the point.
> 
> But none of this really has anything to do with joins.
> 
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
> 
> 

-- 
View this message in context: http://www.nabble.com/examples-for-erlang-with-joins-tp22394129p22409049.html
Sent from the Erlang Questions mailing list archive at Nabble.com.




More information about the erlang-questions mailing list