ID:2112350
 
Resolved
Applies to:DM Language
Status: Resolved

This issue has been resolved.
Syntactic sugar:
A ||= B // read as "A defaults to B"

Equivalent to:
A = A || B // "set A to A or B"

Also equivalent to:
if(!A) A = B // "if A is falsey, set A to B"

but doesn't repeat A. :)

Useful for when you want to lazy-initialize lists or other objects, especially if the variable has a really long name:
var lazy_list[]

proc
AddToLazyList(Item)
// lazy_list = lazy_list || new
lazy_list ||= new
lazy_list += Item

RemoveFromLazyList(Item)
if(lazy_list)
lazy_list -= Item
lazy_list = lazy_list.len && lazy_list // potential &&= operator? backwards tho
Looks fancy, and seems like a nice idea imo. +1
I kinda want this myself. It may be an easy thing to add.

The main thing is, I think I wouldn't want it to compile with new instructions, but rather I'd prefer it to compile in the if(!A) A=B form. That's because the || and && operators are shortcut operators, and will jump past code they don't need to evaluate.
Definitely a good idea.

Could we get a &&= too? It's have less use cases but it can probably come in handy somewhere.
Supported. This would be very useful.
Lummox JR resolved issue