[SparForte][Banner]
[Top Main Menu] Intro | Tutorials | Reference | Packages | Examples | Contributors   [Back Page]      [Next Page]  

The @ and % Operands

AdaScript has two short-cut operands provided for scripting and convenience on the command line.

Itself (@)

AdaScript provides a self-referential operand. "@", pronounced "itself", returns the value of the variable on the left side of an assignment statement. Use @ to save yourself unnecessary typing.

=> total := @ + 1; -- total := total + 1;

(An operand is used instead of C-style "+=", "-=", and so forth because it's much more resilient to typos. Leaving out the "@" or transposing it with the ":=" or "+" will result in a syntax error. In C, these mistakes usually result in legal assignments.)

=> result := 10 - @; -- impossible with C-style shortcuts

When assigning a value to an array, @ refers to the array item being assigned, not the entire array.

=> zebra_population( 1966 ) := @+1; -- add 1 to 1966 population

Common self-referential (or combined operator) shortcuts:

C styleSparForte Style
temp++temp:=@+1
++temptemp:=@+1
temp--temp:=@-1
--temptemp:=@-1
temp+=xtemp:=@+x
temp-=xtemp:=@-x
temp*=xtemp:=@*x
temp/=xtemp:=@/x
temp%=xtemp:=@ mod x
temp.=x (PHP)temp:= @&x

Itsef can also be used as an operator to repeat commands, procedures or pragmas with new parameters. Read this as "and itself with". This is called a a "chain".

=> echo "hello" @ "world"
hello
world
=> put_line( "hello" ) @ ("world")
hello
world
=>

Last Output (%)

AdaScript provides a last output operand. "%", pronounced "last output", returns the last put_line (or ?) value. This is similar to Python's last output operand.

=> put_line( 5*2 )
10
=> put_line( %+5 )
15

The type of the last output is remembered.

=> put_line( 5 )
5
=> put_line( % & " is a good number" )
put_line( % & " is a good number" );
                                  ^ type universal_numeric is inherently different from a universal_string

Use % for quick calculations at the command line.
 

[Right Submenu]

 AdaScript versus GCC

 Case Sensitivity

 Reserved Words

 Comments

 Literals

 Bourne Shell Word Expansions

 Fundamental Types

 User-defined Types

 Enumerated Types

 Arrays

 Records

 Basic Assignment

 The @ and % Operands

 Command Argument Shortcuts

 Redirection and Pipelines

 Command Line Interaction

 Built-in Shell Commands

 The Current Directory

 Database Commands

 Flow of Control

 Other Statements/ Subprograms

 External Commands

 Block Statements and Subprograms

 TCP/IP Sockets

 Numeric Formatting with Put

 Interpreter Directives

 Command Line Options

 Command Reference

 ASCII and Latin_1 Character Sets

 Common Error Messages

 Common PHP Functions and the SparForte Equivalent

[Back to Top] Back To Top [Small Forte Symbol]