From b2c449dd6665007d338c51b720ada165f8b37dc5 Mon Sep 17 00:00:00 2001 From: Simon Forman Date: Tue, 6 Apr 2021 11:41:39 -0700 Subject: [PATCH] Print Boolean values with lowercase intitial letters. --- joy/utils/stack.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/joy/utils/stack.py b/joy/utils/stack.py index fc11151..cc00673 100644 --- a/joy/utils/stack.py +++ b/joy/utils/stack.py @@ -72,7 +72,6 @@ printed left-to-right. These functions are written to support :doc:`../pretty`. ''' -from builtins import map def list_to_stack(el, stack=()): '''Convert a Python list (or other sequence) to a Joy stack:: @@ -129,15 +128,25 @@ def expression_to_string(expression): return _to_string(expression, iter_stack) +_JOY_BOOL_LITS = 'false', 'true' + + +def _joy_repr(thing): + if isinstance(thing, bool): + return _JOY_BOOL_LITS[thing] + return repr(thing) + + def _to_string(stack, f): - if not isinstance(stack, tuple): return repr(stack) + if not isinstance(stack, tuple): return _joy_repr(stack) if not stack: return '' # shortcut return ' '.join(map(_s, f(stack))) _s = lambda s: ( - '[%s]' % expression_to_string(s) if isinstance(s, tuple) - else repr(s) + '[%s]' % expression_to_string(s) + if isinstance(s, tuple) + else _joy_repr(s) )