Tags » Elixir

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。


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


The Elixir of Bliss

The Elixir of Bliss

Define for me

this formula you call life

extract for me

this phenomenon you call joy

derive for me

the essence of these souls we twist… 12 more words


The Lemonade Diet, Day One

Today is the last day of June 2015. Sunshine, blue skies and a green-hillside dotted with various sizes of evergreens are visible from my living-room office, somewhat miraculous for this time of year in my Tennessee Valley mountaintop getaway. 1,193 more words

Mind Set

Beauty Protector - Protect and Oil

I am absolutely blown away by this little product…my Birchbox pals rave reviews were definitely justified!

After washing my hair yesterday I popped 5-6 drops of this onto my hands (I thought I’d double the recommended amount as I have lots of hair) and worked it through my damp hair from the roots to the tips. 217 more words

Fashion & Beauty

Caviar Repairx Lengthening Elixir - Alterna

Olá pessoal…

Estamos sumidas daqui né?? Esses meses foram meio corridos para mim, sem tempo para criar posts e afins… Masss hoje venho aqui para contar de uma descoberta durante a minha viagem que teria me arrependido demais caso não tivesse comprado. 934 more words


Music Product Reviews - Things I will be Taking With Me on the Road

Well it won’t be long before I go on my Cross Canada Tour. Things are coming along great as I have 6 shows in 3 different cities. 271 more words


The Fantastic Berry Bombastic 'I Love My Gut' Smoothie.

For me, food should be functional…which is a strange thing to say, but in this day and age..food is a far cry from what it was intended to be. 710 more words

Musings & Reflections