/* structure.c -- Structure interface. */ /* Copyright (c) 1984, Taiichi Yuasa and Masami Hagiya. Copyright (c) 1990, Giuseppe Attardi. Copyright (c) 2001, Juan Jose Garcia Ripoll. ECL is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. See file '../Copyright' for full details. */ #include "ecl.h" /******************************* ------- ******************************/ #ifdef CLOS bool structure_subtypep(cl_object x, cl_object y) { cl_object superiors; if (CLASS_NAME(x) == y) return(TRUE); for (superiors=CLASS_SUPERIORS(x); superiors!=Cnil; superiors=CDR(superiors)) { if (structure_subtypep(CAR(superiors), y)) return(TRUE); } return(FALSE); } #else bool structure_subtypep(cl_object x, cl_object y) { do { if (!SYMBOLP(x)) return(FALSE); if (x == y) return(TRUE); x = get(x, @'si::structure-include', Cnil); } while (x != Cnil); return(FALSE); } #endif /* CLOS */ cl_object si_structure_subtype_p(cl_object x, cl_object y) { @(return ((type_of(x) == T_STRUCTURE && structure_subtypep(STYPE(x), y)) ? Ct : Cnil)) } #ifndef CLOS /* This is only used for printing. Should not cons!! */ cl_object structure_to_list(cl_object x) { cl_object *p, r, s; int i, n; s = getf(SNAME(x)->symbol.plist, @'si::structure-slot-descriptions', Cnil); p = &CDR(r = CONS(SNAME(x), Cnil)); for (i=0, n=SLENGTH(x); !endp(s) && i 0; --i) { l = CDR(l); if (endp(l)) FEtype_error_index(idx); } CAR(l) = v; @(return v) } cl_object si_list_nth(cl_object idx, cl_object x) { /* Used in structure access functions generated by DEFSTRUCT. si:list-nth is similar to nth except that (si:list-nth i x) is error if the length of the list x is less than i. */ cl_fixnum i; cl_object l; assert_type_cons(x); for (i = fixnnint(idx), l = x; i > 0; --i) { l = CDR(l); if (endp(l)) FEtype_error_index(idx); } @(return CAR(l)) }