3 * Copyright 2006,2009,2010 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio 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
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
27 #include <gruel/pmt.h>
29 #include <gruel/msg_accepter.h>
30 #include <gruel/pmt_pool.h>
36 static const int CACHE_LINE_SIZE = 64; // good guess
38 # if (PMT_LOCAL_ALLOCATOR)
40 static pmt_pool global_pmt_pool(sizeof(pmt_pair), CACHE_LINE_SIZE);
43 pmt_base::operator new(size_t size)
45 void *p = global_pmt_pool.malloc();
47 // fprintf(stderr, "pmt_base::new p = %p\n", p);
48 assert((reinterpret_cast<intptr_t>(p) & (CACHE_LINE_SIZE - 1)) == 0);
53 pmt_base::operator delete(void *p, size_t size)
55 global_pmt_pool.free(p);
60 void intrusive_ptr_add_ref(pmt_base* p) { ++(p->count_); }
61 void intrusive_ptr_release(pmt_base* p) { if (--(p->count_) == 0 ) delete p; }
65 // nop -- out of line virtual destructor
68 ////////////////////////////////////////////////////////////////////////////
70 ////////////////////////////////////////////////////////////////////////////
72 pmt_exception::pmt_exception(const std::string &msg, pmt_t obj)
73 : logic_error(msg + ": " + pmt_write_string(obj))
77 pmt_wrong_type::pmt_wrong_type(const std::string &msg, pmt_t obj)
78 : pmt_exception(msg + ": wrong_type ", obj)
82 pmt_out_of_range::pmt_out_of_range(const std::string &msg, pmt_t obj)
83 : pmt_exception(msg + ": out of range ", obj)
87 pmt_notimplemented::pmt_notimplemented(const std::string &msg, pmt_t obj)
88 : pmt_exception(msg + ": notimplemented ", obj)
92 ////////////////////////////////////////////////////////////////////////////
94 ////////////////////////////////////////////////////////////////////////////
99 return dynamic_cast<pmt_symbol*>(x.get());
105 return dynamic_cast<pmt_integer*>(x.get());
111 return dynamic_cast<pmt_real*>(x.get());
117 return dynamic_cast<pmt_complex*>(x.get());
123 return dynamic_cast<pmt_pair*>(x.get());
129 return dynamic_cast<pmt_vector*>(x.get());
135 return dynamic_cast<pmt_tuple*>(x.get());
138 static pmt_uniform_vector *
139 _uniform_vector(pmt_t x)
141 return dynamic_cast<pmt_uniform_vector*>(x.get());
147 return dynamic_cast<pmt_any*>(x.get());
150 ////////////////////////////////////////////////////////////////////////////
152 ////////////////////////////////////////////////////////////////////////////
154 const pmt_t PMT_T = pmt_t(new pmt_bool()); // singleton
155 const pmt_t PMT_F = pmt_t(new pmt_bool()); // singleton
156 const pmt_t PMT_NIL = pmt_t(new pmt_null()); // singleton
157 const pmt_t PMT_EOF = pmt_cons(PMT_NIL, PMT_NIL); // singleton
159 ////////////////////////////////////////////////////////////////////////////
161 ////////////////////////////////////////////////////////////////////////////
163 pmt_bool::pmt_bool(){}
166 pmt_is_true(pmt_t obj)
172 pmt_is_false(pmt_t obj)
178 pmt_is_bool(pmt_t obj)
180 return obj->is_bool();
184 pmt_from_bool(bool val)
186 return val ? PMT_T : PMT_F;
190 pmt_to_bool(pmt_t val)
196 throw pmt_wrong_type("pmt_to_bool", val);
199 ////////////////////////////////////////////////////////////////////////////
201 ////////////////////////////////////////////////////////////////////////////
203 static const unsigned int SYMBOL_HASH_TABLE_SIZE = 701;
204 static std::vector<pmt_t> s_symbol_hash_table(SYMBOL_HASH_TABLE_SIZE);
206 pmt_symbol::pmt_symbol(const std::string &name) : d_name(name){}
210 hash_string(const std::string &s)
215 for (std::string::const_iterator p = s.begin(); p != s.end(); ++p){
216 h = (h << 4) + (*p & 0xff);
227 pmt_is_symbol(const pmt_t& obj)
229 return obj->is_symbol();
233 pmt_string_to_symbol(const std::string &name)
235 unsigned hash = hash_string(name) % SYMBOL_HASH_TABLE_SIZE;
237 // Does a symbol with this name already exist?
238 for (pmt_t sym = s_symbol_hash_table[hash]; sym; sym = _symbol(sym)->next()){
239 if (name == _symbol(sym)->name())
240 return sym; // Yes. Return it
243 // Nope. Make a new one.
244 pmt_t sym = pmt_t(new pmt_symbol(name));
245 _symbol(sym)->set_next(s_symbol_hash_table[hash]);
246 s_symbol_hash_table[hash] = sym;
252 pmt_intern(const std::string &name)
254 return pmt_string_to_symbol(name);
258 pmt_symbol_to_string(const pmt_t& sym)
260 if (!sym->is_symbol())
261 throw pmt_wrong_type("pmt_symbol_to_string", sym);
263 return _symbol(sym)->name();
268 ////////////////////////////////////////////////////////////////////////////
270 ////////////////////////////////////////////////////////////////////////////
273 pmt_is_number(pmt_t x)
275 return x->is_number();
278 ////////////////////////////////////////////////////////////////////////////
280 ////////////////////////////////////////////////////////////////////////////
282 pmt_integer::pmt_integer(long value) : d_value(value) {}
285 pmt_is_integer(pmt_t x)
287 return x->is_integer();
292 pmt_from_long(long x)
294 return pmt_t(new pmt_integer(x));
300 pmt_integer* i = dynamic_cast<pmt_integer*>(x.get());
304 throw pmt_wrong_type("pmt_to_long", x);
307 ////////////////////////////////////////////////////////////////////////////
309 ////////////////////////////////////////////////////////////////////////////
311 pmt_real::pmt_real(double value) : d_value(value) {}
320 pmt_from_double(double x)
322 return pmt_t(new pmt_real(x));
326 pmt_to_double(pmt_t x)
329 return _real(x)->value();
331 return _integer(x)->value();
333 throw pmt_wrong_type("pmt_to_double", x);
336 ////////////////////////////////////////////////////////////////////////////
338 ////////////////////////////////////////////////////////////////////////////
340 pmt_complex::pmt_complex(std::complex<double> value) : d_value(value) {}
343 pmt_is_complex(pmt_t x)
345 return x->is_complex();
349 pmt_make_rectangular(double re, double im)
351 return pmt_t(new pmt_complex(std::complex<double>(re, im)));
355 pmt_to_complex(pmt_t x)
358 return _complex(x)->value();
360 return _real(x)->value();
362 return _integer(x)->value();
364 throw pmt_wrong_type("pmt_to_complex", x);
367 ////////////////////////////////////////////////////////////////////////////
369 ////////////////////////////////////////////////////////////////////////////
371 pmt_null::pmt_null() {}
372 pmt_pair::pmt_pair(const pmt_t& car, const pmt_t& cdr) : d_car(car), d_cdr(cdr) {}
375 pmt_is_null(const pmt_t& x)
381 pmt_is_pair(const pmt_t& obj)
383 return obj->is_pair();
387 pmt_cons(const pmt_t& x, const pmt_t& y)
389 return pmt_t(new pmt_pair(x, y));
393 pmt_car(const pmt_t& pair)
395 pmt_pair* p = dynamic_cast<pmt_pair*>(pair.get());
399 throw pmt_wrong_type("pmt_car", pair);
403 pmt_cdr(const pmt_t& pair)
405 pmt_pair* p = dynamic_cast<pmt_pair*>(pair.get());
409 throw pmt_wrong_type("pmt_cdr", pair);
413 pmt_set_car(pmt_t pair, pmt_t obj)
416 _pair(pair)->set_car(obj);
418 throw pmt_wrong_type("pmt_set_car", pair);
422 pmt_set_cdr(pmt_t pair, pmt_t obj)
425 _pair(pair)->set_cdr(obj);
427 throw pmt_wrong_type("pmt_set_cdr", pair);
430 ////////////////////////////////////////////////////////////////////////////
432 ////////////////////////////////////////////////////////////////////////////
434 pmt_vector::pmt_vector(size_t len, pmt_t fill)
437 for (size_t i = 0; i < len; i++)
442 pmt_vector::ref(size_t k) const
445 throw pmt_out_of_range("pmt_vector_ref", pmt_from_long(k));
450 pmt_vector::set(size_t k, pmt_t obj)
453 throw pmt_out_of_range("pmt_vector_set", pmt_from_long(k));
458 pmt_vector::fill(pmt_t obj)
460 for (size_t i = 0; i < length(); i++)
465 pmt_is_vector(pmt_t obj)
467 return obj->is_vector();
471 pmt_make_vector(size_t k, pmt_t fill)
473 return pmt_t(new pmt_vector(k, fill));
477 pmt_vector_ref(pmt_t vector, size_t k)
479 if (!vector->is_vector())
480 throw pmt_wrong_type("pmt_vector_ref", vector);
481 return _vector(vector)->ref(k);
485 pmt_vector_set(pmt_t vector, size_t k, pmt_t obj)
487 if (!vector->is_vector())
488 throw pmt_wrong_type("pmt_vector_set", vector);
489 _vector(vector)->set(k, obj);
493 pmt_vector_fill(pmt_t vector, pmt_t obj)
495 if (!vector->is_vector())
496 throw pmt_wrong_type("pmt_vector_set", vector);
497 _vector(vector)->fill(obj);
500 ////////////////////////////////////////////////////////////////////////////
502 ////////////////////////////////////////////////////////////////////////////
504 pmt_tuple::pmt_tuple(size_t len)
510 pmt_tuple::ref(size_t k) const
513 throw pmt_out_of_range("pmt_tuple_ref", pmt_from_long(k));
518 pmt_is_tuple(pmt_t obj)
520 return obj->is_tuple();
524 pmt_tuple_ref(const pmt_t &tuple, size_t k)
526 if (!tuple->is_tuple())
527 throw pmt_wrong_type("pmt_tuple_ref", tuple);
528 return _tuple(tuple)->ref(k);
531 // for (i=0; i < 10; i++)
532 // make_constructor()
537 return pmt_t(new pmt_tuple(0));
541 pmt_make_tuple(const pmt_t &e0)
543 pmt_tuple *t = new pmt_tuple(1);
549 pmt_make_tuple(const pmt_t &e0, const pmt_t &e1)
551 pmt_tuple *t = new pmt_tuple(2);
558 pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2)
560 pmt_tuple *t = new pmt_tuple(3);
568 pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3)
570 pmt_tuple *t = new pmt_tuple(4);
579 pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3, const pmt_t &e4)
581 pmt_tuple *t = new pmt_tuple(5);
591 pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3, const pmt_t &e4, const pmt_t &e5)
593 pmt_tuple *t = new pmt_tuple(6);
604 pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3, const pmt_t &e4, const pmt_t &e5, const pmt_t &e6)
606 pmt_tuple *t = new pmt_tuple(7);
618 pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3, const pmt_t &e4, const pmt_t &e5, const pmt_t &e6, const pmt_t &e7)
620 pmt_tuple *t = new pmt_tuple(8);
633 pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3, const pmt_t &e4, const pmt_t &e5, const pmt_t &e6, const pmt_t &e7, const pmt_t &e8)
635 pmt_tuple *t = new pmt_tuple(9);
649 pmt_make_tuple(const pmt_t &e0, const pmt_t &e1, const pmt_t &e2, const pmt_t &e3, const pmt_t &e4, const pmt_t &e5, const pmt_t &e6, const pmt_t &e7, const pmt_t &e8, const pmt_t &e9)
651 pmt_tuple *t = new pmt_tuple(10);
666 pmt_to_tuple(const pmt_t &x)
668 if (x->is_tuple()) // already one
671 size_t len = pmt_length(x);
672 pmt_tuple *t = new pmt_tuple(len);
676 for (size_t i = 0; i < len; i++)
677 t->_set(i, _vector(x)->ref(i));
683 for (size_t i = 0; i < len; i++){
684 t->_set(i, pmt_car(y));
690 throw pmt_wrong_type("pmt_to_tuple", x);
695 ////////////////////////////////////////////////////////////////////////////
696 // Uniform Numeric Vectors
697 ////////////////////////////////////////////////////////////////////////////
700 pmt_is_uniform_vector(pmt_t x)
702 return x->is_uniform_vector();
706 pmt_uniform_vector_elements(pmt_t vector, size_t &len)
708 if (!vector->is_uniform_vector())
709 throw pmt_wrong_type("pmt_uniform_vector_elements", vector);
710 return _uniform_vector(vector)->uniform_elements(len);
714 pmt_uniform_vector_writable_elements(pmt_t vector, size_t &len)
716 if (!vector->is_uniform_vector())
717 throw pmt_wrong_type("pmt_uniform_vector_writable_elements", vector);
718 return _uniform_vector(vector)->uniform_writable_elements(len);
721 ////////////////////////////////////////////////////////////////////////////
723 ////////////////////////////////////////////////////////////////////////////
726 * This is an a-list implementation.
728 * When we need better performance for large dictionaries, consider implementing
729 * persistent Red-Black trees as described in "Purely Functional Data Structures",
730 * Chris Okasaki, 1998, section 3.3.
734 pmt_is_dict(const pmt_t &obj)
736 return pmt_is_null(obj) || pmt_is_pair(obj);
746 pmt_dict_add(const pmt_t &dict, const pmt_t &key, const pmt_t &value)
748 if (pmt_is_null(dict))
749 return pmt_acons(key, value, PMT_NIL);
751 if (pmt_dict_has_key(dict, key))
752 return pmt_acons(key, value, pmt_dict_delete(dict, key));
754 return pmt_acons(key, value, dict);
758 pmt_dict_delete(const pmt_t &dict, const pmt_t &key)
760 if (pmt_is_null(dict))
763 if (pmt_eqv(pmt_caar(dict), key))
764 return pmt_cdr(dict);
766 return pmt_cons(pmt_car(dict), pmt_dict_delete(pmt_cdr(dict), key));
770 pmt_dict_ref(const pmt_t &dict, const pmt_t &key, const pmt_t ¬_found)
772 pmt_t p = pmt_assv(key, dict); // look for (key . value) pair
780 pmt_dict_has_key(const pmt_t &dict, const pmt_t &key)
782 return pmt_is_pair(pmt_assv(key, dict));
786 pmt_dict_items(pmt_t dict)
788 if (!pmt_is_dict(dict))
789 throw pmt_wrong_type("pmt_dict_values", dict);
791 return dict; // equivalent to dict in the a-list case
795 pmt_dict_keys(pmt_t dict)
797 if (!pmt_is_dict(dict))
798 throw pmt_wrong_type("pmt_dict_keys", dict);
800 return pmt_map(pmt_car, dict);
804 pmt_dict_values(pmt_t dict)
806 if (!pmt_is_dict(dict))
807 throw pmt_wrong_type("pmt_dict_keys", dict);
809 return pmt_map(pmt_cdr, dict);
812 ////////////////////////////////////////////////////////////////////////////
814 ////////////////////////////////////////////////////////////////////////////
816 pmt_any::pmt_any(const boost::any &any) : d_any(any) {}
819 pmt_is_any(pmt_t obj)
821 return obj->is_any();
825 pmt_make_any(const boost::any &any)
827 return pmt_t(new pmt_any(any));
831 pmt_any_ref(pmt_t obj)
834 throw pmt_wrong_type("pmt_any_ref", obj);
835 return _any(obj)->ref();
839 pmt_any_set(pmt_t obj, const boost::any &any)
842 throw pmt_wrong_type("pmt_any_set", obj);
846 ////////////////////////////////////////////////////////////////////////////
847 // msg_accepter -- built from "any"
848 ////////////////////////////////////////////////////////////////////////////
851 pmt_is_msg_accepter(const pmt_t &obj)
853 if (!pmt_is_any(obj))
856 boost::any r = pmt_any_ref(obj);
857 return boost::any_cast<gruel::msg_accepter_sptr>(&r) != 0;
860 //! make a msg_accepter
862 pmt_make_msg_accepter(gruel::msg_accepter_sptr ma)
864 return pmt_make_any(ma);
867 //! Return underlying msg_accepter
868 gruel::msg_accepter_sptr
869 pmt_msg_accepter_ref(const pmt_t &obj)
872 return boost::any_cast<gruel::msg_accepter_sptr>(pmt_any_ref(obj));
874 catch (boost::bad_any_cast &e){
875 throw pmt_wrong_type("pmt_msg_accepter_ref", obj);
880 ////////////////////////////////////////////////////////////////////////////
881 // Binary Large Object -- currently a u8vector
882 ////////////////////////////////////////////////////////////////////////////
887 // return pmt_is_u8vector(x);
888 return pmt_is_uniform_vector(x);
892 pmt_make_blob(const void *buf, size_t len_in_bytes)
894 return pmt_init_u8vector(len_in_bytes, (const uint8_t *) buf);
898 pmt_blob_data(pmt_t blob)
901 return pmt_uniform_vector_elements(blob, len);
905 pmt_blob_length(pmt_t blob)
908 pmt_uniform_vector_elements(blob, len);
913 ////////////////////////////////////////////////////////////////////////////
915 ////////////////////////////////////////////////////////////////////////////
918 pmt_eq(const pmt_t& x, const pmt_t& y)
924 pmt_eqv(const pmt_t& x, const pmt_t& y)
929 if (x->is_integer() && y->is_integer())
930 return _integer(x)->value() == _integer(y)->value();
932 if (x->is_real() && y->is_real())
933 return _real(x)->value() == _real(y)->value();
935 if (x->is_complex() && y->is_complex())
936 return _complex(x)->value() == _complex(y)->value();
942 pmt_eqv_raw(pmt_base *x, pmt_base *y)
947 if (x->is_integer() && y->is_integer())
948 return _integer(x)->value() == _integer(y)->value();
950 if (x->is_real() && y->is_real())
951 return _real(x)->value() == _real(y)->value();
953 if (x->is_complex() && y->is_complex())
954 return _complex(x)->value() == _complex(y)->value();
960 pmt_equal(const pmt_t& x, const pmt_t& y)
965 if (x->is_pair() && y->is_pair())
966 return pmt_equal(pmt_car(x), pmt_car(y)) && pmt_equal(pmt_cdr(x), pmt_cdr(y));
968 if (x->is_vector() && y->is_vector()){
969 pmt_vector *xv = _vector(x);
970 pmt_vector *yv = _vector(y);
971 if (xv->length() != yv->length())
974 for (unsigned i = 0; i < xv->length(); i++)
975 if (!pmt_equal(xv->_ref(i), yv->_ref(i)))
981 if (x->is_tuple() && y->is_tuple()){
982 pmt_tuple *xv = _tuple(x);
983 pmt_tuple *yv = _tuple(y);
984 if (xv->length() != yv->length())
987 for (unsigned i = 0; i < xv->length(); i++)
988 if (!pmt_equal(xv->_ref(i), yv->_ref(i)))
994 if (x->is_uniform_vector() && y->is_uniform_vector()){
995 pmt_uniform_vector *xv = _uniform_vector(x);
996 pmt_uniform_vector *yv = _uniform_vector(y);
997 if (xv->length() != yv->length())
1000 size_t len_x, len_y;
1001 if (memcmp(xv->uniform_elements(len_x),
1002 yv->uniform_elements(len_y),
1009 // FIXME add other cases here...
1015 pmt_length(const pmt_t& x)
1018 return _vector(x)->length();
1020 if (x->is_uniform_vector())
1021 return _uniform_vector(x)->length();
1024 return _tuple(x)->length();
1031 pmt_t it = pmt_cdr(x);
1032 while (pmt_is_pair(it)){
1036 if (pmt_is_null(it))
1039 // not a proper list
1040 throw pmt_wrong_type("pmt_length", x);
1043 // FIXME dictionary length (number of entries)
1045 throw pmt_wrong_type("pmt_length", x);
1049 pmt_assq(pmt_t obj, pmt_t alist)
1051 while (pmt_is_pair(alist)){
1052 pmt_t p = pmt_car(alist);
1053 if (!pmt_is_pair(p)) // malformed alist
1056 if (pmt_eq(obj, pmt_car(p)))
1059 alist = pmt_cdr(alist);
1065 * This avoids a bunch of shared_pointer reference count manipulation.
1068 pmt_assv_raw(pmt_base *obj, pmt_base *alist)
1070 while (alist->is_pair()){
1071 pmt_base *p = ((pmt_pair *)alist)->d_car.get();
1072 if (!p->is_pair()) // malformed alist
1075 if (pmt_eqv_raw(obj, ((pmt_pair *)p)->d_car.get()))
1076 return ((pmt_pair *)alist)->d_car;
1078 alist = (((pmt_pair *)alist)->d_cdr).get();
1086 pmt_assv(pmt_t obj, pmt_t alist)
1088 return pmt_assv_raw(obj.get(), alist.get());
1094 pmt_assv(pmt_t obj, pmt_t alist)
1096 while (pmt_is_pair(alist)){
1097 pmt_t p = pmt_car(alist);
1098 if (!pmt_is_pair(p)) // malformed alist
1101 if (pmt_eqv(obj, pmt_car(p)))
1104 alist = pmt_cdr(alist);
1113 pmt_assoc(pmt_t obj, pmt_t alist)
1115 while (pmt_is_pair(alist)){
1116 pmt_t p = pmt_car(alist);
1117 if (!pmt_is_pair(p)) // malformed alist
1120 if (pmt_equal(obj, pmt_car(p)))
1123 alist = pmt_cdr(alist);
1129 pmt_map(pmt_t proc(const pmt_t&), pmt_t list)
1133 while(pmt_is_pair(list)){
1134 r = pmt_cons(proc(pmt_car(list)), r);
1135 list = pmt_cdr(list);
1138 return pmt_reverse_x(r);
1142 pmt_reverse(pmt_t listx)
1147 while(pmt_is_pair(list)){
1148 r = pmt_cons(pmt_car(list), r);
1149 list = pmt_cdr(list);
1151 if (pmt_is_null(list))
1154 throw pmt_wrong_type("pmt_reverse", listx);
1158 pmt_reverse_x(pmt_t list)
1160 // FIXME do it destructively
1161 return pmt_reverse(list);
1165 pmt_nth(size_t n, pmt_t list)
1167 pmt_t t = pmt_nthcdr(n, list);
1175 pmt_nthcdr(size_t n, pmt_t list)
1177 if (!(pmt_is_pair(list) || pmt_is_null(list)))
1178 throw pmt_wrong_type("pmt_nthcdr", list);
1181 if (pmt_is_pair(list)){
1182 list = pmt_cdr(list);
1186 if (pmt_is_null(list))
1189 throw pmt_wrong_type("pmt_nthcdr: not a LIST", list);
1195 pmt_memq(pmt_t obj, pmt_t list)
1197 while (pmt_is_pair(list)){
1198 if (pmt_eq(obj, pmt_car(list)))
1200 list = pmt_cdr(list);
1206 pmt_memv(pmt_t obj, pmt_t list)
1208 while (pmt_is_pair(list)){
1209 if (pmt_eqv(obj, pmt_car(list)))
1211 list = pmt_cdr(list);
1217 pmt_member(pmt_t obj, pmt_t list)
1219 while (pmt_is_pair(list)){
1220 if (pmt_equal(obj, pmt_car(list)))
1222 list = pmt_cdr(list);
1228 pmt_subsetp(pmt_t list1, pmt_t list2)
1230 while (pmt_is_pair(list1)){
1231 pmt_t p = pmt_car(list1);
1232 if (pmt_is_false(pmt_memv(p, list2)))
1234 list1 = pmt_cdr(list1);
1240 pmt_list1(const pmt_t& x1)
1242 return pmt_cons(x1, PMT_NIL);
1246 pmt_list2(const pmt_t& x1, const pmt_t& x2)
1248 return pmt_cons(x1, pmt_cons(x2, PMT_NIL));
1252 pmt_list3(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3)
1254 return pmt_cons(x1, pmt_cons(x2, pmt_cons(x3, PMT_NIL)));
1258 pmt_list4(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4)
1260 return pmt_cons(x1, pmt_cons(x2, pmt_cons(x3, pmt_cons(x4, PMT_NIL))));
1264 pmt_list5(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4, const pmt_t& x5)
1266 return pmt_cons(x1, pmt_cons(x2, pmt_cons(x3, pmt_cons(x4, pmt_cons(x5, PMT_NIL)))));
1270 pmt_list6(const pmt_t& x1, const pmt_t& x2, const pmt_t& x3, const pmt_t& x4, const pmt_t& x5, const pmt_t& x6)
1272 return pmt_cons(x1, pmt_cons(x2, pmt_cons(x3, pmt_cons(x4, pmt_cons(x5, pmt_cons(x6, PMT_NIL))))));
1276 pmt_list_add(pmt_t list, const pmt_t& item)
1278 return pmt_reverse(pmt_cons(item, pmt_reverse(list)));
1282 pmt_caar(pmt_t pair)
1284 return (pmt_car(pmt_car(pair)));
1288 pmt_cadr(pmt_t pair)
1290 return pmt_car(pmt_cdr(pair));
1294 pmt_cdar(pmt_t pair)
1296 return pmt_cdr(pmt_car(pair));
1300 pmt_cddr(pmt_t pair)
1302 return pmt_cdr(pmt_cdr(pair));
1306 pmt_caddr(pmt_t pair)
1308 return pmt_car(pmt_cdr(pmt_cdr(pair)));
1312 pmt_cadddr(pmt_t pair)
1314 return pmt_car(pmt_cdr(pmt_cdr(pmt_cdr(pair))));
1318 pmt_is_eof_object(pmt_t obj)
1320 return pmt_eq(obj, PMT_EOF);
1326 printf("sizeof(pmt_t) = %3zd\n", sizeof(pmt_t));
1327 printf("sizeof(pmt_base) = %3zd\n", sizeof(pmt_base));
1328 printf("sizeof(pmt_bool) = %3zd\n", sizeof(pmt_bool));
1329 printf("sizeof(pmt_symbol) = %3zd\n", sizeof(pmt_symbol));
1330 printf("sizeof(pmt_integer) = %3zd\n", sizeof(pmt_integer));
1331 printf("sizeof(pmt_real) = %3zd\n", sizeof(pmt_real));
1332 printf("sizeof(pmt_complex) = %3zd\n", sizeof(pmt_complex));
1333 printf("sizeof(pmt_null) = %3zd\n", sizeof(pmt_null));
1334 printf("sizeof(pmt_pair) = %3zd\n", sizeof(pmt_pair));
1335 printf("sizeof(pmt_vector) = %3zd\n", sizeof(pmt_vector));
1336 printf("sizeof(pmt_uniform_vector) = %3zd\n", sizeof(pmt_uniform_vector));
1339 } /* namespace pmt */