-
Notifications
You must be signed in to change notification settings - Fork 0
Home
thautwarm edited this page Aug 29, 2017
·
11 revisions
Welcome to the flowpython wiki!
Here are some tutorials about Flowpython.
-
where
>> where = 1 >> where += where where: where += 1 >> where >> 3
from math import pi r = 1 # the radius h = 10 # the height S = (2*S_top + S_side) where: S_top = pi*r**2 S_side = C * h where: C = 2*pi*r
-
lambda
- format
lambda x: f(x) <=> .x -> f(x) <=> as-with x def f(x)
- curry
.x -> .y -> ret where: ret = f(x,y) as-with x def as y def ret where: ret = f(x,y)
-
pattern-matching
the default mode is
[==]
.condic[] list(range(0,100)): +[] case (a,*b,c) => assert a==0 and b == list(range(1,99)) and c == 99 condic 1: [>] case 0 => assert 1 > 0 condic 1: [is not] case 1 => assert 1 is not 1 case 1 => assert 1 == 1 otherwise => True condic 1: (type) case int => assert type(1) == int condic 1: (.x->x+3) case 1 => assert x+3 == 1 where: x=1 (.x->x+3) case 4 => assert x+3 == 4 where: x=1 tomap = as-with f def as var def ret where: ret = list(map(f,var)) condic[] [1,2,3]: +(type) case (*a,b):(int,int,int) => assert [*a,b] == x and tomap(type)(x) == [int,int,int] where: x = [1,2,3] case (*a,b)-> a:list => pass condic +[in] 1: case a:{1,2,3} => assert x in y where: x = 1 y = {1,2,3} condic +[>] (10,20): case (a,b):(5,10) => assert (a,b) > (5,10)
-
arrow transform
>> 1 -> _ >> 1 >> 1 -> _+2 >> 2 >> range(200) -> map(.x->x+1, _) -> list(_) >> [2,3,4,5,6,7,...
-
matching filter
condic +(type) [1,3,5]: case (*a,b)->a:list => print("type(a) == list") otherwise => raise False, "excuse me??"
-
Branches
environ = dict(c = 'd', d = 'e') otherwise = True x = r where: | environ['c'] == 'c' => r = 1 | environ['d'] == 'd' => r = 2 | otherwise => r = 3 x ->> print # See pipeline grammar in next section. >> 3
-
Pipeline
1 ->> add1 => mul3 => div4 where: add1 = . x -> x+1 mul3 = . x -> x*3 div4 = . x -> x/4 >> 1.5 range(100) ->> flow_map(.x->%2) => flow_filter(.x->x) => len # [1..100] -> [0,1,0,1..] -> [1,1,1,1..] -> 50 >> 50