For something as simple as addition the pattern matching would gain no 
speed, but in more complex things it could, however you would not know the 
answer ahead of time for that so usually something like ETS is used to 
cache like that.

On Wednesday, September 14, 2016 at 9:15:42 PM UTC-6, Shyam Sankaran wrote:
>
> I was reading about metaprgramming in elixir where Chris explains how 
> easily elixir provides unicode support in a few lines of code through 
> pattern matching. I thought it would be a cool idea to cache functions by 
> generating code which defines the function with the previously passed 
> parameters as input and the computed value as the body of the function. 
> Next time, instead of evaluating the function, you just have to pattern 
> match !!!
>
> Lets assume a function:
>
> def add(a,b) do: a+b
>
> add(1,2)  -> evaluates 1+2 = 3 -> spawn a function that creates a function 
> : def add(1,2) do: 3 
> add(1,2) -> pattern matches with  add(1,2) -> returns 3
>
> thoughts?
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/7afc3e06-22b2-4da7-99a0-a74a862b51b7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to