Forked from hkoba/from15.1 Introduction to the Message Pattern Theory.st
Created
August 1, 2020 22:43
-
-
Save tariqhamid/8988f5021ecf93728a7ebb0c5287d465 to your computer and use it in GitHub Desktop.
Examples of Messaging Pattern in Philippe Mougin's F-Script. These are excerpts from FScriptGuide, could be reached at http://macgroup.rma.ac.be/Docs/devel/F_Script_Guide.pdf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"With F-Script, the operations that apply to single objects can be applied with equal ease to | |
the processing of entire arrays." | |
"What is fun is that the same sort of element-by-element parallel processing can be obtained with any | |
kind of message!" | |
> {1,2,3,4} * {1,2,3,4} | |
{1, 4, 9, 16} | |
> {1,2,3,4} max:{-10,20,0,2} | |
{1, 20, 3, 4} | |
> {1,2,3,4, 'bar'} > {-10,20,0,2,'foo'} | |
{true, false, true, true, false} | |
> {1,2,3,4,5,6} = {-1,2,-3,4,-5,6} | |
{false, true, false, true, false, true} | |
> {1,2,3,4} between:{0,1,-5,3} and:{2,2,-2,10} | |
{true, true, false, true} | |
> {1.2, 1.8, 3.2, 4} floor | |
{1, 1, 3, 4} | |
> {'oliver', 'henry', 'bertram'} uppercaseString | |
{'OLIVER', 'HENRY', 'BERTRAM'} | |
> {1,2,3,4} * 2 | |
{2, 4, 6, 8} | |
> {1,2,3,4} between:3 and:10 | |
{false, false, true, true} | |
> {{1,2,3,4}, {'oliver', 'henry'}, {10,100}} count | |
> {{1,2,3,4}, {'oliver', 'henry'}, {10,100}} @ count | |
{4, 2, 2} | |
"The ' @' notation means that a loop is performed on the array." | |
> { { {1,2,3,4}, {'oliver', 'henry'}, {10,100} } , { {1945,1968}, {20002} } } @@ count | |
{{4, 2, 2}, {2, 1}} | |
"You can string as many @ as you want. The leftmost @ is said to be at level 1, the next @ is said to be | |
at level 2 and so on." | |
"What about arguments? Is there an equivalent special notation to force loops on arguments? Yes –in | |
the case of arguments, you have to put a @ before the argument." | |
> {'General ', 'Mr. ', 'Miss ' } @ ++ @ {'Grant', 'Smith', 'Robinson'} | |
{'General Grant', 'Mr. Smith', 'Miss Robinson'} | |
> 2 max: @ {0,1,10,20} | |
{2, 2, 10, 20} | |
"Note that when there is @ in a message-sending expression, any other loop for the same level on objects | |
of the expressions must be explicitly stated. For example:" | |
> {1,2,3} + {10,20,30} " implicit loop on the receiver and the argument (because Array does not respond to +)" | |
{11, 22, 33} | |
> {1,2,3} @ + {10,20,30} " explicit loop on the receiver -> no more implicit loop on the argument. " | |
error: argument of method "+" must be a Number or a FSBoolean | |
> {1,2,3} @ + @ {10,20,30} " explicit loop on the receiver and the argument" | |
{11, 22, 33} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> {1,2,3} @1 * @2 {10,100,1000,10000} | |
{{10,100,1000,10000}, {20,200,2000,20000}, {3,300,3000,30000}} | |
"The outer-most loop specifications can be abbreviated by omitting the 1 after @. The above command | |
and the following are thus equivalent:" | |
> {1,2,3} @ * @2 {10,100,1000,10000} | |
{{10,100,1000,10000}, {20,200,2000,20000}, {3,300,3000,30000}} | |
"The @1:@2 pattern has a standard name; it is called the outer-product." | |
> {'a1', 'a2', 'a3' } ++ {'b1', 'b2', 'b3', 'b4' } | |
{'a1','a2','a3','b1','b2','b3','b4'} | |
> {'a1','a2','a3'} @ ++ @ {'b1','b2','b3','b4'} | |
{'a1b1','a2b2','a3b3'} | |
> {'a1','a2','a3'} @1 ++ @2 {'b1','b2','b3','b4'} | |
{{'a1b1','a1b2','a1b3','a1b4'}, | |
{'a2b1','a2b2','a2b3','a2b4'}, | |
{'a3b1','a3b2','a3b3','a3b4'}} | |
> {'a1','a2','a3'} @2 ++ @1 {'b1','b2','b3','b4'} | |
{{'a1b1','a2b1','a3b1'}, | |
{'a1b2','a2b2','a3b2'}, | |
{'a1b3','a2b3','a3b3'}, | |
{'a1b4','a2b4','a3b4'}} | |
"...." | |
> {{'a11','a12','a13'},{'a21','a22','a23'}} ++ {{'b11','b12'},{'b21','b22'}} | |
{{'a11','a12','a13'}, {'a21','a22','a23'}, {'b11','b12'}, {'b21','b22'}} | |
> {{'a11','a12','a13'},{'a21','a22','a23'}} @ ++ {{'b11','b12'},{'b21','b22'}} | |
{{'a11', 'a12', 'a13', {'b11', 'b12'}, {'b21', 'b22'}}, | |
{'a21', 'a22', 'a23', {'b11', 'b12'}, {'b21', 'b22'}}} | |
> {{'a11','a12','a13'},{'a21','a22','a23'}} @@ ++ @@ {{'b11','b12'},{'b21','b22'}} | |
{{'a11b11', 'a12b12'}, {'a21b21', 'a22b22'}} | |
> {{'a11','a12','a13'},{'a21','a22','a23'}} @1@ ++ @2@ {{'b11','b12'},{'b21','b22'}} | |
{{{'a11b11', 'a12b12'}, {'a11b21', 'a12b22'}}, | |
{{'a21b11', 'a22b12'}, {'a21b21', 'a22b22'}}} | |
> {{'a11','a12','a13'},{'a21','a22','a23'}} @1@2 ++ @2@1 {{'b11','b12'},{'b21','b22'}} | |
{{{{'a11b11','a12b11','a13b11'},{'a11b12','a12b12','a13b12'}}, | |
{{'a11b21','a12b21','a13b21'},{'a11b22','a12b22','a13b22'}}}, | |
{{{'a21b11','a22b11','a23b11'},{'a21b12','a22b12','a23b12'}}, | |
{{'a21b21','a22b21','a23b21'},{'a21b22','a22b22','a23b22'}}}} | |
"Let's analyze the last example: | |
The pattern here is @1@2:@2@1. | |
This pattern has the form ij:kl where i is @1,j is @2,k is @2 and l is @1." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment