source: project/wiki/eggref/5/pipes @ 37480

Last change on this file since 37480 was 37480, checked in by juergen, 17 months ago

pipes docu

File size: 3.6 KB
Line 
1[[tags: egg]]
2
3== pipes
4
5[[toc:]]
6
7=== Description
8
9Besides the documentation procedure, this module exports three routines,
10the macros pipe and pipe* as well as the procedure flip*. The first
11macro takes a variable and a sequence of partial combinations, calls the
12first combination with the variable as additional left argument and
13hands the result successively to the next combination. For example
14
15  (pipe 3 (+ 1) (- 2) (* 5))
16
17will return 10.
18
19Sometimes its necessary to add the variable to the right of the argument
20list. To achieve this simply replace the combination's name, fn say, with
21(flip* fn): flip* flips the first argument of fn to the end, and thus is a
22generalisation of flip in (chicken base).
23
24==== pipes
25
26<procedure>(pipes)</procedure>
27<procedure>(pipes sym)</procedure>
28
29documentation procedure:
30the first call shows the list of exported symbols,
31the second the documentation of sym.
32
33==== pipe
34
35<macro>(pipe x (fn . xs) ...)</macro>
36
37calls each combination with the result of applying its combination to
38the left as first argument. In particular (pipe x (fn . xs)) is
39(fn x . xs) and (pipe x (fn . xs) (gn . ys)) is (gn (fn x . xs)).
40
41==== pipe*
42
43<macro>(pipe* (fn . xs) ...)</macro>
44
45pipe as a procedure: (pipe* (fn . xs) ...) is
46(lambda (x) (pipe x (fn . xs) ...))
47
48==== flip*>
49
50<procedure>(flip*% proc)</procedure>
51
52flips the arguments of proc by shifting the first one to the end.
53
54=== Examples
55
56<enscript highlight=scheme>
57
58((flip* list)) ; -> '()
59((flip* list) 1) ; -> '(1)
60((flip* list) 1 2) ; -> '(2 1)
61((flip* list) 1 2 3 4) ; -> '(2 3 4 1)
62((flip* map) '(0 1 2) add1) ; -> '(1 2 3)
63
64(pipe 5) ; -> 5
65(pipe 5 (+ 1)) ; -> 6
66(pipe 5 (- 10) (positive?)) ; -> #f
67(pipe 5 (- 10) (negative?)) ; -> #t
68(pipe 10 ((flip* list) 1 2 3 4)) ; -> '(1 2 3 4 10)
69(pipe 10 (list 1 2 3 4)) ; -> '(10 1 2 3 4))
70(pipe '(0 1 2) ((flip* map) add1)) ; -> '(1 2 3))
71(pipe 0 (list 1 2 3)) ; - > '(0 1 2 3))
72(pipe 0 ((flip* list) 1 2 3)) ; - > '(1 2 3 0))
73
74</enscript>
75
76=== Requirements
77
78none
79
80== Last update
81
82Mar 28, 2019
83
84== Author
85
86[[/users/juergen-lorenz|Juergen Lorenz]]
87
88== License
89
90 Copyright (c) 2016-2019, Juergen Lorenz
91 All rights reserved.
92
93 Redistribution and use in source and binary forms, with or without
94 modification, are permitted provided that the following conditions are
95 met:
96 
97 Redistributions of source code must retain the above copyright
98 notice, this list of conditions and the following disclaimer.
99 
100 Redistributions in binary form must reproduce the above copyright
101 notice, this list of conditions and the following disclaimer in the
102 documentation and/or other materials provided with the distribution.
103 Neither the name of the author nor the names of its contributors may be
104 used to endorse or promote products derived from this software without
105 specific prior written permission.
106   
107 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
108 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
109 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
110 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
111 HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
112 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
113 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
114 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
115 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
116 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
117 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
118
119== Version History
120; 1.0 : initial import
121
122
123
Note: See TracBrowser for help on using the repository browser.