diff options
-rw-r--r-- | eval.c | 1 | ||||
-rw-r--r-- | lib.c | 10 | ||||
-rw-r--r-- | lib.h | 3 | ||||
-rw-r--r-- | stdlib/doc-syms.tl | 1 | ||||
-rw-r--r-- | stdlib/struct.tl | 2 | ||||
-rw-r--r-- | struct.c | 2 | ||||
-rw-r--r-- | txr.1 | 15 |
7 files changed, 25 insertions, 9 deletions
@@ -6771,6 +6771,7 @@ void eval_init(void) reg_fun(intern(lit("typeof"), user_package), func_n1(typeof)); reg_fun(intern(lit("subtypep"), user_package), func_n2(subtypep)); reg_fun(intern(lit("typep"), user_package), func_n2(typep)); + reg_fun(intern(lit("built-in-type-p"), user_package), func_n1(built_in_type_p)); reg_fun(intern(lit("atom"), user_package), func_n1(atom)); reg_fun(intern(lit("null"), user_package), null_f); @@ -209,7 +209,7 @@ static val code2type(int code) return nil; } -val builtin_type_p(val sym) +val built_in_type_p(val sym) { type_t i; @@ -219,6 +219,9 @@ val builtin_type_p(val sym) return t; } + if (gethash(cobj_hash, sym)) + return t; + return nil; } @@ -9206,11 +9209,6 @@ static void cobj_populate_hash(void) sethash(cobj_hash, ptr->cls_sym, num_fast(ptr - cobj_class)); } -int cobj_class_exists(val cls_sym) -{ - return gethash(cobj_hash, cls_sym) != nil; -} - val cobj(mem_t *handle, struct cobj_class *cls, struct cobj_ops *ops) { if (cls != 0) { @@ -563,7 +563,7 @@ extern alloc_bytes_t malloc_bytes; extern alloc_bytes_t gc_bytes; val identity(val obj); -val builtin_type_p(val sym); +val built_in_type_p(val sym); val typeof(val obj); val subtypep(val sub, val sup); val typep(val obj, val type); @@ -1100,7 +1100,6 @@ val length_str_lt(val str, val len); val length_str_le(val str, val len); struct cobj_class *cobj_register(val cls_sym); struct cobj_class *cobj_register_super(val cls_sym, struct cobj_class *super); -int cobj_class_exists(val cls_sym); val cobj(mem_t *handle, struct cobj_class *cls, struct cobj_ops *ops); val cobjp(val obj); val cobjclassp(val obj, struct cobj_class *); diff --git a/stdlib/doc-syms.tl b/stdlib/doc-syms.tl index 829e418a..e1a5d5a0 100644 --- a/stdlib/doc-syms.tl +++ b/stdlib/doc-syms.tl @@ -233,6 +233,7 @@ ("build" "N-01346AAA") ("build-list" "N-0315C467") ("buildn" "N-01346AAA") + ("built-in-type-p" "N-011BB3FF") ("butlast" "N-026BB6FA") ("butlastn" "N-01E2C334") ("caar" "N-001FA3CB") diff --git a/stdlib/struct.tl b/stdlib/struct.tl index bd62637f..9108ab02 100644 --- a/stdlib/struct.tl +++ b/stdlib/struct.tl @@ -39,6 +39,8 @@ (atom (list atom nil))) (unless (bindable name) (compile-error form "~s isn't a bindable symbol" name)) + (if (built-in-type-p name) + (compile-warning form "~s is a built-in type" name)) (unless (proper-listp slot-specs) (compile-error form "bad syntax: dotted form")) (let* ((instance-init-form nil) @@ -439,7 +439,7 @@ val make_struct_type(val name, val supers, lisplib_try_load(name); - if (builtin_type_p(name) || cobj_class_exists(name)) + if (built_in_type_p(name)) uw_throwf(error_s, lit("~a: ~s is a built-in type"), self, name, nao); @@ -19284,6 +19284,21 @@ always matches. If such a clause is placed as the last clause of a it provides a fallback case, whose forms are evaluated if none of the previous clauses match. +.coNP Function @ built-in-type-p +.synb +.mets (built-in-type-p << object ) +.syne +.desc +The +.code built-in-type-p +function returns +.code t +if +.meta object +is a symbol which is the name of a built-in type. +For all other objects it returns +.codn nil . + .SS* Object Equivalence .coNP Functions @, identity @ identity* and @ use |