2 @node Procedures and Macros
3 @chapter Procedures and Macros
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.
15 @section Lambda: Basic Procedure Creation
18 @node Optional Arguments
19 @section Optional Arguments
22 @node Procedure Properties
23 @section Procedure Properties and Metainformation
25 @c docstring begin (texi-doc-string "guile" "procedure-properties")
26 @deffn primitive procedure-properties proc
27 Return @var{obj}'s property list.
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}.
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}.
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
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.
54 @c docstring begin (texi-doc-string "guile" "closure?")
55 @deffn primitive closure? obj
56 Return @code{#t} if @var{obj} is a closure.
59 @c docstring begin (texi-doc-string "guile" "procedure?")
60 @deffn primitive procedure? obj
61 Return @code{#t} if @var{obj} is a procedure.
64 @c docstring begin (texi-doc-string "guile" "thunk?")
65 @deffn primitive thunk? obj
66 Return @code{#t} if @var{obj} is a thunk.
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
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.
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}.
86 @c docstring begin (texi-doc-string "guile" "source-property")
88 @deffn primitive source-property obj key
89 Return the source property specified by @var{key} from
90 @var{obj}'s source property list.
94 @node Procedures with Setters
95 @section Procedures with Setters
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}.
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.
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.
115 @c docstring begin (texi-doc-string "guile" "setter")
116 @deffn primitive setter proc
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]
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.
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:
147 (lambda (x env) `(set! ,(cadr x) (tracef ,(cadr x) ',(cadr x))))))
149 (trace @i{foo}) @equiv{} (set! @i{foo} (tracef @i{foo} '@i{foo})).
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:
165 (lambda (x env) `(set! ,(cadr x) (tracef ,(cadr x) ',(cadr x))))))
167 (trace @i{foo}) @equiv{} (set! @i{foo} (tracef @i{foo} '@i{foo})).
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
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.
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}.
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}.
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
205 @c TeX-master: "guile.texi"