From a74474de3902a39daa365cdb6d9f3cdc60b97dcf Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Thu, 19 Oct 2017 15:32:40 -0400 Subject: [PATCH 1/2] deprecate rvalues consisting only of underscores --- NEWS.md | 3 +++ base/client.jl | 4 ++-- src/flisp/julia_extensions.c | 11 +++++++++++ src/jlfrontend.scm | 4 ++-- src/julia-syntax.scm | 6 +++--- 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/NEWS.md b/NEWS.md index 11a56e3b90408..ca8f630574983 100644 --- a/NEWS.md +++ b/NEWS.md @@ -118,6 +118,9 @@ Language changes * `reduce(+, [...])` and `reduce(*, [...])` no longer widen the iterated over arguments to system word size. `sum` and `prod` still preserve this behavior. ([#22825]) + * Like `_`, variable names consisting only of underscores can be assigned, + but accessing their values is deprecated ([]). + Breaking changes ---------------- diff --git a/base/client.jl b/base/client.jl index 29abb482966a8..f38e655724840 100644 --- a/base/client.jl +++ b/base/client.jl @@ -208,8 +208,8 @@ function parse_input_line(s::String; filename::String="none") # expr ex = ccall(:jl_parse_input_line, Any, (Ptr{UInt8}, Csize_t, Ptr{UInt8}, Csize_t), s, sizeof(s), filename, sizeof(filename)) - if ex === :_ - # remove with 0.6 deprecation + if ex isa Symbol && all(equalto('_'), string(ex)) + # remove with 0.7 deprecation expand(Main, ex) # to get possible warning about using _ as an rvalue end return ex diff --git a/src/flisp/julia_extensions.c b/src/flisp/julia_extensions.c index b54c6889ab982..598defd763794 100644 --- a/src/flisp/julia_extensions.c +++ b/src/flisp/julia_extensions.c @@ -210,6 +210,16 @@ value_t fl_julia_strip_op_suffix(fl_context_t *fl_ctx, value_t *args, uint32_t n return opnew_symbol; } +/* check whether arg is a symbol that consists solely of underscores. */ +value_t fl_julia_underscore_symbolp(fl_context_t *fl_ctx, value_t *args, uint32_t nargs) +{ + argcount(fl_ctx, "underscore-symbol?", nargs, 1); + if (!issymbol(args[0])) return fl_ctx->F; + char *op = symbol_name(fl_ctx, args[0]); + while (*op == '_') ++op; + return *op ? fl_ctx->F : fl_ctx->T; +} + #include "julia_charmap.h" utf8proc_int32_t jl_charmap_map(utf8proc_int32_t c, void *ctx) @@ -298,6 +308,7 @@ static const builtinspec_t julia_flisp_func_info[] = { { "identifier-start-char?", fl_julia_identifier_start_char }, { "op-suffix-char?", fl_julia_op_suffix_char }, { "strip-op-suffix", fl_julia_strip_op_suffix }, + { "underscore-symbol?", fl_julia_underscore_symbolp }, { NULL, NULL } }; diff --git a/src/jlfrontend.scm b/src/jlfrontend.scm index e704f540b1500..6942c9fb375d2 100644 --- a/src/jlfrontend.scm +++ b/src/jlfrontend.scm @@ -100,8 +100,8 @@ (or (memq (car e) '(toplevel line module import importall using export error incomplete)) (and (eq? (car e) 'global) (every symbol? (cdr e)))))) - (if (eq? e '_) - (syntax-deprecation #f "_ as an rvalue" "")) + (if (underscore-symbol? e) + (syntax-deprecation #f "underscores as an rvalue" "")) e) (else (let ((last *in-expand*)) diff --git a/src/julia-syntax.scm b/src/julia-syntax.scm index 4d668dc861222..9afa174c4b19f 100644 --- a/src/julia-syntax.scm +++ b/src/julia-syntax.scm @@ -3515,11 +3515,11 @@ f(x) = yt(x) (let ((e1 (if (and arg-map (symbol? e)) (get arg-map e e) e))) - (if (and value (or (eq? e '_) + (if (and value (or (underscore-symbol? e) (and (pair? e) (or (eq? (car e) 'outerref) (eq? (car e) 'globalref)) - (eq? (cadr e) '_)))) - (syntax-deprecation #f (string "_ as an rvalue" (linenode-string current-loc)) + (underscore-symbol? (cadr e))))) + (syntax-deprecation #f (string "underscores as an rvalue" (linenode-string current-loc)) "")) (if (and (not *warn-all-loop-vars*) (has? deprecated-loop-vars e)) (begin (deprecation-message From 8a3ab18c3b1dfb12ee0154f586ee2bf1ef459334 Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Thu, 19 Oct 2017 15:33:48 -0400 Subject: [PATCH 2/2] issue number in NEWS --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index ca8f630574983..f21dc28f6a62b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -119,7 +119,7 @@ Language changes system word size. `sum` and `prod` still preserve this behavior. ([#22825]) * Like `_`, variable names consisting only of underscores can be assigned, - but accessing their values is deprecated ([]). + but accessing their values is deprecated ([#24221]). Breaking changes ----------------