diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2019-09-06 07:26:03 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2019-09-06 07:26:03 -0700 |
commit | 78d6a6ed5cd8a141fdae8e7f85faeadbd5b177b2 (patch) | |
tree | 21e39400f7f201524f08ff7bdf71cdb17dfaa4c0 /lib.c | |
parent | 1a444721869bca8f94f1a5370b9d177444e35ea8 (diff) | |
download | txr-78d6a6ed5cd8a141fdae8e7f85faeadbd5b177b2.tar.gz txr-78d6a6ed5cd8a141fdae8e7f85faeadbd5b177b2.tar.bz2 txr-78d6a6ed5cd8a141fdae8e7f85faeadbd5b177b2.zip |
subtypep: structs with car or length method are sequences.
* lib.c (subtypep): For the sequence supertype, check
whether the subtype is a structure that has a length or
car method, returning t if so.
* struct.c (get_special_slot_by_type): New function.
* struct.h (get_special_slot_by_type): Declared.
* txr.1: Add <structures with cars or length methods> to the
type hierarchy diagram.
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 7 |
1 files changed, 7 insertions, 0 deletions
@@ -232,6 +232,13 @@ val subtypep(val sub, val sup) } else if (sup == list_s) { return tnil(sub == null_s || sub == cons_s || sub == lcons_s); } else if (sup == sequence_s) { + val sub_struct = find_struct_type(sub); + if (sub_struct) { + if (get_special_slot_by_type(sub_struct, length_m) || + get_special_slot_by_type(sub_struct, car_m)) + return t; + return nil; + } return tnil(sub == str_s || sub == lit_s || sub == lstr_s || sub == vec_s || sub == null_s || sub == cons_s || sub == lcons_s || sub == list_s || sub == string_s); |