Move doc files into guile-core distribution (7)
[bpt/guile.git] / doc / scheme-procedures.texi
1 @page
2 @node Procedures and Macros
3 @chapter Procedures and Macros
4
5 @menu
6 * Lambda:: Basic procedure creation using lambda.
7 * Optional Arguments:: Handling keyword, optional and rest arguments.
8 * Procedure Properties:: Procedure properties and metainformation.
9 * Procedures with Setters:: Procedures with setters.
10 * Macros:: Macros.
11 @end menu
12
13
14 @node Lambda
15 @section Lambda: Basic Procedure Creation
16
17
18 @node Optional Arguments
19 @section Optional Arguments
20
21
22 @node Procedure Properties
23 @section Procedure Properties and Metainformation
24
25 @c docstring begin (texi-doc-string "guile" "procedure-properties")
26 @deffn primitive procedure-properties proc
27 Return @var{obj}'s property list.
28 @end deffn
29
30 @c docstring begin (texi-doc-string "guile" "procedure-property")
31 @deffn primitive procedure-property p k
32 Return the property of @var{obj} with name @var{key}.
33 @end deffn
34
35 @c docstring begin (texi-doc-string "guile" "set-procedure-properties!")
36 @deffn primitive set-procedure-properties! proc new_val
37 Set @var{obj}'s property list to @var{alist}.
38 @end deffn
39
40 @c docstring begin (texi-doc-string "guile" "set-procedure-property!")
41 @deffn primitive set-procedure-property! p k v
42 In @var{obj}'s property list, set the property named @var{key} to
43 @var{value}.
44 @end deffn
45
46 @c docstring begin (texi-doc-string "guile" "procedure-documentation")
47 @deffn primitive procedure-documentation proc
48 Return the documentation string associated with @code{proc}. By
49 convention, if a procedure contains more than one expression and the
50 first expression is a string constant, that string is assumed to contain
51 documentation for that procedure.
52 @end deffn
53
54 @c docstring begin (texi-doc-string "guile" "closure?")
55 @deffn primitive closure? obj
56 Return @code{#t} if @var{obj} is a closure.
57 @end deffn
58
59 @c docstring begin (texi-doc-string "guile" "procedure?")
60 @deffn primitive procedure? obj
61 Return @code{#t} if @var{obj} is a procedure.
62 @end deffn
63
64 @c docstring begin (texi-doc-string "guile" "thunk?")
65 @deffn primitive thunk? obj
66 Return @code{#t} if @var{obj} is a thunk.
67 @end deffn
68
69 @c docstring begin (texi-doc-string "guile" "set-source-properties!")
70 @deffn primitive set-source-properties! obj plist
71 Install the association list @var{plist} as the source property
72 list for @var{obj}.
73 @end deffn
74
75 @c docstring begin (texi-doc-string "guile" "set-source-property!")
76 @deffn primitive set-source-property! obj key datum
77 Set the source property of object @var{obj}, which is specified by
78 @var{key} to @var{datum}. Normally, the key will be a symbol.
79 @end deffn
80
81 @c docstring begin (texi-doc-string "guile" "source-properties")
82 @deffn primitive source-properties obj
83 Return the source property association list of @var{obj}.
84 @end deffn
85
86 @c docstring begin (texi-doc-string "guile" "source-property")
87
88 @deffn primitive source-property obj key
89 Return the source property specified by @var{key} from
90 @var{obj}'s source property list.
91 @end deffn
92
93
94 @node Procedures with Setters
95 @section Procedures with Setters
96
97 @c docstring begin (texi-doc-string "guile" "make-procedure-with-setter")
98 @deffn primitive make-procedure-with-setter procedure setter
99 Create a new procedure which behaves like @var{procedure}, but
100 with the associated setter @var{setter}.
101 @end deffn
102
103 @c docstring begin (texi-doc-string "guile" "procedure-with-setter?")
104 @deffn primitive procedure-with-setter? obj
105 Return @code{#t} if @var{obj} is a procedure with an
106 associated setter procedure.
107 @end deffn
108
109 @c docstring begin (texi-doc-string "guile" "procedure")
110 @deffn primitive procedure proc
111 Return the procedure of @var{proc}, which must be either a
112 procedure with setter, or an operator struct.
113 @end deffn
114
115 @c docstring begin (texi-doc-string "guile" "setter")
116 @deffn primitive setter proc
117 @end deffn
118
119
120 @node Macros
121 @section Macros
122
123 [FIXME: This needs some more text on the difference between procedures,
124 macros and memoizing macros. Also, any definitions listed here should
125 be double-checked by someone who knows what's going on. Ask Mikael, Jim
126 or Aubrey for help. -twp]
127
128 @c docstring begin (texi-doc-string "guile" "procedure->syntax")
129 @deffn primitive procedure->syntax code
130 Returns a @dfn{macro} which, when a symbol defined to this value
131 appears as the first symbol in an expression, returns the result
132 of applying @var{code} to the expression and the environment.
133 @end deffn
134
135 @c docstring begin (texi-doc-string "guile" "procedure->macro")
136 @deffn primitive procedure->macro code
137 Returns a @dfn{macro} which, when a symbol defined to this value
138 appears as the first symbol in an expression, evaluates the result
139 of applying @var{code} to the expression and the environment.
140 The value returned from @var{code} which has been passed to
141 @code{procedure->memoizing-macro} replaces the form passed to
142 @var{code}. For example:
143
144 @example
145 (define trace
146 (procedure->macro
147 (lambda (x env) `(set! ,(cadr x) (tracef ,(cadr x) ',(cadr x))))))
148
149 (trace @i{foo}) @equiv{} (set! @i{foo} (tracef @i{foo} '@i{foo})).
150 @end example
151 @end deffn
152
153 @c docstring begin (texi-doc-string "guile" "procedure->memoizing-macro")
154 @deffn primitive procedure->memoizing-macro code
155 Returns a @dfn{macro} which, when a symbol defined to this value
156 appears as the first symbol in an expression, evaluates the result
157 of applying @var{proc} to the expression and the environment.
158 The value returned from @var{proc} which has been passed to
159 @code{procedure->memoizing-macro} replaces the form passed to
160 @var{proc}. For example:
161
162 @example
163 (define trace
164 (procedure->macro
165 (lambda (x env) `(set! ,(cadr x) (tracef ,(cadr x) ',(cadr x))))))
166
167 (trace @i{foo}) @equiv{} (set! @i{foo} (tracef @i{foo} '@i{foo})).
168 @end example
169 @end deffn
170
171 @c docstring begin (texi-doc-string "guile" "macro?")
172 @deffn primitive macro? obj
173 Return @code{#t} if @var{obj} is a regular macro, a memoizing macro or a
174 syntax transformer.
175 @end deffn
176
177 @c ARGFIXME m/obj
178 @c docstring begin (texi-doc-string "guile" "macro-type")
179 @deffn primitive macro-type m
180 Return one of the symbols @code{syntax}, @code{macro} or @code{macro!},
181 depending on whether @var{obj} is a syntax tranformer, a regular macro,
182 or a memoizing macro, respectively. If @var{obj} is not a macro,
183 @code{#f} is returned.
184 @end deffn
185
186 @c docstring begin (texi-doc-string "guile" "macro-name")
187 @deffn primitive macro-name m
188 Return the name of the macro @var{m}.
189 @end deffn
190
191 @c docstring begin (texi-doc-string "guile" "macro-transformer")
192 @deffn primitive macro-transformer m
193 Return the transformer of the macro @var{m}.
194 @end deffn
195
196 @c docstring begin (texi-doc-string "guile" "cons-source")
197 @deffn primitive cons-source xorig x y
198 Create and return a new pair whose car and cdr are @var{x} and @var{y}.
199 Any source properties associated with @var{xorig} are also associated
200 with the new pair.
201 @end deffn
202
203
204 @c Local Variables:
205 @c TeX-master: "guile.texi"
206 @c End: