Meta
ASnake Documentation
Summary:
Metas are special statements which can create macros or change compiler settings within the script. They are handled at compile-time rather than runtime. Meaning they cannot be changed after a Python script is compiled.
Metas mostly exist to override some of ASnake's design decisions if one does not like them, allowing you to somewhat customize the language. It also allows you to automate certain tedious tasks.
In the future there may be some mechanism to discover the various metas, however for now there it is only covered in the documentation.
All metas are begun with a $
.
Metas have indentation scope, meaning that their effects only occur inside their block.
Boolean Switches:
These metas can be turned on or off using an assignment structure. A $
to mark as a meta, the alias of the meta-name you wish to set (alias is case sensitive), a =
(no aliases like is
), and then the boolean state.
The capitalization of the boolean can be arbitrary, and these aliases only work for metas.
True aliases:
- true
- yes
- on
False aliases:
- false
- no
- off
Here are the following (alphabetical) metas which can be enabled or disabled via boolean switches:
Default Expression With Function:
Setting by default is on
.
Aliases:
- noDefExpOnFunc
- defExpIgnoreFunction
- defaultExpressionIgnoreFunction
- ignoreDefExpFunction
(Default expressions)[default%20expression.html] will trigger when functions are operated on, which makes the assumption the statement has no effect, and thus triggers default expression.
func does return '!!!'
"Hello, World"+func()
# result: Hello, World!!!
$ defaultExpressionIgnoreFunction = True
"Hello, World"+func()
# no result
This meta will disable that trigger; thus not wrapping the line with a default expression.
Ignore Indentation:
Setting by default is off
.
Aliases:
- ignoreIndentation
- ignoreIndent
- noindent
- noIndent
- noIndentation
Covered on the indentation page.
Optimize:
Setting by default is on
, but may be affected by compiler flags.
Aliases:
- optimize
- optimization
- optimizing
Will attempt to turn off or on optimization for the section proceeding it. Due to how the compiler works, this might not isolate a section. Meaning you can turn off optimization for a section but still have it be optimized. However, the optimizer will be discouraged from operating on the section.
Python Compatibility:
Setting by default is off
, but may be affected by compiler flags.
Aliases:
- pythonCompatibility
- pycompat
- pyCompatibility
- pyCompat
- pythonCompat
Attempts to interpret the code as Python code, turning ASnake into a full superset instead of a semi superset. Use this if you are trying to copy and paste in regular Python code, and just want to use ASnake as an optimizing compiler.
Using the --python-compatibility
or -pc
flag with the compiler automatically inserts this meta.
This will turn on Python Function Pass, turn on Python Is, and set Default Expression to nothing.
Python Function Pass
Setting by default is off
.
Aliases:
- funcPass
- funcpass
- passFunction
- functionPass
- pyfunc
- pyFunc
By default ASnake will call a function when it is bare.
myFunc does print "hi!"
myFunc
# result: hi!
Turning this meta on will allow you to directly pass functions.
myFunc does print "hi!"
x = myFunc
x()
# result: hi!
Python is
:
Setting by default is off
.
Aliases:
- pyis
- pythonIs
- pyIs
- isPython
- pythonis
- isIdentity
In ASnake is
is considered either a comparison or assignment based on context. In Python is
is an identity check, which tests if two variables or values refer to the same object. Which is different than to comparing values, as they can have the same value but refer to a different object.
$ pyIs = true
x = ["apple","pair"]
y = ["apple","pair"]
print x is y
# result: False
Special Value:
These metas expect a custom value of some kind. The expected value will differ based on the meta.
As before, it always starts with a $
, then the meta name, then a =
, then the expected value.
$ meta = value
Again, they will be listed alphabetically.
Conditional Version:
Aliases:
- ifVersion
- isVersion
- ifVersionIs
- isVersionIs
- ifVersionGreaterThanOrEqualTo
- ifver
This expects a float representing a Python version. If the version being compiled is greater than or equal to the provided version, the block will compile. Otherwise, it will not compile.
Treat it like a conditional block
$ ifVersion = 3.8
print "hi"
print "there"
# if Python version is at or above 3.8:
# result: "hi"
# result: "there"
# if Python version is below 3.8:
# result "there"
Default Expression:
Aliases:
- defexp
- defaultExpression
- defaultPrint
- expPrint
- defprint
Covered here on the Default Expression page.
Inline Replace:
Aliases:
- inline
- def
This meta is meant as a form of macro replacement, however it replaces with tokens rather than strings.
Expects a $
start, then a def
or inline
, then a custom name (does not share name-space with variables), then a =
, then code.
The assignment takes up the line, and so does not support indentation. You can use various indentation tricks like then
and end
to make one-liners which fit in the meta.
After a inline name assignment, you can use the inline name like an (activate meta)[#activate] to replace it with the provided code value. It's generally recommended that you not have whitespace when calling it, however you can.
Inlines can also contain other inlines.
$ def addTwo = + 2
print 2 $addTwo
# result: 4
$ inline ifFour = if 2 $addTwo is 4 do 'its four'
$ifFour
# result: its four
This is a powerful meta which make for very readable code, and reduce the amount of written code. Perhaps even used create mini (jank) versions of ASnake, like for other natural languages besides English.
Use responsibly, as it can also create spaghetti code just as easily as it can make beautiful code.
Activate:
These metas require no argument or value, just the start of $
then it's meta name.
$meta
Compile Target:
You can change the compile target multiple times within the script.
- Cython aliases:
- Cython
- cython
- Python aliases:
- Python
- python
- ASnake aliases:
- ASnake
- Asnake
- asnake
There should probably be more than that, but this is what is supported right now.
Brackets:
Covered on the indentation page.
Scroll to top