Added more examples

This commit is contained in:
Yann Esposito (Yogsototh) 2012-07-10 00:30:25 +02:00
parent d53d035312
commit 2cfeaf7b73
6 changed files with 721 additions and 636 deletions

View file

@ -19,18 +19,42 @@ blogimage("main.jpg","Title image")
begindiv(intro) 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

View file

@ -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

View file

@ -20,14 +20,18 @@ blogimage("main.jpg","Title image")
begindiv(intro) 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

View file

@ -215,20 +215,24 @@ Before telling you why you should learn Haskell and use yesod, I will talk about
&lt;div class="intro"&gt; &lt;div class="intro"&gt;
&lt;p&gt;UPDATE: &lt;a href="http://nicholassterling.wordpress.com/2012/03/30/a-zsh-map-function/"&gt;Nicholas Sterling had discovered a way to implement anonymous functions&lt;/a&gt; &lt;p&gt;UPDATE: &lt;a href="http://nicholassterling.wordpress.com/2012/03/30/a-zsh-map-function/"&gt;Nicholas Sterling had discovered a way to implement anonymous functions&lt;/a&gt;
and &lt;a href="https://github.com/Tarrasch/zsh_functional"&gt;Arash Rouhani has made a github repo which make install easier and added some tests&lt;/a&gt;. and &lt;a href="https://github.com/Tarrasch/zsh_functional"&gt;Arash Rouhani has made a github repo which make install easier and added some tests&lt;/a&gt;.
With this last version you should use &lt;code&gt;map&lt;/code&gt; if you use external function. Thanks to both of you!&lt;/p&gt;
&lt;p&gt;With this last version you should use &lt;code&gt;map&lt;/code&gt; if you use external function.
&lt;code&gt;mapl&lt;/code&gt; to use lambda function. And &lt;code&gt;mapa&lt;/code&gt; for arithmetic operations.&lt;/p&gt; &lt;code&gt;mapl&lt;/code&gt; to use lambda function. And &lt;code&gt;mapa&lt;/code&gt; for arithmetic operations.&lt;/p&gt;
&lt;p&gt;Example: &lt;/p&gt; &lt;p&gt;Example: &lt;/p&gt;
&lt;pre&gt;&lt;code class="zsh"&gt;~ mapl 'result $1' $(mapa '$1+5' $(mapa '$1*2' {1..3})) &lt;pre&gt;&lt;code class="zsh"&gt;$ filterl 'echo $1|grep a &amp;gt;/dev/null' ab cd ef ada
result 7 ab
result 9 ada
result 11
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;span class="sc"&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/p&gt;</content> $ folda '$1+$2' {1..5}
15
$ folda '$1*$2' {1..20}
...&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;</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>

View file

@ -212,19 +212,19 @@ Avant de vous dire pourquoi vous devriez aussi le consid&#233;rer, je pr&#233;f&
&lt;p&gt;UPDATE: &lt;a href="http://nicholassterling.wordpress.com/2012/03/30/a-zsh-map-function/"&gt;Nicholas Sterling a d&#233;couvert un moyen de faire des fonctions anonymes&lt;/a&gt; &lt;p&gt;UPDATE: &lt;a href="http://nicholassterling.wordpress.com/2012/03/30/a-zsh-map-function/"&gt;Nicholas Sterling a d&#233;couvert un moyen de faire des fonctions anonymes&lt;/a&gt;
et &lt;a href="https://github.com/Tarrasch/zsh_functional"&gt;Arash Rouhani a cr&#233;&#233; un repository sur github qui simplifie l&amp;rsquo;installation&lt;/a&gt;. et &lt;a href="https://github.com/Tarrasch/zsh_functional"&gt;Arash Rouhani a cr&#233;&#233; un repository sur github qui simplifie l&amp;rsquo;installation&lt;/a&gt;.
Avec cette derni&#232;re version vous pouvez utiliser &lt;code&gt;map&lt;/code&gt; si vous utilisez Merci &#224; vous deux!&lt;/p&gt;
&lt;p&gt;Avec cette derni&#232;re version vous pouvez utiliser &lt;code&gt;map&lt;/code&gt; si vous utilisez
des fonctions d&#233;clar&#233;es. &lt;code&gt;mapl&lt;/code&gt; pour les fonctions anonymes des fonctions d&#233;clar&#233;es. &lt;code&gt;mapl&lt;/code&gt; pour les fonctions anonymes
et &lt;code&gt;mapa&lt;/code&gt; pour les fonctions arithm&#233;tiques.&lt;/p&gt; et &lt;code&gt;mapa&lt;/code&gt; pour les fonctions arithm&#233;tiques.&lt;/p&gt;
&lt;p&gt;Exemple&amp;nbsp;:&lt;/p&gt; &lt;p&gt;Exemple&amp;nbsp;:&lt;/p&gt;
&lt;pre&gt;&lt;code class="zsh"&gt;~ mapl 'result $1' $(mapa '$1+5' $(mapa '$1*2' {1..3})) &lt;pre&gt;&lt;code class="zsh"&gt;$ filterl 'echo $1|grep a &amp;gt;/dev/null' ab cd ef ada
result 7 ab
result 9 ada
result 11
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;...&lt;/p&gt;&lt;/div&gt;&lt;/p&gt;</content> $ folda '$1+...&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;</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