Added more examples
This commit is contained in:
parent
d53d035312
commit
2cfeaf7b73
6 changed files with 721 additions and 636 deletions
|
@ -21,16 +21,40 @@ begindiv(intro)
|
||||||
|
|
||||||
UPDATE: [Nicholas Sterling had discovered a way to implement anonymous functions](http://nicholassterling.wordpress.com/2012/03/30/a-zsh-map-function/)
|
UPDATE: [Nicholas Sterling had discovered a way to implement anonymous functions](http://nicholassterling.wordpress.com/2012/03/30/a-zsh-map-function/)
|
||||||
and [Arash Rouhani has made a github repo which make install easier and added some tests](https://github.com/Tarrasch/zsh_functional).
|
and [Arash Rouhani has made a github repo which make install easier and added some tests](https://github.com/Tarrasch/zsh_functional).
|
||||||
|
Thanks to both of you!
|
||||||
|
|
||||||
With this last version you should use `map` if you use external function.
|
With this last version you should use `map` if you use external function.
|
||||||
`mapl` to use lambda function. And `mapa` for arithmetic operations.
|
`mapl` to use lambda function. And `mapa` for arithmetic operations.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
<code class="zsh">
|
<code class="zsh">
|
||||||
~ mapl 'result $1' $(mapa '$1+5' $(mapa '$1*2' {1..3}))
|
$ filterl 'echo $1|grep a >/dev/null' ab cd ef ada
|
||||||
|
ab
|
||||||
|
ada
|
||||||
|
|
||||||
|
$ folda '$1+$2' {1..5}
|
||||||
|
15
|
||||||
|
|
||||||
|
$ folda '$1*$2' {1..20}
|
||||||
|
2432902008176640000
|
||||||
|
|
||||||
|
$ mapl 'X $1:t Y' ~/.zsh/functional/src/*
|
||||||
|
X each Y
|
||||||
|
X filter Y
|
||||||
|
X fold Y
|
||||||
|
X map Y
|
||||||
|
|
||||||
|
$ mapa '$1*2' {1..3}
|
||||||
|
2
|
||||||
|
4
|
||||||
|
6
|
||||||
|
|
||||||
|
$ mapl 'result $1' $(mapa '$1+5' $(mapa '$1*2' {1..3}))
|
||||||
result 7
|
result 7
|
||||||
result 9
|
result 9
|
||||||
result 11
|
result 11
|
||||||
|
|
||||||
</code>
|
</code>
|
||||||
|
|
||||||
%tldr some simple implementation of higher order function for zsh.
|
%tldr some simple implementation of higher order function for zsh.
|
||||||
|
@ -121,7 +145,9 @@ Just believe me that the functional programming approach is superior.
|
||||||
Actually I lack the lambda operator.
|
Actually I lack the lambda operator.
|
||||||
If someone has an idea on how to create anonymous functions, just tell me, thanks.
|
If someone has an idea on how to create anonymous functions, just tell me, thanks.
|
||||||
|
|
||||||
Here is the source code:
|
Here is the (first version[^1]) source code:
|
||||||
|
|
||||||
|
[^1]: As stated in the intro, if you want to install it, just go [there](https://github.com/Tarrasch/zsh_functional).
|
||||||
|
|
||||||
<code class="zsh" file="functional.sh">
|
<code class="zsh" file="functional.sh">
|
||||||
#!/usr/bin/env zsh
|
#!/usr/bin/env zsh
|
||||||
|
|
|
@ -21,6 +21,8 @@ begindiv(intro)
|
||||||
|
|
||||||
UPDATE: [Nicholas Sterling a découvert un moyen de faire des fonctions anonymes](http://nicholassterling.wordpress.com/2012/03/30/a-zsh-map-function/)
|
UPDATE: [Nicholas Sterling a découvert un moyen de faire des fonctions anonymes](http://nicholassterling.wordpress.com/2012/03/30/a-zsh-map-function/)
|
||||||
et [Arash Rouhani a créé un repository sur github qui simplifie l'installation](https://github.com/Tarrasch/zsh_functional).
|
et [Arash Rouhani a créé un repository sur github qui simplifie l'installation](https://github.com/Tarrasch/zsh_functional).
|
||||||
|
Merci à vous deux!
|
||||||
|
|
||||||
Avec cette dernière version vous pouvez utiliser `map` si vous utilisez
|
Avec cette dernière version vous pouvez utiliser `map` si vous utilisez
|
||||||
des fonctions déclarées. `mapl` pour les fonctions anonymes
|
des fonctions déclarées. `mapl` pour les fonctions anonymes
|
||||||
et `mapa` pour les fonctions arithmétiques.
|
et `mapa` pour les fonctions arithmétiques.
|
||||||
|
@ -28,10 +30,32 @@ et `mapa` pour les fonctions arithmétiques.
|
||||||
Exemple :
|
Exemple :
|
||||||
|
|
||||||
<code class="zsh">
|
<code class="zsh">
|
||||||
~ mapl 'result $1' $(mapa '$1+5' $(mapa '$1*2' {1..3}))
|
$ filterl 'echo $1|grep a >/dev/null' ab cd ef ada
|
||||||
|
ab
|
||||||
|
ada
|
||||||
|
|
||||||
|
$ folda '$1+$2' {1..5}
|
||||||
|
15
|
||||||
|
|
||||||
|
$ folda '$1*$2' {1..20}
|
||||||
|
2432902008176640000
|
||||||
|
|
||||||
|
$ mapl 'X $1:t Y' ~/.zsh/functional/src/*
|
||||||
|
X each Y
|
||||||
|
X filter Y
|
||||||
|
X fold Y
|
||||||
|
X map Y
|
||||||
|
|
||||||
|
$ mapa '$1*2' {1..3}
|
||||||
|
2
|
||||||
|
4
|
||||||
|
6
|
||||||
|
|
||||||
|
$ mapl 'result $1' $(mapa '$1+5' $(mapa '$1*2' {1..3}))
|
||||||
result 7
|
result 7
|
||||||
result 9
|
result 9
|
||||||
result 11
|
result 11
|
||||||
|
|
||||||
</code>
|
</code>
|
||||||
|
|
||||||
%tlal des fonctions d'ordres supérieurs en zsh.
|
%tlal des fonctions d'ordres supérieurs en zsh.
|
||||||
|
@ -124,7 +148,9 @@ Je vous demande simplement de me croire quand je dis que l'approche fonctionnell
|
||||||
Actuellement il me manque une fonction lambda, si quelqu'un à une idée elle serait la bienvenue.
|
Actuellement il me manque une fonction lambda, si quelqu'un à une idée elle serait la bienvenue.
|
||||||
Je ne sais pas encore comment créer facilement des fonctions anonymes.
|
Je ne sais pas encore comment créer facilement des fonctions anonymes.
|
||||||
|
|
||||||
Voici le code source :
|
Voici le code source (de la première version[^1]) :
|
||||||
|
|
||||||
|
[^1]: Comme précisé dans l'introduction, si vous voulez l'installez allez plutôt voir dans ce [repository](https://github.com/Tarrasch/zsh_functional).
|
||||||
|
|
||||||
<code class="zsh" file="functional.sh">
|
<code class="zsh" file="functional.sh">
|
||||||
#!/usr/bin/env zsh
|
#!/usr/bin/env zsh
|
||||||
|
|
|
@ -22,12 +22,16 @@ begindiv(intro)
|
||||||
|
|
||||||
en: UPDATE: [Nicholas Sterling had discovered a way to implement anonymous functions](http://nicholassterling.wordpress.com/2012/03/30/a-zsh-map-function/)
|
en: UPDATE: [Nicholas Sterling had discovered a way to implement anonymous functions](http://nicholassterling.wordpress.com/2012/03/30/a-zsh-map-function/)
|
||||||
en: and [Arash Rouhani has made a github repo which make install easier and added some tests](https://github.com/Tarrasch/zsh_functional).
|
en: and [Arash Rouhani has made a github repo which make install easier and added some tests](https://github.com/Tarrasch/zsh_functional).
|
||||||
|
en: Thanks to both of you!
|
||||||
|
en:
|
||||||
en: With this last version you should use `map` if you use external function.
|
en: With this last version you should use `map` if you use external function.
|
||||||
en: `mapl` to use lambda function. And `mapa` for arithmetic operations.
|
en: `mapl` to use lambda function. And `mapa` for arithmetic operations.
|
||||||
en:
|
en:
|
||||||
en: Example:
|
en: Example:
|
||||||
fr: UPDATE: [Nicholas Sterling a découvert un moyen de faire des fonctions anonymes](http://nicholassterling.wordpress.com/2012/03/30/a-zsh-map-function/)
|
fr: UPDATE: [Nicholas Sterling a découvert un moyen de faire des fonctions anonymes](http://nicholassterling.wordpress.com/2012/03/30/a-zsh-map-function/)
|
||||||
fr: et [Arash Rouhani a créé un repository sur github qui simplifie l'installation](https://github.com/Tarrasch/zsh_functional).
|
fr: et [Arash Rouhani a créé un repository sur github qui simplifie l'installation](https://github.com/Tarrasch/zsh_functional).
|
||||||
|
fr: Merci à vous deux!
|
||||||
|
fr:
|
||||||
fr: Avec cette dernière version vous pouvez utiliser `map` si vous utilisez
|
fr: Avec cette dernière version vous pouvez utiliser `map` si vous utilisez
|
||||||
fr: des fonctions déclarées. `mapl` pour les fonctions anonymes
|
fr: des fonctions déclarées. `mapl` pour les fonctions anonymes
|
||||||
fr: et `mapa` pour les fonctions arithmétiques.
|
fr: et `mapa` pour les fonctions arithmétiques.
|
||||||
|
@ -35,10 +39,32 @@ fr:
|
||||||
fr: Exemple :
|
fr: Exemple :
|
||||||
|
|
||||||
<code class="zsh">
|
<code class="zsh">
|
||||||
~ mapl 'result $1' $(mapa '$1+5' $(mapa '$1*2' {1..3}))
|
$ filterl 'echo $1|grep a >/dev/null' ab cd ef ada
|
||||||
|
ab
|
||||||
|
ada
|
||||||
|
|
||||||
|
$ folda '$1+$2' {1..5}
|
||||||
|
15
|
||||||
|
|
||||||
|
$ folda '$1*$2' {1..20}
|
||||||
|
2432902008176640000
|
||||||
|
|
||||||
|
$ mapl 'X $1:t Y' ~/.zsh/functional/src/*
|
||||||
|
X each Y
|
||||||
|
X filter Y
|
||||||
|
X fold Y
|
||||||
|
X map Y
|
||||||
|
|
||||||
|
$ mapa '$1*2' {1..3}
|
||||||
|
2
|
||||||
|
4
|
||||||
|
6
|
||||||
|
|
||||||
|
$ mapl 'result $1' $(mapa '$1+5' $(mapa '$1*2' {1..3}))
|
||||||
result 7
|
result 7
|
||||||
result 9
|
result 9
|
||||||
result 11
|
result 11
|
||||||
|
|
||||||
</code>
|
</code>
|
||||||
|
|
||||||
en: %tldr some simple implementation of higher order function for zsh.
|
en: %tldr some simple implementation of higher order function for zsh.
|
||||||
|
@ -153,8 +179,11 @@ fr: Je ne sais pas encore comment créer facilement des fonctions anonymes.
|
||||||
en: Actually I lack the lambda operator.
|
en: Actually I lack the lambda operator.
|
||||||
en: If someone has an idea on how to create anonymous functions, just tell me, thanks.
|
en: If someone has an idea on how to create anonymous functions, just tell me, thanks.
|
||||||
|
|
||||||
en: Here is the source code:
|
en: Here is the (first version[^1]) source code:
|
||||||
fr: Voici le code source :
|
fr: Voici le code source (de la première version[^1]) :
|
||||||
|
|
||||||
|
en: [^1]: As stated in the intro, if you want to install it, just go [there](https://github.com/Tarrasch/zsh_functional).
|
||||||
|
fr: [^1]: Comme précisé dans l'introduction, si vous voulez l'installez allez plutôt voir dans ce [repository](https://github.com/Tarrasch/zsh_functional).
|
||||||
|
|
||||||
<code class="zsh" file="functional.sh">
|
<code class="zsh" file="functional.sh">
|
||||||
#!/usr/bin/env zsh
|
#!/usr/bin/env zsh
|
||||||
|
|
|
@ -217,18 +217,22 @@ Before telling you why you should learn Haskell and use yesod, I will talk about
|
||||||
|
|
||||||
<p>UPDATE: <a href="http://nicholassterling.wordpress.com/2012/03/30/a-zsh-map-function/">Nicholas Sterling had discovered a way to implement anonymous functions</a>
|
<p>UPDATE: <a href="http://nicholassterling.wordpress.com/2012/03/30/a-zsh-map-function/">Nicholas Sterling had discovered a way to implement anonymous functions</a>
|
||||||
and <a href="https://github.com/Tarrasch/zsh_functional">Arash Rouhani has made a github repo which make install easier and added some tests</a>.
|
and <a href="https://github.com/Tarrasch/zsh_functional">Arash Rouhani has made a github repo which make install easier and added some tests</a>.
|
||||||
With this last version you should use <code>map</code> if you use external function.
|
Thanks to both of you!</p>
|
||||||
|
|
||||||
|
<p>With this last version you should use <code>map</code> if you use external function.
|
||||||
<code>mapl</code> to use lambda function. And <code>mapa</code> for arithmetic operations.</p>
|
<code>mapl</code> to use lambda function. And <code>mapa</code> for arithmetic operations.</p>
|
||||||
|
|
||||||
<p>Example: </p>
|
<p>Example: </p>
|
||||||
|
|
||||||
<pre><code class="zsh">~ mapl 'result $1' $(mapa '$1+5' $(mapa '$1*2' {1..3}))
|
<pre><code class="zsh">$ filterl 'echo $1|grep a &gt;/dev/null' ab cd ef ada
|
||||||
result 7
|
ab
|
||||||
result 9
|
ada
|
||||||
result 11
|
|
||||||
</code></pre>
|
|
||||||
|
|
||||||
<p><span class="sc"></span></p></div></p></content>
|
$ folda '$1+$2' {1..5}
|
||||||
|
15
|
||||||
|
|
||||||
|
$ folda '$1*$2' {1..20}
|
||||||
|
...</code></pre></div></p></content>
|
||||||
</entry>
|
</entry>
|
||||||
<entry>
|
<entry>
|
||||||
<id>tag:yannesposito.com,2011-09-28:/Scratch/en/blog/programming-language-experience/</id>
|
<id>tag:yannesposito.com,2011-09-28:/Scratch/en/blog/programming-language-experience/</id>
|
||||||
|
|
|
@ -212,19 +212,19 @@ Avant de vous dire pourquoi vous devriez aussi le considérer, je préf&
|
||||||
|
|
||||||
<p>UPDATE: <a href="http://nicholassterling.wordpress.com/2012/03/30/a-zsh-map-function/">Nicholas Sterling a découvert un moyen de faire des fonctions anonymes</a>
|
<p>UPDATE: <a href="http://nicholassterling.wordpress.com/2012/03/30/a-zsh-map-function/">Nicholas Sterling a découvert un moyen de faire des fonctions anonymes</a>
|
||||||
et <a href="https://github.com/Tarrasch/zsh_functional">Arash Rouhani a créé un repository sur github qui simplifie l&rsquo;installation</a>.
|
et <a href="https://github.com/Tarrasch/zsh_functional">Arash Rouhani a créé un repository sur github qui simplifie l&rsquo;installation</a>.
|
||||||
Avec cette dernière version vous pouvez utiliser <code>map</code> si vous utilisez
|
Merci à vous deux!</p>
|
||||||
|
|
||||||
|
<p>Avec cette dernière version vous pouvez utiliser <code>map</code> si vous utilisez
|
||||||
des fonctions déclarées. <code>mapl</code> pour les fonctions anonymes
|
des fonctions déclarées. <code>mapl</code> pour les fonctions anonymes
|
||||||
et <code>mapa</code> pour les fonctions arithmétiques.</p>
|
et <code>mapa</code> pour les fonctions arithmétiques.</p>
|
||||||
|
|
||||||
<p>Exemple&nbsp;:</p>
|
<p>Exemple&nbsp;:</p>
|
||||||
|
|
||||||
<pre><code class="zsh">~ mapl 'result $1' $(mapa '$1+5' $(mapa '$1*2' {1..3}))
|
<pre><code class="zsh">$ filterl 'echo $1|grep a &gt;/dev/null' ab cd ef ada
|
||||||
result 7
|
ab
|
||||||
result 9
|
ada
|
||||||
result 11
|
|
||||||
</code></pre>
|
|
||||||
|
|
||||||
<p>...</p></div></p></content>
|
$ folda '$1+...</code></pre></div></p></content>
|
||||||
</entry>
|
</entry>
|
||||||
<entry>
|
<entry>
|
||||||
<id>tag:yannesposito.com,2011-09-28:/Scratch/fr/blog/programming-language-experience/</id>
|
<id>tag:yannesposito.com,2011-09-28:/Scratch/fr/blog/programming-language-experience/</id>
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue