Default Expression

ASnake Documentation

Table Of Contents

Summary:

When an expression has no effect, ASnake assumes you want to trigger a function; which by default is print, but can be changed.

A expression is considered to have no effect when it lacks assignment on variables or literals.

bob = 'bob'
bob
# result: bob
bob * 2
# result: bobob

In the above example, in the compile it wraps print around the expression like print(bob * 2).

Functions:

This does not apply to bare functions, as it is assumed that the function may have intended side-effects if you are calling it that way. However, if you operate on the result of the function but do not assign, the statement would have no effect beyond the function; thus it is assumed you want to trigger a default expression.

two does return 2

two
# no result
two * two
# result: 4

Change Default Expression Function:

You may not want print to be the function to be used when default expression is triggered. Perhaps you want write to a log file, make a network call, or change a global variable. So long as you have a function to handle that, it can be done using a meta parameter.

result = None
changeResult does
    global result
    result = stuff
from stuff

$ defaultExpression = changeResult

123 / 4
result += 2
print result
# result: 32.75

The following are the aliases for the meta of changing the default expression function:

  1. defexp
  2. defaultExpression
  3. defaultPrint
  4. expPrint
  5. defprint

If you do not want default expressions to trigger, you can leave it blank like so:

$ defaultExpression =
12
# no result
Scroll to top