1 /* This file contains definitions for discouraged features. When you
2 discourage something, move it here when that is feasible.
5 /* Copyright (C) 2003, 2004, 2006 Free Software Foundation, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #if (SCM_ENABLE_DISCOURAGED == 1)
27 scm_short2num (short x
)
29 return scm_from_short (x
);
33 scm_ushort2num (unsigned short x
)
35 return scm_from_ushort (x
);
41 return scm_from_int (x
);
45 scm_uint2num (unsigned int x
)
47 return scm_from_uint (x
);
53 return scm_from_long (x
);
57 scm_ulong2num (unsigned long x
)
59 return scm_from_ulong (x
);
63 scm_size2num (size_t x
)
65 return scm_from_size_t (x
);
69 scm_ptrdiff2num (ptrdiff_t x
)
71 return scm_from_ssize_t (x
);
75 scm_num2short (SCM x
, unsigned long pos
, const char *s_caller
)
77 return scm_to_short (x
);
81 scm_num2ushort (SCM x
, unsigned long pos
, const char *s_caller
)
83 return scm_to_ushort (x
);
87 scm_num2int (SCM x
, unsigned long pos
, const char *s_caller
)
89 return scm_to_int (x
);
93 scm_num2uint (SCM x
, unsigned long pos
, const char *s_caller
)
95 return scm_to_uint (x
);
99 scm_num2long (SCM x
, unsigned long pos
, const char *s_caller
)
101 return scm_to_long (x
);
105 scm_num2ulong (SCM x
, unsigned long pos
, const char *s_caller
)
107 return scm_to_ulong (x
);
111 scm_num2size (SCM x
, unsigned long pos
, const char *s_caller
)
113 return scm_to_size_t (x
);
117 scm_num2ptrdiff (SCM x
, unsigned long pos
, const char *s_caller
)
119 return scm_to_ssize_t (x
);
122 #if SCM_SIZEOF_LONG_LONG != 0
125 scm_long_long2num (long long x
)
127 return scm_from_long_long (x
);
131 scm_ulong_long2num (unsigned long long x
)
133 return scm_from_ulong_long (x
);
137 scm_num2long_long (SCM x
, unsigned long pos
, const char *s_caller
)
139 return scm_to_long_long (x
);
143 scm_num2ulong_long (SCM x
, unsigned long pos
, const char *s_caller
)
145 return scm_to_ulong_long (x
);
151 scm_make_real (double x
)
153 return scm_from_double (x
);
157 scm_num2dbl (SCM a
, const char *why
)
159 return scm_to_double (a
);
163 scm_float2num (float n
)
165 return scm_from_double ((double) n
);
169 scm_double2num (double n
)
171 return scm_from_double (n
);
175 scm_make_complex (double x
, double y
)
177 return scm_c_make_rectangular (x
, y
);
181 scm_mem2symbol (const char *mem
, size_t len
)
183 return scm_from_locale_symboln (mem
, len
);
187 scm_mem2uninterned_symbol (const char *mem
, size_t len
)
189 return scm_make_symbol (scm_from_locale_stringn (mem
, len
));
193 scm_str2symbol (const char *str
)
195 return scm_from_locale_symbol (str
);
199 /* This function must only be applied to memory obtained via malloc,
200 since the GC is going to apply `free' to it when the string is
203 Also, s[len] must be `\0', since we promise that strings are
204 null-terminated. Perhaps we could handle non-null-terminated
205 strings by claiming they're shared substrings of a string we just
208 scm_take_str (char *s
, size_t len
)
210 SCM answer
= scm_from_locale_stringn (s
, len
);
215 /* `s' must be a malloc'd string. See scm_take_str. */
217 scm_take0str (char *s
)
219 return scm_take_locale_string (s
);
223 scm_mem2string (const char *src
, size_t len
)
225 return scm_from_locale_stringn (src
, len
);
229 scm_str2string (const char *src
)
231 return scm_from_locale_string (src
);
235 scm_makfrom0str (const char *src
)
237 if (!src
) return SCM_BOOL_F
;
238 return scm_from_locale_string (src
);
242 scm_makfrom0str_opt (const char *src
)
244 return scm_makfrom0str (src
);
249 scm_allocate_string (size_t len
)
251 return scm_i_make_string (len
, NULL
);
254 SCM_DEFINE (scm_make_keyword_from_dash_symbol
, "make-keyword-from-dash-symbol", 1, 0, 0,
256 "Make a keyword object from a @var{symbol} that starts with a dash.")
257 #define FUNC_NAME s_scm_make_keyword_from_dash_symbol
259 SCM dash_string
, non_dash_symbol
;
261 SCM_ASSERT (scm_is_symbol (symbol
)
262 && ('-' == scm_i_symbol_chars(symbol
)[0]),
263 symbol
, SCM_ARG1
, FUNC_NAME
);
265 dash_string
= scm_symbol_to_string (symbol
);
267 scm_string_to_symbol (scm_c_substring (dash_string
,
269 scm_c_string_length (dash_string
)));
271 return scm_symbol_to_keyword (non_dash_symbol
);
275 SCM_DEFINE (scm_keyword_dash_symbol
, "keyword-dash-symbol", 1, 0, 0,
277 "Return the dash symbol for @var{keyword}.\n"
278 "This is the inverse of @code{make-keyword-from-dash-symbol}.")
279 #define FUNC_NAME s_scm_keyword_dash_symbol
281 SCM symbol
= scm_keyword_to_symbol (keyword
);
282 SCM parts
= scm_list_2 (scm_from_locale_string ("-"),
283 scm_symbol_to_string (symbol
));
284 return scm_string_to_symbol (scm_string_append (parts
));
289 scm_c_make_keyword (const char *s
)
291 return scm_from_locale_keyword (s
);
296 scm_i_init_discouraged (void)
298 #include "libguile/discouraged.x"