boeckmann / asm6502

Small but useful 6502 assembler in ~3K lines of ANSI C code.
MIT License
5 stars 2 forks source link

Implement ?: operator #25

Closed boeckmann closed 1 year ago

boeckmann commented 1 year ago

expr ?: default returns expr, if it is defined. It returns default, if expr is not defined Makes the following convinient:

BORDER_COLOR = BORDER_COLOR ?: 6
boeckmann commented 1 year ago

While this is nice it is nothing that can not be done with an .IFNDEF. Also it is not so common.

waltje commented 1 year ago

Hahaha!

This gives opportunity to some fun:

    FOO = C64 ?: APPLE2 ?: $DEAD     .echo "Haha, foo is ",[$]FOO

On the commandline, with a -DC64=100 and/or  -DAPPLE2=2 you can create fun output.

For real use, this could be used to "get" the type of target into a single variable, based on what target was -D'd on the commandline..

boeckmann commented 1 year ago

Yeah, it has some nice characteristics. Do you think its useful? Would prevent some IF cascades. I am in doubt if it is worth implementing.

waltje commented 1 year ago

It is already implemented - the expressions are iterative, so it does not matter if you use it once or 10 times in a single statement.

It is like

   foo = (..) ? x : (..) ? y : (..) ? z : -1

in C.  Gets tedious, but does work and saves a LOT of "iffing".