Topic: APLX Help : Help on APL language : APL Fundamentals : Specification
[ Previous | Next | Contents | Index | APL Home ]

www.microapl.co.uk

Specification (Assignment)


The symbol associates the data on its right with the name specified on its left. The named data is known as a variable. The name associated with it is the variable name. Subsequent references to the variable name automatically refer to the data associated with that name. This operation is known as specification or assignment.

             NUM← 24                      (scalar 24 is assigned to NUM)
             DESCRN←'ITEM 241A'           (simple character vector)
             PRICES← 2.34 9.30 12 60.38   (numeric vector is assigned to PRICES)
             DATA←1 'A' 2 'D'             (mixed vector assigned to DATA)

When entering character data, care must be exercised if the quote character is to be included in the data. As stated above, adjacent quote marks are evaluated as indicating the quote character in the data. A vector containing only characters can be entered in one of two ways - the characters can either be entered within one set of quote marks or the characters must be separated by spaces. See also the section on Vector Notation.

             ALF←'A' 'B' 'C' 'D'     (data is a set of characters)
             ALF
       ABCD
             ALF←'ABCD'              (alternative method of entry)
             ALF
       ABCD
             ALF←'A''B''C''D'        (no space between characters)
             ALF
       A'B'C'D

The right argument to can be any APL expression that generates a result:

             COST←110-67                  (The result of evaluating an
             COST                          expression is assigned to
       43                                  COST)
             PROFIT←(PRICE←COST×1.2)-COST←100
             PROFIT                       (right to left execution ensures
       20                                  that the value assigned to
                                           COST is used in the expression
                                           inside parentheses.)

Variables which are either scalars or vectors can be entered directly, as shown above. Matrices or higher dimensional arrays must be established or entered via functions (see for example ⍴, 'reshape').

             TAB←2 3⍴⍳6                   (The numbers 1 - 6 are arranged as 2
                                           rows of 3 columns and are assigned
                                           to TAB)

Topic: APLX Help : Help on APL language : APL Fundamentals : Specification
[ Previous | Next | Contents | Index | APL Home ]