Commit | Line | Data |
---|---|---|
38a93523 NJ |
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 | ||
38a93523 NJ |
25 | @deffn primitive procedure-properties proc |
26 | Return @var{obj}'s property list. | |
27 | @end deffn | |
28 | ||
38a93523 NJ |
29 | @deffn primitive procedure-property p k |
30 | Return the property of @var{obj} with name @var{key}. | |
31 | @end deffn | |
32 | ||
38a93523 NJ |
33 | @deffn primitive set-procedure-properties! proc new_val |
34 | Set @var{obj}'s property list to @var{alist}. | |
35 | @end deffn | |
36 | ||
38a93523 NJ |
37 | @deffn primitive set-procedure-property! p k v |
38 | In @var{obj}'s property list, set the property named @var{key} to | |
39 | @var{value}. | |
40 | @end deffn | |
41 | ||
38a93523 NJ |
42 | @deffn primitive procedure-documentation proc |
43 | Return the documentation string associated with @code{proc}. By | |
44 | convention, if a procedure contains more than one expression and the | |
45 | first expression is a string constant, that string is assumed to contain | |
46 | documentation for that procedure. | |
47 | @end deffn | |
48 | ||
38a93523 NJ |
49 | @deffn primitive closure? obj |
50 | Return @code{#t} if @var{obj} is a closure. | |
51 | @end deffn | |
52 | ||
5c4b24e1 | 53 | @rnindex procedure? |
38a93523 NJ |
54 | @deffn primitive procedure? obj |
55 | Return @code{#t} if @var{obj} is a procedure. | |
56 | @end deffn | |
57 | ||
38a93523 NJ |
58 | @deffn primitive thunk? obj |
59 | Return @code{#t} if @var{obj} is a thunk. | |
60 | @end deffn | |
61 | ||
38a93523 NJ |
62 | @deffn primitive set-source-properties! obj plist |
63 | Install the association list @var{plist} as the source property | |
64 | list for @var{obj}. | |
65 | @end deffn | |
66 | ||
38a93523 NJ |
67 | @deffn primitive set-source-property! obj key datum |
68 | Set the source property of object @var{obj}, which is specified by | |
69 | @var{key} to @var{datum}. Normally, the key will be a symbol. | |
70 | @end deffn | |
71 | ||
38a93523 NJ |
72 | @deffn primitive source-properties obj |
73 | Return the source property association list of @var{obj}. | |
74 | @end deffn | |
75 | ||
38a93523 NJ |
76 | |
77 | @deffn primitive source-property obj key | |
78 | Return the source property specified by @var{key} from | |
79 | @var{obj}'s source property list. | |
80 | @end deffn | |
81 | ||
82 | ||
83 | @node Procedures with Setters | |
84 | @section Procedures with Setters | |
85 | ||
38a93523 NJ |
86 | @deffn primitive make-procedure-with-setter procedure setter |
87 | Create a new procedure which behaves like @var{procedure}, but | |
88 | with the associated setter @var{setter}. | |
89 | @end deffn | |
90 | ||
38a93523 NJ |
91 | @deffn primitive procedure-with-setter? obj |
92 | Return @code{#t} if @var{obj} is a procedure with an | |
93 | associated setter procedure. | |
94 | @end deffn | |
95 | ||
38a93523 NJ |
96 | @deffn primitive procedure proc |
97 | Return the procedure of @var{proc}, which must be either a | |
98 | procedure with setter, or an operator struct. | |
99 | @end deffn | |
100 | ||
38a93523 NJ |
101 | @deffn primitive setter proc |
102 | @end deffn | |
103 | ||
104 | ||
105 | @node Macros | |
106 | @section Macros | |
107 | ||
108 | [FIXME: This needs some more text on the difference between procedures, | |
109 | macros and memoizing macros. Also, any definitions listed here should | |
110 | be double-checked by someone who knows what's going on. Ask Mikael, Jim | |
111 | or Aubrey for help. -twp] | |
112 | ||
38a93523 | 113 | @deffn primitive procedure->syntax code |
ae9f3a15 MG |
114 | Return a @dfn{macro} which, when a symbol defined to this value |
115 | appears as the first symbol in an expression, returns the | |
116 | result of applying @var{code} to the expression and the | |
117 | environment. | |
38a93523 NJ |
118 | @end deffn |
119 | ||
38a93523 | 120 | @deffn primitive procedure->macro code |
ae9f3a15 MG |
121 | Return a @dfn{macro} which, when a symbol defined to this value |
122 | appears as the first symbol in an expression, evaluates the | |
123 | result of applying @var{code} to the expression and the | |
124 | environment. The value returned from @var{code} which has been | |
125 | passed to @code{procedure->memoizing-macro} replaces the form | |
126 | passed to @var{code}. For example: | |
127 | @lisp | |
38a93523 NJ |
128 | (define trace |
129 | (procedure->macro | |
130 | (lambda (x env) `(set! ,(cadr x) (tracef ,(cadr x) ',(cadr x)))))) | |
131 | ||
132 | (trace @i{foo}) @equiv{} (set! @i{foo} (tracef @i{foo} '@i{foo})). | |
ae9f3a15 | 133 | @end lisp |
38a93523 NJ |
134 | @end deffn |
135 | ||
38a93523 | 136 | @deffn primitive procedure->memoizing-macro code |
ae9f3a15 MG |
137 | Return a @dfn{macro} which, when a symbol defined to this value |
138 | appears as the first symbol in an expression, evaluates the | |
139 | result of applying @var{proc} to the expression and the | |
140 | environment. The value returned from @var{proc} which has been | |
141 | passed to @code{procedure->memoizing-macro} replaces the form | |
142 | passed to @var{proc}. For example: | |
143 | @lisp | |
38a93523 NJ |
144 | (define trace |
145 | (procedure->macro | |
146 | (lambda (x env) `(set! ,(cadr x) (tracef ,(cadr x) ',(cadr x)))))) | |
147 | ||
148 | (trace @i{foo}) @equiv{} (set! @i{foo} (tracef @i{foo} '@i{foo})). | |
ae9f3a15 | 149 | @end lisp |
38a93523 NJ |
150 | @end deffn |
151 | ||
38a93523 NJ |
152 | @deffn primitive macro? obj |
153 | Return @code{#t} if @var{obj} is a regular macro, a memoizing macro or a | |
154 | syntax transformer. | |
155 | @end deffn | |
156 | ||
38a93523 | 157 | @deffn primitive macro-type m |
ae9f3a15 MG |
158 | Return one of the symbols @code{syntax}, @code{macro} or |
159 | @code{macro!}, depending on whether @var{m} is a syntax | |
160 | tranformer, a regular macro, or a memoizing macro, | |
161 | respectively. If @var{m} is not a macro, @code{#f} is | |
162 | returned. | |
38a93523 NJ |
163 | @end deffn |
164 | ||
38a93523 NJ |
165 | @deffn primitive macro-name m |
166 | Return the name of the macro @var{m}. | |
167 | @end deffn | |
168 | ||
38a93523 NJ |
169 | @deffn primitive macro-transformer m |
170 | Return the transformer of the macro @var{m}. | |
171 | @end deffn | |
172 | ||
38a93523 NJ |
173 | @deffn primitive cons-source xorig x y |
174 | Create and return a new pair whose car and cdr are @var{x} and @var{y}. | |
175 | Any source properties associated with @var{xorig} are also associated | |
176 | with the new pair. | |
177 | @end deffn | |
178 | ||
179 | ||
180 | @c Local Variables: | |
181 | @c TeX-master: "guile.texi" | |
182 | @c End: |