list.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #ifndef SCM_LIST_H
  2. #define SCM_LIST_H
  3. /* Copyright 1995-1997,2000-2001,2003-2006,2008-2009,2018-2019
  4. Free Software Foundation, Inc.
  5. This file is part of Guile.
  6. Guile is free software: you can redistribute it and/or modify it
  7. under the terms of the GNU Lesser General Public License as published
  8. by the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Guile is distributed in the hope that it will be useful, but WITHOUT
  11. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  13. License for more details.
  14. You should have received a copy of the GNU Lesser General Public
  15. License along with Guile. If not, see
  16. <https://www.gnu.org/licenses/>. */
  17. #include "libguile/error.h"
  18. SCM_API SCM scm_list_1 (SCM e1);
  19. SCM_API SCM scm_list_2 (SCM e1, SCM e2);
  20. SCM_API SCM scm_list_3 (SCM e1, SCM e2, SCM e3);
  21. SCM_API SCM scm_list_4 (SCM e1, SCM e2, SCM e3, SCM e4);
  22. SCM_API SCM scm_list_5 (SCM e1, SCM e2, SCM e3, SCM e4, SCM e5);
  23. SCM_API SCM scm_list_n (SCM elt, ...);
  24. SCM_API SCM scm_list (SCM objs);
  25. SCM_API SCM scm_list_head (SCM lst, SCM k);
  26. SCM_API SCM scm_make_list (SCM n, SCM init);
  27. SCM_API SCM scm_cons_star (SCM arg, SCM objs);
  28. SCM_API SCM scm_null_p (SCM x);
  29. SCM_API SCM scm_list_p (SCM x);
  30. SCM_API long scm_ilength (SCM sx);
  31. SCM_API SCM scm_length (SCM x);
  32. SCM_API SCM scm_append (SCM args);
  33. SCM_API SCM scm_append_x (SCM args);
  34. SCM_API SCM scm_reverse (SCM lst);
  35. SCM_API SCM scm_reverse_x (SCM lst, SCM newtail);
  36. SCM_API SCM scm_list_ref (SCM lst, SCM k);
  37. SCM_API SCM scm_list_set_x (SCM lst, SCM k, SCM val);
  38. SCM_API SCM scm_list_cdr_set_x (SCM lst, SCM k, SCM val);
  39. SCM_API SCM scm_last_pair (SCM sx);
  40. SCM_API SCM scm_list_tail (SCM lst, SCM k);
  41. SCM_API SCM scm_c_memq (SCM x, SCM lst);
  42. SCM_API SCM scm_memq (SCM x, SCM lst);
  43. SCM_API SCM scm_memv (SCM x, SCM lst);
  44. SCM_API SCM scm_member (SCM x, SCM lst);
  45. SCM_API SCM scm_delq_x (SCM item, SCM lst);
  46. SCM_API SCM scm_delv_x (SCM item, SCM lst);
  47. SCM_API SCM scm_delete_x (SCM item, SCM lst);
  48. SCM_API SCM scm_list_copy (SCM lst);
  49. SCM_API SCM scm_delq (SCM item, SCM lst);
  50. SCM_API SCM scm_delv (SCM item, SCM lst);
  51. SCM_API SCM scm_delete (SCM item, SCM lst);
  52. SCM_API SCM scm_delq1_x (SCM item, SCM lst);
  53. SCM_API SCM scm_delv1_x (SCM item, SCM lst);
  54. SCM_API SCM scm_delete1_x (SCM item, SCM lst);
  55. SCM_API SCM scm_filter (SCM pred, SCM list);
  56. SCM_API SCM scm_filter_x (SCM pred, SCM list);
  57. SCM_API SCM scm_copy_tree (SCM obj);
  58. #define SCM_VALIDATE_REST_ARGUMENT(x) \
  59. do { \
  60. if (SCM_DEBUG_REST_ARGUMENT) { \
  61. if (scm_ilength (x) < 0) { \
  62. SCM_MISC_ERROR ("Rest arguments do not form a proper list.", SCM_EOL); \
  63. } \
  64. } \
  65. } while (0)
  66. #define SCM_VALIDATE_LIST(pos, lst) \
  67. do { \
  68. SCM_ASSERT (scm_ilength (lst) >= 0, lst, pos, FUNC_NAME); \
  69. } while (0)
  70. #define SCM_VALIDATE_NONEMPTYLIST(pos, lst) \
  71. do { \
  72. SCM_ASSERT (scm_ilength (lst) > 0, lst, pos, FUNC_NAME); \
  73. } while (0)
  74. /* Note: we use (cvar != -1) instead of (cvar >= 0) below
  75. in case 'cvar' is of unsigned type. */
  76. #define SCM_VALIDATE_LIST_COPYLEN(pos, lst, cvar) \
  77. do { \
  78. cvar = scm_ilength (lst); \
  79. SCM_ASSERT (cvar != -1, lst, pos, FUNC_NAME); \
  80. } while (0)
  81. /* Note: we use (cvar != -1) instead of (cvar >= 0) below
  82. in case 'cvar' is of unsigned type. */
  83. #define SCM_VALIDATE_NONEMPTYLIST_COPYLEN(pos, lst, cvar) \
  84. do { \
  85. cvar = scm_ilength (lst); \
  86. SCM_ASSERT (cvar != -1, lst, pos, FUNC_NAME); \
  87. } while (0)
  88. /* Guile internal functions */
  89. SCM_INTERNAL SCM scm_i_finite_list_copy (SCM /* a list known to be finite */);
  90. SCM_INTERNAL void scm_init_list (void);
  91. #endif /* SCM_LIST_H */