1 /* Copyright (C) 1995,1996,1997,1999,2000,2001, 2006, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public License
5 * as published by the Free Software Foundation; either version 3 of
6 * the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 #include "libguile/_scm.h"
27 #include "libguile/strings.h"
28 #include "libguile/vectors.h"
29 #include "libguile/smob.h"
30 #include "libguile/deprecation.h"
32 #include "libguile/validate.h"
33 #include "libguile/procs.h"
34 #include "libguile/procprop.h"
35 #include "libguile/objcodes.h"
36 #include "libguile/programs.h"
44 SCM_DEFINE (scm_procedure_p
, "procedure?", 1, 0, 0,
46 "Return @code{#t} if @var{obj} is a procedure.")
47 #define FUNC_NAME s_scm_procedure_p
49 return scm_from_bool (SCM_PROGRAM_P (obj
)
50 || (SCM_STRUCTP (obj
) && SCM_STRUCT_APPLICABLE_P (obj
))
51 || (SCM_HAS_TYP7 (obj
, scm_tc7_smob
)
52 && SCM_SMOB_APPLICABLE_P (obj
)));
56 SCM_DEFINE (scm_thunk_p
, "thunk?", 1, 0, 0,
58 "Return @code{#t} if @var{obj} is a thunk.")
59 #define FUNC_NAME s_scm_thunk_p
62 return scm_from_bool (scm_i_procedure_arity (obj
, &req
, &opt
, &rest
)
67 SCM_SYMBOL (sym_documentation
, "documentation");
69 SCM_DEFINE (scm_procedure_documentation
, "procedure-documentation", 1, 0, 0,
71 "Return the documentation string associated with @code{proc}. By\n"
72 "convention, if a procedure contains more than one expression and the\n"
73 "first expression is a string constant, that string is assumed to contain\n"
74 "documentation for that procedure.")
75 #define FUNC_NAME s_scm_procedure_documentation
77 SCM_VALIDATE_PROC (SCM_ARG1
, proc
);
78 return scm_procedure_property (proc
, sym_documentation
);
83 /* Procedure-with-setter
86 static SCM pws_vtable
;
89 SCM_DEFINE (scm_procedure_with_setter_p
, "procedure-with-setter?", 1, 0, 0,
91 "Return @code{#t} if @var{obj} is a procedure with an\n"
92 "associated setter procedure.")
93 #define FUNC_NAME s_scm_procedure_with_setter_p
95 return scm_from_bool (SCM_STRUCTP (obj
) && SCM_STRUCT_SETTER_P (obj
));
99 SCM_DEFINE (scm_make_procedure_with_setter
, "make-procedure-with-setter", 2, 0, 0,
100 (SCM procedure
, SCM setter
),
101 "Create a new procedure which behaves like @var{procedure}, but\n"
102 "with the associated setter @var{setter}.")
103 #define FUNC_NAME s_scm_make_procedure_with_setter
106 SCM_VALIDATE_PROC (1, procedure
);
107 SCM_VALIDATE_PROC (2, setter
);
108 ret
= scm_make_struct (pws_vtable
, SCM_INUM0
,
109 scm_list_2 (procedure
, setter
));
111 /* don't use procedure_name, because don't care enough to do a reverse
113 name
= scm_procedure_property (procedure
, scm_sym_name
);
114 if (scm_is_true (name
))
115 scm_set_procedure_property_x (ret
, scm_sym_name
, name
);
120 SCM_DEFINE (scm_procedure
, "procedure", 1, 0, 0,
122 "Return the procedure of @var{proc}, which must be an\n"
123 "applicable struct.")
124 #define FUNC_NAME s_scm_procedure
126 SCM_ASSERT (SCM_STRUCTP (proc
) && SCM_STRUCT_APPLICABLE_P (proc
),
127 proc
, SCM_ARG1
, FUNC_NAME
);
128 return SCM_STRUCT_PROCEDURE (proc
);
132 SCM_PRIMITIVE_GENERIC (scm_setter
, "setter", 1, 0, 0,
134 "Return the setter of @var{proc}, which must be an\n"
135 "applicable struct with a setter.")
136 #define FUNC_NAME s_scm_setter
138 if (SCM_UNLIKELY (!SCM_STRUCTP (proc
)))
139 return scm_wta_dispatch_1 (g_scm_setter
, proc
, SCM_ARG1
, FUNC_NAME
);
140 if (SCM_STRUCT_SETTER_P (proc
))
141 return SCM_STRUCT_SETTER (proc
);
142 if (SCM_PUREGENERICP (proc
)
143 && SCM_IS_A_P (proc
, scm_class_generic_with_setter
))
144 /* FIXME: might not be an accessor */
145 return SCM_GENERIC_SETTER (proc
);
146 return scm_wta_dispatch_1 (g_scm_setter
, proc
, SCM_ARG1
, FUNC_NAME
);
147 return SCM_BOOL_F
; /* not reached */
156 scm_c_make_struct (scm_applicable_struct_with_setter_vtable_vtable
,
159 SCM_UNPACK (scm_from_latin1_symbol ("pwpw")));
161 #include "libguile/procs.x"