Meetup

6 views
Skip to first unread message

Christian Jacobsen

unread,
Apr 25, 2012, 9:07:40 AM4/25/12
to functional-programming-sthlm
There's two seats available for tonight's meetup. Get your ticket
here: http://www.eventbrite.com/myevents?org_id=2039657 !

Christian Jacobsen

unread,
Apr 25, 2012, 9:13:50 AM4/25/12
to functional-programming-sthlm
And the correct url is of course: http://april25funcprogsthlm-autohome.eventbrite.com/

On Apr 25, 3:07 pm, Christian Jacobsen <christian.jacob...@jayway.com>
wrote:
Message has been deleted

Djui

unread,
Apr 25, 2012, 5:45:30 PM4/25/12
to functional-pro...@googlegroups.com
Two Erlang solutions to the red-green layout example tonight: (a) is 
shortest, (b) is a bit more flexible/readable: 

-module(layout).                                                        
-export([ run/0 ]).                                                     
                                                                        
run() ->                                                                
  L = [r,r,g,g,r,g,g,g,r,r,g,r],                                        
  F = [r,r,[g,g],r,[g,g],[g],r,r,[g],r],                                
  F = layout(L).                                                        
                                                                        
layout(L) -> lists:reverse(layout(L, {0,[]}, [])).                      
                                                                        
layout([r|T], {0,_}, R) -> layout(T, {0,  []   }, [r  |R]);             
layout([r|T], {_,B}, R) -> layout(T, {0,  []   }, [r,B|R]);             
layout([g|T], {2,B}, R) -> layout(T, {1,  [g]  }, [B  |R]);             
layout([g|T], {N,B}, R) -> layout(T, {N+1,[g|B]},      R );             
layout([],    {0,_}, R) -> R;                                           
layout([],    {_,B}, R) -> [B|R].                                       
                                                                        
                                                                        
                                                                        
                                                                        
-module(layout).                                                        
-export([ run/0 ]).                                                     
                                                                        
run() ->                                                                
  L = [r,r,g,g,r,g,g,g,r,r,g,r],                                        
  F = [r,r,[g,g],r,[g,g],[g],r,r,[g],r],                                
  F = layout(L).                                                        
                                                                        
layout(L) -> lists:reverse(layout(L, new(), [])).                       
                                                                        
layout([r|T],       B, R) -> layout(T, new(),          [r|flush(B, R)]);
layout([g|T], {2,_}=B, R) -> layout(T, push(g, new()),    flush(B, R)); 
layout([g|T],       B, R) -> layout(T, push(g, B),                 R);  
layout([],          B, R) ->                              flush(B, R).  
                                                                        
new() -> {0,[]}.                                                        
                                                                        
push(E, {N,B}) -> {N+1, [E|B]}.                                         
                                                                        
flush(R, {0,_}) -> R;                                                   
flush(R, {_,B}) -> [B|R].                                               
Reply all
Reply to author
Forward
0 new messages