Accessing Attribute Values

Intermediate Level

This topic is intended for intermediate programmers.

You can get the value of an objects attributes at compile time using the attribute access operator .@.


For example:

Attributes without an argument will have the value true if they are present, and false otherwise.

attributes.asa
@public:
foo ::(){
}

bar ::(){
}

printl(foo.@public);
printl(bar.@public);
Shell
$ asa attributes.asa
$ ./build/attributes
true
false

Attributes with an argument will return the value they contain if they are present, and false if they are not present.

attr_arguments.asa
@deprecated("Some message"):
foo ::(){
}

@customAttr("example"):
bar ::(){
}

printl(foo.@deprecated);
printl(bar.@customAttr);
printl(bar.@deprecated);
Shell
$ asa attr_arguments.asa
$ ./build/attr_arguments
Some message
example
false

While it is easy to get the value of an attribute, you can not use the same method to change the value of an attribute.

attr_set.asa
@customAttr("example"):
bar ::(){
}

bar.@customAttr = "changed";

TODO:
Place the actual error message here
Shell
$ asa attr_set.asa
$ ./build/attr_set
error[E007]:  Cannot modify value of attribute using access operator `.@`. Did you mean to use `#set_attribute()`?

Because attributes are considered immutable, modifying them at compile time is delegated to compiler directives for meta programming. See #set_attribute.