gbdev / gbdev/rgbds

[Feature request] Ternary operator

Open
#621 11 comments 2 reactions 0 assignees View on GitHub
enhancement rgbasm rgblink
Dominant language
C++
Stars
1.6k
Forks
193
Avg merge
1d 33m
Merged PRs (30d)
23

Description

This would be mostly useful for within user-defined functions (#201), but would also be more terse than the current `if/else/endc`.

Example:

```
giveitem: MACRO
db giveitem_command
db \1 ; item
if _NARG == 2
db \2 ; quantity
else
db 1 ; quantity
endc
ENDM

; simplifies to

giveitem: MACRO
db giveitem_command
db \1 ; item
db _NARG == 2 ? \2 : 1 ; quantity
ENDM
```

```
growth_rate: MACRO
; [1]/[2]*n**3 + [3]*n**2 + [4]*n - [5]
dn \1, \2
if \3 & $80 ; signed
db -\3 | $80
else
db \3
endc
db \4, \5
ENDM

; simplifies to

growth_rate: MACRO
; [1]/[2]*n**3 + [3]*n**2 + [4]*n - [5]
dn \1, \2
db \3 & $80 ? -\3 | $80 : \3 ; signed
db \4, \5
ENDM
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.