Skip to main content
added 24 characters in body; edited tags
Source Link
Moshe
  • 133
  • 5

I want to assign an expression to a variable, and if it has no value, use some default.

On almost every programming language I can use something like:

let linked_hl_id = hlID(l:linked_group) || 114

But of course it does not work, and the option I found is this eyesore using ternary and 2 lines of assignment:

let linked_hl_id = hlID(l:linked_group)
let linked_hl_id = linked_hl_id ? linked_hl_id : 114

What is a better syntax for that? ThanksUsing NVIM v0.4.4.

Thanks.

I want to assign an expression to a variable, and if it has no value, use some default.

On almost every programming language I can use something like:

let linked_hl_id = hlID(l:linked_group) || 114

But of course it does not work, and the option I found is this eyesore using ternary and 2 lines of assignment:

let linked_hl_id = hlID(l:linked_group)
let linked_hl_id = linked_hl_id ? linked_hl_id : 114

What is a better syntax for that? Thanks.

I want to assign an expression to a variable, and if it has no value, use some default.

On almost every programming language I can use something like:

let linked_hl_id = hlID(l:linked_group) || 114

But of course it does not work, and the option I found is this eyesore using ternary and 2 lines of assignment:

let linked_hl_id = hlID(l:linked_group)
let linked_hl_id = linked_hl_id ? linked_hl_id : 114

What is a better syntax for that? Using NVIM v0.4.4.

Thanks.

added 40 characters in body
Source Link
Moshe
  • 133
  • 5

I want to assign an expression to a variable, and if it has no value, use some default.

On almost every programming language I can use something like:

let linked_hl_id = hlID(l:linked_group) || 114

But of course it does not work, and the option I found is this eyesore using ternary and 2 lines of assignment:

let linked_hl_id = hlID(l:linked_group)
let linked_hl_id = linked_hl_id ? linked_hl_id : 114

What is a better syntax for that? Thanks.

I want to assign an expression to a variable, and if it has no value, use some default.

On almost every programming language I can use something like:

let linked_hl_id = hlID(l:linked_group) || 114

But of course it does not work, and the option I found is this eyesore:

let linked_hl_id = hlID(l:linked_group)
let linked_hl_id = linked_hl_id ? linked_hl_id : 114

What is a better syntax for that? Thanks.

I want to assign an expression to a variable, and if it has no value, use some default.

On almost every programming language I can use something like:

let linked_hl_id = hlID(l:linked_group) || 114

But of course it does not work, and the option I found is this eyesore using ternary and 2 lines of assignment:

let linked_hl_id = hlID(l:linked_group)
let linked_hl_id = linked_hl_id ? linked_hl_id : 114

What is a better syntax for that? Thanks.

Source Link
Moshe
  • 133
  • 5

Define default value to a variable

I want to assign an expression to a variable, and if it has no value, use some default.

On almost every programming language I can use something like:

let linked_hl_id = hlID(l:linked_group) || 114

But of course it does not work, and the option I found is this eyesore:

let linked_hl_id = hlID(l:linked_group)
let linked_hl_id = linked_hl_id ? linked_hl_id : 114

What is a better syntax for that? Thanks.