Commit 85130616 authored by Juergen Nickelsen's avatar Juergen Nickelsen
Browse files

builtin apropos; #<undefined> -> #<unbound>; optimized princ_string

for symbols (as before for strings); make describe print information
about the name of a symbol
parent 521b3540
......@@ -568,6 +568,24 @@ obp_t bf_measure(obp_t args, obp_t out_port, int level)
return result;
}
obp_t bf_apropos(obp_t args, obp_t out_port, int level)
{
obp_t pattern = princ_string(CAR(args));
Lstring_t *search = AS(pattern, STRING);
hashmap_t syms = AS(symbols, MAP)->map;
entptr_t entry;
obp_t result = the_Nil;
hashmap_enum_start(syms);
while ((entry = hashmap_enum_next(syms))) {
obp_t name = entry_get_key(entry);
if (strstr(AS(name, STRING)->content, search->content)) {
result = cons(entry_get_value(entry), result);
}
}
return result;
}
obp_t bf_funcall(obp_t args, obp_t out_port, int level)
{
obp_t fun = CAR(args);
......@@ -1033,6 +1051,7 @@ void init_builtins(void)
register_builtin(PRINCS_NAME, bf_princs, 0, 1, 2);
register_builtin(DESCRIBE_NAME, bf_describe, 0, 1, 2);
register_builtin(LENGTH_NAME, bf_length, 0, 1, 1);
register_builtin(APROPOS_NAME, bf_apropos, 0, 1, 1);
gettimeofday(&start_time, 0);
}
......
......@@ -2,7 +2,7 @@
#define STDOUT_PORT_NAME "*stdout-port*"
#define STDERR_PORT_NAME "*stderr-port*"
#define STDIN_PORT_NAME "*stdin-port*"
#define UNDEF_OBJECT_NAME "#<undefined>"
#define UNBOUND_VALUE_NAME "#<unbound>"
#define NIL_NAME "nil"
#define T_NAME "t"
#define QUOTE_NAME "quote"
......@@ -73,3 +73,4 @@
#define PRINCS_NAME "princs"
#define DESCRIBE_NAME "describe"
#define LENGTH_NAME "length"
#define APROPOS_NAME "apropos"
......@@ -328,6 +328,9 @@ obp_t princ_string(obp_t ob)
if (IS(ob, STRING)) {
return ob;
}
if (IS(ob, SYMBOL)) {
return AS(ob, SYMBOL)->name;
}
return to_string(ob, 0);
}
......@@ -361,7 +364,7 @@ char *blanks(int n)
strbuf_t describe_ob(obp_t ob, strbuf_t sb)
{
if (ob == 0) {
return strbuf_append(sb, UNDEF_OBJECT_NAME "\n");
return strbuf_append(sb, UNBOUND_VALUE_NAME "\n");
}
sprintf(tmp_buf, "ob %p type %d %s mark %d eq %d r/o %d size %d: ",
ob, ob->type, type_name(ob->type), ob->mark,
......@@ -370,11 +373,13 @@ strbuf_t describe_ob(obp_t ob, strbuf_t sb)
sb = s_expr(ob, sb, TOSTRING_READ);
sb = strbuf_addc(sb, '\n');
if (IS(ob, SYMBOL)) {
sb = strbuf_append(sb , " value: ");
sb = strbuf_append(sb, " name: ");
sb = describe_ob(AS(ob, SYMBOL)->name, sb);
sb = strbuf_append(sb, " value: ");
sb = describe_ob(AS(ob, SYMBOL)->value, sb);
sb = strbuf_append(sb , " function: ");
sb = strbuf_append(sb, " function: ");
sb = describe_ob(AS(ob, SYMBOL)->function, sb);
sb = strbuf_append(sb , " props: ");
sb = strbuf_append(sb, " props: ");
sb = describe_ob(AS(ob, SYMBOL)->props, sb);
}
return sb;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment