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, 2008 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
29 #if (SCM_ENABLE_DISCOURAGED == 1)
32 scm_short2num (short x)
34 return scm_from_short (x);
38 scm_ushort2num (unsigned short x)
40 return scm_from_ushort (x);
46 return scm_from_int (x);
50 scm_uint2num (unsigned int x)
52 return scm_from_uint (x);
58 return scm_from_long (x);
62 scm_ulong2num (unsigned long x)
64 return scm_from_ulong (x);
68 scm_size2num (size_t x)
70 return scm_from_size_t (x);
74 scm_ptrdiff2num (ptrdiff_t x)
76 return scm_from_ssize_t (x);
80 scm_num2short (SCM x, unsigned long pos, const char *s_caller)
82 return scm_to_short (x);
86 scm_num2ushort (SCM x, unsigned long pos, const char *s_caller)
88 return scm_to_ushort (x);
92 scm_num2int (SCM x, unsigned long pos, const char *s_caller)
94 return scm_to_int (x);
98 scm_num2uint (SCM x, unsigned long pos, const char *s_caller)
100 return scm_to_uint (x);
104 scm_num2long (SCM x, unsigned long pos, const char *s_caller)
106 return scm_to_long (x);
110 scm_num2ulong (SCM x, unsigned long pos, const char *s_caller)
112 return scm_to_ulong (x);
116 scm_num2size (SCM x, unsigned long pos, const char *s_caller)
118 return scm_to_size_t (x);
122 scm_num2ptrdiff (SCM x, unsigned long pos, const char *s_caller)
124 return scm_to_ssize_t (x);
127 #if SCM_SIZEOF_LONG_LONG != 0
130 scm_long_long2num (long long x)
132 return scm_from_long_long (x);
136 scm_ulong_long2num (unsigned long long x)
138 return scm_from_ulong_long (x);
142 scm_num2long_long (SCM x, unsigned long pos, const char *s_caller)
144 return scm_to_long_long (x);
148 scm_num2ulong_long (SCM x, unsigned long pos, const char *s_caller)
150 return scm_to_ulong_long (x);
156 scm_make_real (double x)
158 return scm_from_double (x);
162 scm_num2dbl (SCM a, const char *why)
164 return scm_to_double (a);
168 scm_float2num (float n)
170 return scm_from_double ((double) n);
174 scm_double2num (double n)
176 return scm_from_double (n);
180 scm_make_complex (double x, double y)
182 return scm_c_make_rectangular (x, y);
186 scm_mem2symbol (const char *mem, size_t len)
188 return scm_from_locale_symboln (mem, len);
192 scm_mem2uninterned_symbol (const char *mem, size_t len)
194 return scm_make_symbol (scm_from_locale_stringn (mem, len));
198 scm_str2symbol (const char *str)
200 return scm_from_locale_symbol (str);
204 /* This function must only be applied to memory obtained via malloc,
205 since the GC is going to apply `free' to it when the string is
208 Also, s[len] must be `\0', since we promise that strings are
209 null-terminated. Perhaps we could handle non-null-terminated
210 strings by claiming they're shared substrings of a string we just
213 scm_take_str (char *s, size_t len)
215 SCM answer = scm_from_locale_stringn (s, len);
220 /* `s' must be a malloc'd string. See scm_take_str. */
222 scm_take0str (char *s)
224 return scm_take_locale_string (s);
228 scm_mem2string (const char *src, size_t len)
230 return scm_from_locale_stringn (src, len);
234 scm_str2string (const char *src)
236 return scm_from_locale_string (src);
240 scm_makfrom0str (const char *src)
242 if (!src) return SCM_BOOL_F;
243 return scm_from_locale_string (src);
247 scm_makfrom0str_opt (const char *src)
249 return scm_makfrom0str (src);
254 scm_allocate_string (size_t len)
256 return scm_i_make_string (len, NULL);
259 SCM_DEFINE (scm_make_keyword_from_dash_symbol, "make-keyword-from-dash-symbol", 1, 0, 0,
261 "Make a keyword object from a @var{symbol} that starts with a dash.")
262 #define FUNC_NAME s_scm_make_keyword_from_dash_symbol
264 SCM dash_string, non_dash_symbol;
266 SCM_ASSERT (scm_is_symbol (symbol)
267 && ('-' == scm_i_symbol_chars(symbol)[0]),
268 symbol, SCM_ARG1, FUNC_NAME);
270 dash_string = scm_symbol_to_string (symbol);
272 scm_string_to_symbol (scm_c_substring (dash_string,
274 scm_c_string_length (dash_string)));
276 return scm_symbol_to_keyword (non_dash_symbol);
280 SCM_DEFINE (scm_keyword_dash_symbol, "keyword-dash-symbol", 1, 0, 0,
282 "Return the dash symbol for @var{keyword}.\n"
283 "This is the inverse of @code{make-keyword-from-dash-symbol}.")
284 #define FUNC_NAME s_scm_keyword_dash_symbol
286 SCM symbol = scm_keyword_to_symbol (keyword);
287 SCM parts = scm_list_2 (scm_from_locale_string ("-"),
288 scm_symbol_to_string (symbol));
289 return scm_string_to_symbol (scm_string_append (parts));
294 scm_c_make_keyword (const char *s)
296 return scm_from_locale_keyword (s);
301 scm_i_init_discouraged (void)
303 #include "libguile/discouraged.x"