Please enable JavaScript to view this site.

A-Shell Reference

Navigation: A-Shell BASIC (ASB) > Operators

Shortcut Operators

Scroll Prev Top Next More

Using <mask> rewritten February 2020

A-Shell offers the following shortcut operators:

var += <expr>     ! equivalent to var = var + <expr>

var -= <expr>     ! equivalent to var = var - <expr>

var *= <expr>     ! equivalent to var = var * <expr>

var /= <expr>     ! equivalent to var = var / <expr>

var |= <expr>     ! equivalent to var = var OR <expr>

var &= <expr>     ! equivalent to var = var AND <expr>

var #+= <expr>    ! equivalent to var = var #+ <expr>   (explicit addition)

var $+= <expr>    ! equivalent to var = var $+ <expr>   (explicit concatenation)

Comments

These require /X:2 or /RC, but they do not have any compatibility effect on the resulting RUN module. Note that the += operator works equally well for numeric addition as well as string concatenation; see Explicit Operators below.

Operator Precedence

While the shortcut operators do not change anything about the rules of operator precedence, it may make the rules easy to overlook.  (To compound the potential confusion, the compiler handling of shortcut operators changed in compiler edit 970 - see History Notes for details.)

For example, the syntax of the statement:

a *= b + c

may lead one to think of it as equivalent to:

a = a * (b + c)

but since there are no automatic parentheses in the expansion of the shortcut syntax, the actual equivalent is simply this:

a = a * b + c

which, due to the fact that multiplication has higher precedence than addition, is equivalent to this:

a = (a * b) + c

Another potentially confusing case involves USING, e.g.

a *= b + c USING mask$

Since USING has lower precedence than addition, this is equivalent to:

a = ((a * b) + c) USING mask$

When in doubt, add your own parentheses, and if really in doubt, revert to the original equivalent syntax—i.e., without the shortcut operator.

See History Notes below.

Explicit Operators

Shortcut operators #+= and $+= are equivalent to the existing shortcut operator += except that they unambiguously and explicitly specify either addition or concatenation, respectively, regardless of the destination type. For example:

map1 a$,s,10

dimx $num, ordmap(varstr;varstr)

map1 n,f

 

a$ += 1             ! sets a$ = "1"

a$ += 1             ! sets a$ = "11", e.g. "1" + "1"

a$ #+= 2            ! sets a$ = "13", e.g.  val("11") + val("2")

? "a$ = ";a$        ! "13"

 

$num("one") = "1"                  ! sets $num("one") = "1"

$num("one") #+= "1"                ! sets $num("one") = "2"

$num("one") #+= $num("one")        ! sets $num("one") = "4"

? "$num(""one"") = "; $num("one")  ! "4"

 

n += 1              ! n = 1

n #+= $num("one")   ! n = 5, e.g. 1 + val("4")

? "n = ";n          ! 5

 

History

2022 March, A-Shel 6.5.1712, compiler edit 970:  back out edit 958 and remove the parentheses that were previously added by the compiler to the expression on the right side of the shortcut operator.

2021 October, A-Shell 6.5.1708, compiler edit 958:  Implement special handling of a trailing USING operator. Later deleted/superceded by version 6.5.1712.

2020 July, A-Shell 6.5.1686, compiler edit 934:  Added explicit operators #+= and $+=.

2017 May, A-Shell 6.5.1605:  Added vertical bar | and ampersand & shortcut operators.

2010 December, A-Shell 5.1.1195:  Feature added to A-Shell (compiler edit 471)