From 3c97d2982cc2bfcc959d9d20a4075297a2b015df Mon Sep 17 00:00:00 2001 From: Kodi Arfer Date: Sun, 4 Mar 2018 14:44:56 -0800 Subject: [PATCH] Use `*1` instead of `_` for REPL history `_`, as a variable, is now the shadow subtraction operator. --- NEWS.rst | 4 ++++ hy/cmdline.py | 4 ++-- tests/test_bin.py | 5 +++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/NEWS.rst b/NEWS.rst index a1b503f..d41a3d0 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -5,6 +5,10 @@ Unreleased Other Breaking Changes ------------------------------ +* `_` and `-` are now equivalent as single-character names + + * The REPL history variable `_` is now `*1` + * Non-shadow unary `=`, `is`, `<`, etc. now evaluate their argument instead of ignoring it. This change increases consistency a bit and makes accidental unary uses easier to notice. diff --git a/hy/cmdline.py b/hy/cmdline.py index 40fede5..75fe09a 100644 --- a/hy/cmdline.py +++ b/hy/cmdline.py @@ -112,8 +112,8 @@ class HyREPL(code.InteractiveConsole): if value is not None: # Make the last non-None value available to - # the user as `_`. - self.locals['_'] = value + # the user as `*1`. + self.locals[mangle("*1")] = value # Print the value. try: output = self.output_fn(value) diff --git a/tests/test_bin.py b/tests/test_bin.py index 33701ea..94411cc 100644 --- a/tests/test_bin.py +++ b/tests/test_bin.py @@ -74,6 +74,11 @@ def test_bin_hy_stdin_multiline(): assert "'abcd'" in output +def test_bin_hy_history(): + output, _ = run_cmd("hy", '(+ "a" "b")\n(+ *1 "y" "z")') + assert "'abyz'" in output + + def test_bin_hy_stdin_comments(): _, err_empty = run_cmd("hy", '')