[erlang-bugs] error in R12B Efficiency Guide

Zvi <>
Fri Jan 25 02:10:02 CET 2008


Slightly OT:

Does Erlang have some built-in mechanism for testing, if expression matching
the pattern?
Something like this:

-module(is_match).
-compile([export_all]).

-define(IS_MATCH(Pattern,Expr), ((fun(Pattern) -> true; (_) -> false
end)(Expr))).

test() ->	{ 
	  ?IS_MATCH([_,$b,_], "abc"),
	  ?IS_MATCH("xab"++_, "waba"),
	  ?IS_MATCH({_,_}, {1,2}) 
	}.

Erlang (BEAM) emulator version 5.6 [smp:32] [async-threads:0]

Eshell V5.6  (abort with ^G)

1> c(is_match).             
{ok,is_match}
2> is_match:test().         
{true,false,true}


Zvi

-- 
View this message in context: http://www.nabble.com/error-in-R12B-Efficiency-Guide-tp15069805p15079082.html
Sent from the Erlang Bugs mailing list archive at Nabble.com.




More information about the erlang-bugs mailing list