diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-10-20 21:36:33 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2016-10-20 21:36:33 -0700 |
commit | 6d8df2a98bae323078951e4d4268a30b4743e31e (patch) | |
tree | feae27bbcc443512d1ade58098c71bb79baa7727 /eval.c | |
parent | eb6b20a502f7c20b6a5cfc9155dcbf2cb06c895e (diff) | |
download | txr-6d8df2a98bae323078951e4d4268a30b4743e31e.tar.gz txr-6d8df2a98bae323078951e4d4268a30b4743e31e.tar.bz2 txr-6d8df2a98bae323078951e4d4268a30b4743e31e.zip |
Changes to the printing framework.
The print function now takes an optional boolean
for pretty printing.
The print method is also called with a third argument;
hence structures can customize both standard printing
and pretty printing.
* lib.c (obj_print): Take pretty argument, and pass it down
to obj_print_impl. This makes obj_pprint redundant.
(obj_pprint): Function removed: it was identical to obj_print
except for passing t down to obj_print_impl for the
pretty argument. These two wrappers had started small and
got bigger with identical changes done in parallel.
(pprint): New function.
(tostring, dump): Pass nil for pretty argument of obj_print.
(tostringp): Use pprint instead of obj_pprint.
* lib.h (obj_print): Declaration updated.
(obj_pprint): Declaration removed.
(print, pprint): Declared.
* eval.c (prinl): Pass nil for pretty_p argument of obj_print.
Do the stream defaulting here; obj_print doesn't do it.
(pprinl): Pass t for pretty_p argument of obj_print,
and do stream argument defaulting.
(eval_init): Register print to new print function rather
than directly to obj_print.
Register pprint to new pprint function rather than obj_pprint.
* hash.c (hash_print_op): Call obj_print_impl to print
the :equal-based keyword, rather than obj_print. Pass
down the pretty flag. All the other keywords are treated
this way; this fixes an inconsistency.
* match.c (dump_var): Call pprint instead of obj_pprint.
* stream.c (formatv): Call obj_print, with a calculated
pretty argument instead of switching between obj_pprint
and obj_print.
* struct.c (struct_inst_print): Except when in backward
compatibility mode, call the object's print method in both
pretty and regular printing mode, passing the mode as a third
argument.
* tests/012/oop.tl (defstruct animal): Support third argument
in print method. Make it optional because there are some
explicit calls which don't pass the argument.
* txr.1: Documentation updated for print method and the
print function. Revised text for some of the related
functions. Added compat notes.
Diffstat (limited to 'eval.c')
-rw-r--r-- | eval.c | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -4615,14 +4615,14 @@ static val mapf(val fun, struct args *funlist) val prinl(val obj, val stream) { - val ret = obj_print(obj, stream); + val ret = obj_print(obj, default_arg(stream, std_output), nil); put_char(chr('\n'), stream); return ret; } val pprinl(val obj, val stream) { - val ret = obj_pprint(obj, stream); + val ret = obj_print(obj, default_arg(stream, std_output), t); put_char(chr('\n'), stream); return ret; } @@ -5158,8 +5158,8 @@ void eval_init(void) reg_fun(intern(lit("tf"), user_package), func_n0v(tf)); reg_fun(intern(lit("nilf"), user_package), func_n0v(nilf)); - reg_fun(intern(lit("print"), user_package), func_n2o(obj_print, 1)); - reg_fun(intern(lit("pprint"), user_package), func_n2o(obj_pprint, 1)); + reg_fun(intern(lit("print"), user_package), func_n3o(print, 1)); + reg_fun(intern(lit("pprint"), user_package), func_n2o(pprint, 1)); reg_fun(intern(lit("tostring"), user_package), func_n1(tostring)); reg_fun(intern(lit("tostringp"), user_package), func_n1(tostringp)); reg_fun(intern(lit("prinl"), user_package), func_n2o(prinl, 1)); |