Tags » Pattern Matching

Pattern Matching in Elixir

Pattern Matching

Elixir是一個廣義的functional programming language,他是Ruby和Erlang結婚生出來的小孩。Elixir是個很有趣的語言,這裡簡單介紹Elixir的Pattern Matching。Elixir很有趣的一點是他沒有assignment operator。在Elixir的程式碼可以看到=,在一般人熟悉的語言裡,=通常是assignment operator;在Elixir稱為match operator。

在iex或者程式碼裡面執行下列程式,在Elixir都不會看到到錯誤訊息。

a = 2
2 = a

第一行看起來或許跟一般語言的assignment沒有差別,經過match運算之後,Elixir會把2這個整數存到a這個變數;但是第二行在一般語言就會收到錯誤訊息,因為一般assignment語法檢查left-hand如果是一般data的時候,看到=就會產生syntax error。但是,在Elixir只是match operator的判斷,在第二行因為a這個參數在第一行運算後內容是2,因此match operator執行成功。

如果我們把程式改寫成下列這樣,在第二行就會收到第三行註解寫的MatchError的錯誤,而且訊息會說no match of right hand side value: 1。 206 more words

Elixir

The RegEx.

hey, I am Aishwary Tiwari. I am going to post my findings on regular expressions. At first Regular Expressions looked weird but when I got to know them, i found out that it is an awesome an efficient tool to represent strings and match patterns. 496 more words

How To Use Regular Expression

DJ Durkin Pattern Matching Scheme: 3 Buzz Mable

Nick Saban has been the preeminent defensive coach in college football for the better part  of 2 decades. The hallmark of his defense has been the vast array of pattern matching schemes they have available to deal with any situation they may face defensively. 615 more words

NCAA

Naive Pattern Searching

Problem: Searching for a Pattern in a given Text

Solution:


#include<stdio.h>
#include<string.h>

void pattern_matching(char *,char *);
int main()
{
char s1[]="AABAACAADAABAAABAA";
char s2[]="AABA";

pattern_matching(s1,s2);
return 0;
}

void pattern_matching(char *s1,char *s2)
{
int len1,len2,i,j,count;
len1=strlen(s1);
len2=strlen(s2);

for(i=0;i<=len1-len2;i++)
{
count=0;
for(j=0;j<len2;j++)
{
if(s1==s2[j])
count++;
else
break;
}
if(count==len2)
{
printf("substring found at index %d\n",i);
}
}
}

Algorithm

The Chess Match: Detroit Lions' Pass Defense Versus Green Bay

The Green Bay Packers and Detroit Lions were two of the top teams in the NFC last season. The Packers were led by their dynamic offense featuring MVP Aaron Rodgers and play caller Mike McCarthy. 1,393 more words

Offense

People in architectural drawings, part 6; conclusion

By Gordon Rugg

This article is the last in a short series about finding out what people really want. I’ve explored that topic via discussion of idealised dream buildings, to see what regularities emerge and what insights they provide into people’s dreams and desires. 1,705 more words

Design

Tartan Twirls

Another party, another dress. This time it was our work’s summer social, held at The Caves in Edinburgh. It was originally billed as Scottish-themed, but apart from a couple of kilts, a pair of tartan trousers, my dress and a few Scottish accents, it was very much a normal social. 562 more words

Dressmaking