
Basic Data Operation

This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:


Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |
Comparison |
Matching
Memory Operations
Pointers & references |
Addresses


In this task, the goal is to demonstrate common operations on pointers and references. These examples show pointer operations on the stack, which can be dangerous and is rarely done. Pointers and references are commonly used along with Memory allocation on the heap.

#!/usr/local/bin/shale
 
aVariable var                           // Create aVariable
aVariable 0 =                           // Regular assignment.
aVariable "aVariable = %d\n" printf     // Print aVariable
 
aPointer var                            // Create aPointer
aPointer aVariable &=                   // Pointer asssignment, aPointer now points to aVariable
 
aPointer-> "aPointer-> = %d\n" printf   // Pointer dereference. Print what aPointer points to
 
aPointer-> 3.141593 =                   // This will change the value of aVariable
aVariable "aVariable = %f\n" printf     // Print aVariable
 
aPPointer var                           // Create aPPointer
aPPointer aPointer &=                   // aPPointer is a pointer to a pointer
aPPointer->-> "aPPointer->-> = %f\n" printf
 
aPPointer->-> "abc123" =                // This will change the value of aVariable
aVariable "aVariable = %s\n" printf     // Print aVariable
 
// Shale pointers can point to any Shale object, like numbers, strings, variables
// and code fragments.