I have ported the diff sent by Dave Eggum in 2006 to add support
for conditional assignment using ?=.
The following item in the todo list refers to this:
The e-mail thread is here:
https://marc.info/?l=vim-dev&m=116591795423455&w=2
https://github.com/vim/vim/pull/4695
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
I have ported the diff sent by Dave Eggum in 2006 to add support
for conditional assignment using ?=.The following item in the todo list refers to this:
- Add ":let var ?= value", conditional assignment. Patch by Dave Eggum,
2006 Dec 11.
@k-takata commented on this pull request.
In src/eval.c:
> @@ -1487,8 +1488,8 @@ ex_let_const(exarg_T *eap, int is_const) * Assign the typevalue "tv" to the variable or variables at "arg_start". * Handles both "var" with any type and "[var, var; var]" with a list type. * When "nextchars" is not NULL it points to a string with characters that - * must appear after the variable(s). Use "+", "-" or "." for add, subtract - * or concatenate. + * must appear after the variable(s). Use "+", "-", "." or "?" for add, + * subtract concatenate or conditionally assign.
s/subtract/subtract,/
—
You are receiving this because you commented.
Merging #4695 into master will increase coverage by
<.01%.
The diff coverage is100%.
@@ Coverage Diff @@ ## master #4695 +/- ## ========================================== + Coverage 81.35% 81.35% +<.01% ========================================== Files 114 114 Lines 145212 145219 +7 ========================================== + Hits 118130 118136 +6 - Misses 27082 27083 +1
| Impacted Files | Coverage Δ | |
|---|---|---|
| src/eval.c | 86.34% <100%> (+0.02%) |
⬆️ |
| src/profiler.c | 92.69% <0%> (-0.57%) |
⬇️ |
| src/gui_gtk_x11.c | 57.86% <0%> (-0.1%) |
⬇️ |
| src/window.c | 87.33% <0%> (-0.04%) |
⬇️ |
| src/term.c | 79.16% <0%> (+0.05%) |
⬆️ |
| src/if_xcmdsrv.c | 86.17% <0%> (+0.53%) |
⬆️ |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing data
Powered by Codecov. Last update 7964873...0521dc1. Read the comment docs.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.![]()
I usually use get() for this purpose.
let default_value = 42 let g:myplugin_globalvar = get(g:, 'myplugin_globalvar', default_value)
I think get() is enough, but if someone wants this patch,
I want also binary operator for consistency.
let a ?= b let a = a ? b
It doesn't work (because ? is already used for ternary operator a ? b : c).
so I would like to propose ??=.
let a ??= b let a = a ?? b
—
You are receiving this because you commented.
Do not merge this.
if !exists("foo") let foo = "bar" endif
This documentation is NOT right. This implementation is:
let tmp = "bar" if !exists("foo") let foo = tmp endif unlet tmp
For example, if the RHS (right-hand-side) is calling function, the function is always evaluated even if the operator is "?=".
let foo ?= s:bar()
Because this syntax is below.
let tmp = s:bar() if !exists("foo") let foo = tmp endif unlet tmp
i.e. Current implementation does not skip right-hand-side. The 4th argument of set_var_lval is passed as already evaluated value when the set_var_lval will be called. If you want to implement this as your expected, the RHS must not be evaluated.
function s:update() let s:foo = 2 return s:foo endfunction "let s:foo = 1 let s:foo ?= s:update()
You need to change all of the part calling set_var_lval.
—
You are receiving this because you commented.
—
You are receiving this because you commented.
Isn't that ?:, the Elvis operator?
Ah sorry, firstly I see this PR,
I thought let a ?= b is same as let a = a ? a : b (like elvis operator).
My ?? proposal is based on the misunderstanding 😓
In my conclusion, I think ?= is not necessary after all.
I find this operator rather obscure, I can't find it in popular languages.
Also, it's easy enough to use the "if" construct. It's more lines, but it's easier to understand.
I also haven't heard anyone ask for this, and suspect it won't be used much because plugin developers do not know it exists.
Keeping the Vim script language simple is more important, in my opinion.
—
You are receiving this because you commented.