Scalar Functions
Summary

1.  Introduction

2.  Constants

2a.  Numeric Constants

2b.  Character Constants

2c.  Symbol Constants

2d.  Nested Constants

3.  Scalar Functions

4.  Arithmetic Scalar Functions

5.  Operators

5a.  Reduction

5b.  Outer Product

5c.  Scan

5d.  Inner Product

6.  Selection and Assignment

7.  Relational Scalar Functions

8.  Logical Scalar Functions

8a.  Reduction Revisited

8b.  Scan Revisited

9.  Elementary Algebraic and Transcendental Scalar Functions

10.  Miscellaneous Scalar Functions

10a.  Absolute Value and Residue

10b.  Signum

10c.  Floor and Minimum

10d.  Ceiling and Maximum

10e.  Roll

11.  Tables

Table 1.  Scalar Functions

Table 2.  Operators on Scalar Functions


1.  Introduction

This tutorial is for the reader who has little or no experience with
programming in APL-like programming languages.  The scalar functions
exhibit many of the qualities that make A+ an effective programming
language, while at the same time being generally familiar, so this is
a good place to start.

As you will learn, many program fragments in A+ can be stated in a few
expressions that do not include explicit control statements.  This
expressiveness sometimes depends on using A+ primitive functions in
ways that are not apparent from their definitions.  So, don't expect
to see all or even most uses of the A+ primitive functions in these
tutorials.  The tutorials are meant to introduce you to the language
and some of its uses, but when you're done many surprises will still
lie ahead.  Who would want it otherwise?

This tutorial is made up of textual descriptions and A+ examples.  To
execute the examples conveniently you should set up your Emacs
environment to have two visible buffers, one holding the tutorial and
the other an A+ session.  If you are currently reading this in Emacs,
simply press F4.

The examples consist of indented A+ expressions and their values.
Sometimes the text refers to the values, and it is helpful to have
them handy, but the main reason they are displayed is to help you
become familiar with A+ in the Emacs environment.  In the later
tutorials the values usually do not appear in the text.  You should
evaluate the indented expressions, and compare the results in the A+
session with those in the text.

For example, when you see a display of the form

	1 2+3 4
 4 6

the indented expression 1 2+3 4 is the one to bring into the A+
session for evaluation.  The second expression, 4 6, is the result of
executing the indented expression and should not be brought into the
A+ session for evaluation.

To bring individual expressions from the tutorial into the A+ session,
place the cursor on the expression and press F2.  When an expression
is brought into A+ in this way, it is automatically evaluated, and its
value is displayed.  The displayed value should be identical to the
display in the tutorial.

If you need more help on running Emacs and A+, see the "Getting
Started" tutorial.  If you want to try your hand at devising your own
A+ expressions, see the keyboard layout diagrams in Chapter 2 and
Appendix B of the A+ Reference Manual.

2.  Constants

2a.  Numeric Constants

There are several preliminary things to discuss.  First of all, a list
of numeric constants can be entered on a line by separating the
individual numbers with blanks, as in

	3 4.5 7
 3 4.5 7

This is a list of the three numbers, 3, 4.5 and 7.  Secondly, negative
numbers are denoted by a raised minus sign.  For example:

	5+¢2
 3

Exponential notation can be used for fractional, or floating-point,
numbers, as in

	1.23e5
 123000

which is 1.23 times 10 to the 5, or 123000.  Negative exponents are
denoted with the usual minus sign, not the raised minus sign, so that

	¢2000e-2
 ¢20

is negative 2000 times 10 to the negative 2, or negative 20.

2b.  Character Constants

A single character is entered surrounded by quotation marks, and a
list of characters is entered in exactly the same way.  For example:

	'axcdert'
 axcdert

Either single quotes or double quotes can be used, but they must both
be the same.  For example:

	"axcdert"
axcdert

It is interesting to see how a quotation mark can be included in a
list of characters.  If a single quotation mark is to be included,
surround the list with double quotes; if a double quote mark is to be
included, surround the list single quotes.  For example:

	'He said, "Oh no!"'
He said, "Oh no!"

	"I can't go."
I can't go.

The question then becomes, how are both quotation marks included in
the list?  The answer is that the one that is identical to the quotes
surrounding the list must be doubled.  For example:

	'"I can''t go either," he said.'
"I can't go either," he said.

2c. Symbol Constants

A symbol constant is of the form backquote,characters.  An example is
`ThisIsASymbol.  It provides a form that enables rapid comparison and
is convenient for aggregation.  A vector of symbols can be written
simply by juxtaposing them, with or without blanks between them:

	`s1 `s2`s3   `s4 `s5`s6
 `s1 `s2 `s3 `s4 `s5 `s6

2d.  Nested Constants

In addition to numeric, character, and symbolic data, A+ has nested,
or boxed, data.  Nested data comes in lists, like numeric, character,
and symbolic data, except that the elements are not restricted to
individual numbers, characters, or symbols; they can be anything.  For
example:

	(2 3.5 ¢7;'dfgtyuh')
<  2 3.5 ¢7
< dfgtyuh

This constant has two elements.  The < in the display indicates that
what follows is a boxed element.  An easy way of producing nested
arrays is to use strand notation, as in the example.  It is of the
form (...;...;...) and its value is a list, or vector.  The successive
elements of this list are the enclosures, or boxed forms, of the
successive expressions between semicolons or between a semicolon and a
left or right parenthesis.


3.  Scalar Functions

For convenience, the scalar functions have been divided into
categories that may be familiar to you.  The arithmetic functions are
Plus, Minus, Times and Divide.  The relational functions are Equal to,
Not equal to, Less than, Less than or Equal to, Greater than, and
Greater Than or Equal to.  The logical functions are And, Or, and Not.
The elementary functions are Power, Log, and certain trigonometric and
algebraic functions.  Finally, there is a miscellaneous set.  The
names and symbols of the scalar functions are summarized in Table 1,
at the end of the tutorial.

The expressive power of the scalar functions in A+ is largely due to
useful variations provided by operators.  "5. Operators" introduces
Reduction, Scan, Outer Product and Inner Product.  Table 2, at the
end of the tutorial, tells which of these operators apply to which
scalar functions.


4.  Arithmetic Scalar Functions

The common arithmetic operations are examples of scalar functions in
A+.  They are Plus (+), Minus (-), Times («), and Divide (ß).  They
apply to individual numbers, as in:

	3+4
 7

and they apply to lists in an element-by-element fashion.  For
example:

     	2 5 ¢7 + 10
 12 15 3

In this example the three numbers, 2, 5, and  ¢7, are added to 10.
The result is a list of three numbers.  The spaces around the symbol +
are meant as an aid to readability and are not necessary.

A list of numbers can appear on the right of the operation symbol as
well as the left, as in the following subtraction example:

      200 - 27 ¢34.56 1.521e2 129
 173 234.56 47.9 71

and there can be lists on both sides of the symbol:

      2 7 9 « 10 ¢3 4
 20 ¢21 36

When there are two lists, i.e., more than one element on each side,
the number of elements must be the same on each side.

The operation of negation is denoted by - in mathematics, and in A+ as
well.  For example:

      - 3 6.7 ¢12 102 1e-3 ¢3.4e3
 ¢3 ¢6.7 12 ¢102 ¢0.001 3400

The use of one symbol to denote two operations, such as the - symbol
for subtraction and negation, is carried over in A+ to almost all its
primitive operations.  For example, ß denotes both division and the
taking of reciprocals, as in:

      2 ¢3 10 ß 5 6 5
 0.4 ¢0.5 2

and

 	ß 5 10 12
 0.2 0.1 0.08333333333

The number or list of numbers that appears to the left of a symbol is
called the left argument of the operation.  That which appears to the
right is called the right argument.  The two together are referred to
as the arguments of the operation.

When there are two arguments, the operation is said to be dyadic.
When an operation has only argument, when nothing appears to the left
of its symbol that could serve as the left argument, it is said to be
monadic.  Symbols, such as -, that have both a monadic and dyadic use
are called ambivalent.  Most primitive function symbols in A+ are
ambivalent.

It is time to adopt some conventional A+ terminology.  The common
mathematical term for +, -, « and ß is operation.  Operations are
examples of the general mathematical notion of function, but the term
operation is quite commonly used in mathematics when the symbol for
the dyadic function appears between the arguments.  However, in A+ we
tend to use the more general term "function", even for the arithmetic
operations.  This may be due to the fact that A+ also has operators,
another common mathematical concept, and the use of two closely
related terms can be confusing.  Whatever the reason, we will adopt
the A+ convention, and from now on we will refer to the arithmetic
operations as functions, and in particular as scalar functions.

Ex 1.  A mistake that is often made concerning numeric constant lists
such as

	1 5 ¢12 21

is to attach functional significance to the spaces between items.  Now
that we have seen how scalar functions are evaluated, we can examine
this common pitfall.  For example, one might expect to be able to form
the list consisting of 5 plus 23, 24 minus 13, and 10 times 6 simply
by putting these expressions on a line separated by blanks, as in:

	5+23 24-13 10«6

To understand how this expression is evaluated you need to know the
following (see the Syntax tutorial for a general discussion):

    the first thing done in evaluating this expression is to form
       the constant 13 10;
    the next thing done is to form the constant 23 24;
    next, the function « is evaluated;
    then -;
    and finally +.

Use these rules and your knowledge of scalar functions to evaluate
this expression by hand.  Check your answer by bringing this
expression into the A+ session for evaluation with F2.

The next common expectation is to be able to put each of the
expressions 5 plus 23, 24 minus 13, and 10 times 6 in parentheses, and
then put these three parenthesized expressions on a single line
separated by blanks, as in:

	(5+23) (24-13) (10«6)

But this is an invalid expression, and an attempt to evaluate it will
result in an error message:

PARSE +...  : var?

or, in Version 3,

ã[parse] +... : var?

To put the results of individual expressions like these three together
in a list, you must use the function designed for that purpose, which
is called Catenate and is denoted by the comma.  Use F2 to evaluate
the following expression:

	(5+23),(24-13),(10«6)

Ex 2.  Write two expressions for a 5-element list whose first two
elements are those of the list 14+4 8 and whose last three elements
are those of the list 4 9 12-3 10 7.


5.  Operators

In mathematics, operators are objects that act on functions to produce
new functions.  A+ has several operators that act on scalar functions.
We will introduce them here for the arithmetic functions, and return
to them later as more scalar functions are introduced.


5a.  Reduction

The slash (/) denotes an A+ operator called reduction.  For example,
+/ denotes + reduction, and «/ denotes « reduction.  The function
symbol always appears to the left of the slash.  The functions +/ and
«/ are called derived functions because they are derived from other
functions, namely + and «.  A hint at how these derived functions are
defined is that +/ is also called summation.

	+/3 5 8 12
 28
	3+5+8+12
 28
	+/1 2 3 4 5 6 7 8 9 10
 55
	1+2+3+4+5+6+7+8+9+10
 55

That is, +/ takes the sum of all elements in a list.  The reduction
operator applies uniformly to all functions whose symbols are
permitted to the left of the  slash (see Table 2), so you should
suspect that « reduction takes the product of all elements in a list.

	«/3 5 8 12
 1440
	3«5«8«12
 1440
 	«/1 2 3 4 5 6 7 8 9 10
 3628800
 	1«2«3«4«5«6«7«8«9«10
 3628800


5b.  Outer Product

The symbols Ê.  denote the operator called outer product.  Ê.+ is
called the outer product of + and Ê.« is called the outer product of
«.  The outer product operator is sometimes called the table maker,
and here is an example:

	1 6 ¢2 3Ê.+4 10 3
  5 11  4
 10 16  9
  2  8  1
  7 13  6

When you execute the above outer product expression you will see the
four separate lines displayed below the expression.  These four lines
are the rows of a table.  You will note that the numbers in these rows
line up vertically.  The aligned vertical lists are the columns of the
table.  This table contains all combinations of sums of elements from
the list on the left with elements from the list on the right.  For
example, the number at the thi       

So, the extraneous characters are on the ends of the words.  We will  
continue this example in the exercises.                               

Ex 8 Use the Drop primitive and the Each operator to remove one       
character from the end of each word.  Which of the resulting character
vectors still contain extraneous characters? Suggest ways to get rid  
of all extraneous characters at once.                                 

Ex 9 Insert an extra space between two words in the sentence s, and   
call the new sentence s0.  For example:                               

	s0û"Partition Count  is a dyadic function, while Partition is monadic."

Partition s0:                                                         

	w0û(Ú1,s0=' ')Ús0                                                    

Examine w0, and explain how the extra blank in s is manifested in w0. 
How would you remove it from the w0?                                  

Ex 10 Partition the vector s0 of Ex 9 as follows:                     

	w1û(Ú1,s0Å' ,.')Ús0                                                  

Examine w1, and explain how the punctuation characters, as well as the
extra blank, are manifested in w1.  How would you remove these        
characters from w1?                                                   

Ex 11 Suppose the leading character is a blank, i.e.  form            

	s1û' ',s                                                             

Describe the result of                                                

	w2û(Ú1,s1Å' ,.')Ús1                                                  

Ex 12 How would you define a function to partition a sentence into    
words, when the punctuation characters can be commas, periods, and    
semicolons, and when there can be multiple blanks between words, and  
zero or mare blanks at the beginning and end of the sentence?         


5b.  Raze and Rake                                                    

The primitives Raze and Rake apply to nested arrays and bring all     
elements up level 0 and 1, respectively.                              

./usr/share/doc/aplus-fsf-doc/html/tutorials/ScalarFunctions.html0000644000000000000000000010607310750123133024014 0ustar rootroot  
                                    Scalar Functions
Summary

1.  Introduction

2.  Constants

2a.  Numeric Constants

2b.  Character Constants

2c.  Symbol Constants

2d.  Nested Constants

3.  Scalar Functions

4.  Arithmetic Scalar Functions

5.  Operators

5a.  Reduction

5b.  Outer Product

5c.  Scan

5d.  Inner Product

6.  Selection and Assignment

7.  Relational Scalar Functions

8.  Logical Scalar Functions

8a.  Reduction Revisited

8b.  Scan Revisited

9.  Elementary Algebraic and Transcendental Scalar Functions

10.  Miscellaneous Scalar Functions

10a.  Absolute Value and Residue

10b.  Signum

10c.  Floor and Minimum

10d.  Ceiling and Maximum

10e.  Roll

11.  Tables

Table 1.  Scalar Functions

Table 2.  Operators on Scalar Functions


1.  Introduction

This tutorial is for the reader who has little or no experience with
programming in APL-like programming languages.  The scalar functions
exhibit many of the qualities that make A+ an effective programming
language, while at the same time being generally familiar, so this is
a good place to start.

As you will learn, many program fragments in A+ can be stated in a few
expressions that do not include explicit control statements.  This
expressiveness sometimes depends on using A+ primitive functions in
ways that are not apparent from their definitions.  So, don't expect
to see all or even most uses of the A+ primitive functions in these
tutorials.  The tutorials are meant to introduce you to the language
and some of its uses, but when you're done many surprises will still
lie ahead.  Who would want it otherwise?

This tutorial is made up of textual descriptions and A+ examples.  To
execute the examples conveniently you should set up your Emacs
environment to have two visible buffers, one holding the tutorial and
the other an A+ session.  If you are currently reading this in Emacs,
simply press F4.

The examples consist of indented A+ expressions and their values.
Sometimes the text refers to the values, and it is helpful to have
them handy, but the main reason they are displayed is to help you
become familiar with A+ in the Emacs environment.  In the later
tutorials the values usually do not appear in the text.  You should
evaluate the indented expressions, and compare the results in the A+
session with those in the text.

For example, when you see a display of the form

	1 2+3 4
 4 6

the indented expression 1 2+3 4 is the one to bring into the A+
session for evaluation.  The second expression, 4 6, is the result of
executing the indented expression and should not be brought into the
A+ session for evaluation.

To bring individual expressions from the tutorial into the A+ session,
place the cursor on the expression and press F2.  When an expression
is brought into A+ in this way, it is automatically evaluated, and its
value is displayed.  The displayed value should be identical to the
display in the tutorial.

If you need more help on running Emacs and A+, see the "Getting
Started" tutorial.  If you want to try your hand at devising your own
A+ expressions, see the keyboard layout diagrams in Chapter 2 and
Appendix B of the A+ Reference Manual.

2.  Constants

2a.  Numeric Constants

There are several preliminary things to discuss.  First of all, a list
of numeric constants can be entered on a line by separating the
individual numbers with blanks, as in

	3 4.5 7
 3 4.5 7

This is a list of the three numbers, 3, 4.5 and 7.  Secondly, negative
numbers are denoted by a raised minus sign.  For example:

	5+¢2
 3

Exponential notation can be used for fractional, or floating-point,
numbers, as in

	1.23e5
 123000

which is 1.23 times 10 to the 5, or 123000.  Negative exponents are
denoted with the usual minus sign, not the raised minus sign, so that

	¢2000e-2
 ¢20

is negative 2000 times 10 to the negative 2, or negative 20.

2b.  Character Constants

A single character is entered surrounded by quotation marks, and a
list of characters is entered in exactly the same way.  For example:

	'axcdert'
 axcdert

Either single quotes or double quotes can be used, but they must both
be the same.  For example:

	"axcdert"
axcdert

It is interesting to see how a quotation mark can be included in a
list of characters.  If a single quotation mark is to be included,
surround the list with double quotes; if a double quote mark is to be
included, surround the list single quotes.  For example:

	'He said, "Oh no!"'
He said, "Oh no!"

	"I can't go."
I can't go.

The question then becomes, how are both quotation marks included in
the list?  The answer is that the one that is identical to the quotes
surrounding the list must be doubled.  For example:

	'"I can''t go either," he said.'
"I can't go either," he said.

2c. Symbol Constants

A symbol constant is of the form backquote,characters.  An example is
`ThisIsASymbol.  It provides a form that enables rapid comparison and
is convenient for aggregation.  A vector of symbols can be written
simply by juxtaposing them, with or without blanks between them:

	`s1 `s2`s3   `s4 `s5`s6
 `s1 `s2 `s3 `s4 `s5 `s6

2d.  Nested Constants

In addition to numeric, character, and symbolic data, A+ has nested,
or boxed, data.  Nested data comes in lists, like numeric, character,
and symbolic data, except that the elements are not restricted to
individual numbers, characters, or symbols; they can be anything.  For
example:

	(2 3.5 ¢7;'dfgtyuh')
<  2 3.5 ¢7
< dfgtyuh

This constant has two elements.  The < in the display indicates that
what follows is a boxed element.  An easy way of producing nested
arrays is to use strand notation, as in the example.  It is of the
form (...;...;...) and its value is a list, or vector.  The successive
elements of this list are the enclosures, or boxed forms, of the
successive expressions between semicolons or between a semicolon and a
left or right parenthesis.


3.  Scalar Functions

For convenience, the scalar functions have been divided into
categories that may be familiar to you.  The arithmetic functions are
Plus, Minus, Times and Divide.  The relational functions are Equal to,
Not equal to, Less than, Less than or Equal to, Greater than, and
Greater Than or Equal to.  The logical functions are And, Or, and Not.
The elementary functions are Power, Log, and certain trigonometric and
algebraic functions.  Finally, there is a miscellaneous set.  The
names and symbols of the scalar functions are summarized in Table 1,
at the end of the tutorial.

The expressive power of the scalar functions in A+ is largely due to
useful variations provided by operators.  "5. Operators" introduces
Reduction, Scan, Outer Product and Inner Product.  Table 2, at the
end of the tutorial, tells which of these operators apply to which
scalar functions.


4.  Arithmetic Scalar Functions

The common arithmetic operations are examples of scalar functions in
A+.  They are Plus (+), Minus (-), Times («), and Divide (ß).  They
apply to individual numbers, as in:

	3+4
 7

and they apply to lists in an element-by-element fashion.  For
example:

     	2 5 ¢7 + 10
 12 15 3

In this example the three numbers, 2, 5, and  ¢7, are added to 10.
The result is a list of three numbers.  The spaces around the symbol +
are meant as an aid to readability and are not necessary.

A list of numbers can appear on the right of the operation symbol as
well as the left, as in the following subtraction example:

      200 - 27 ¢34.56 1.521e2 129
 173 234.56 47.9 71

and there can be lists on both sides of the symbol:

      2 7 9 « 10 ¢3 4
 20 ¢21 36

When there are two lists, i.e., more than one element on each side,
the number of elements must be the same on each side.

The operation of negation is denoted by - in mathematics, and in A+ as
well.  For example:

      - 3 6.7 ¢12 102 1e-3 ¢3.4e3
 ¢3 ¢6.7 12 ¢102 ¢0.001 3400

The use of one symbol to denote two operations, such as the - symbol
for subtraction and negation, is carried over in A+ to almost all its
primitive operations.  For example, ß denotes both division and the
taking of reciprocals, as in:

      2 ¢3 10 ß 5 6 5
 0.4 ¢0.5 2

and

 	ß 5 10 12
 0.2 0.1 0.08333333333

The number or list of numbers that appears to the left of a symbol is
called the left argument of the operation.  That which appears to the
right is called the right argument.  The two together are referred to
as the arguments of the operation.

When there are two arguments, the operation is said to be dyadic.
When an operation has only argument, when nothing appears to the left
of its symbol that could serve as the left argument, it is said to be
monadic.  Symbols, such as -, that have both a monadic and dyadic use
are called ambivalent.  Most primitive function symbols in A+ are
ambivalent.

It is time to adopt some conventional A+ terminology.  The common
mathematical term for +, -, « and ß is operation.  Operations are
examples of the general mathematical notion of function, but the term
operation is quite commonly used in mathematics when the symbol for
the dyadic function appears between the arguments.  However, in A+ we
tend to use the more general term "function", even for the arithmetic
operations.  This may be due to the fact that A+ also has operators,
another common mathematical concept, and the use of two closely
related terms can be confusing.  Whatever the reason, we will adopt
the A+ convention, and from now on we will refer to the arithmetic
operations as functions, and in particular as scalar functions.

Ex 1.  A mistake that is often made concerning numeric constant lists
such as

	1 5 ¢12 21

is to attach functional significance to the spaces between items.  Now
that we have seen how scalar functions are evaluated, we can examine
this common pitfall.  For example, one might expect to be able to form
the list consisting of 5 plus 23, 24 minus 13, and 10 times 6 simply
by putting these expressions on a line separated by blanks, as in:

	5+23 24-13 10«6

To understand how this expression is evaluated you need to know the
following (see the Syntax tutorial for a general discussion):

    the first thing done in evaluating this expression is to form
       the constant 13 10;
    the next thing done is to form the constant 23 24;
    next, the function « is evaluated;
    then -;
    and finally +.

Use these rules and your knowledge of scalar functions to evaluate
this expression by hand.  Check your answer by bringing this
expression into the A+ session for evaluation with F2.

The next common expectation is to be able to put each of the
expressions 5 plus 23, 24 minus 13, and 10 times 6 in parentheses, and
then put these three parenthesized expressions on a single line
separated by blanks, as in:

	(5+23) (24-13) (10«6)

But this is an invalid expression, and an attempt to evaluate it will
result in an error message:

PARSE +...  : var?

or, in Version 3,

ã[parse] +... : var?

To put the results of individual expressions like these three together
in a list, you must use the function designed for that purpose, which
is called Catenate and is denoted by the comma.  Use F2 to evaluate
the following expression:

	(5+23),(24-13),(10«6)

Ex 2.  Write two expressions for a 5-element list whose first two
elements are those of the list 14+4 8 and whose last three elements
are those of the list 4 9 12-3 10 7.


5.  Operators

In mathematics, operators are objects that act on functions to produce
new functions.  A+ has several operators that act on scalar functions.
We will introduce them here for the arithmetic functions, and return
to them later as more scalar functions are introduced.


5a.  Reduction

The slash (/) denotes an A+ operator called reduction.  For example,
+/ denotes + reduction, and «/ denotes « reduction.  The function
symbol always appears to the left of the slash.  The functions +/ and
«/ are called derived functions because they are derived from other
functions, namely + and «.  A hint at how these derived functions are
defined is that +/ is also called summation.

	+/3 5 8 12
 28
	3+5+8+12
 28
	+/1 2 3 4 5 6 7 8 9 10
 55
	1+2+3+4+5+6+7+8+9+10
 55

That is, +/ takes the sum of all elements in a list.  The reduction
operator applies uniformly to all functions whose symbols are
permitted to the left of the  slash (see Table 2), so you should
suspect that « reduction takes the product of all elements in a list.

	«/3 5 8 12
 1440
	3«5«8«12
 1440
 	«/1 2 3 4 5 6 7 8 9 10
 3628800
 	1«2«3«4«5«6«7«8«9«10
 3628800


5b.  Outer Product

The symbols Ê.  denote the operator called outer product.  Ê.+ is
called the outer product of + and Ê.« is called the outer product of
«.  The outer product operator is sometimes called the table maker,
and here is an example:

	1 6 ¢2 3Ê.+4 10 3
  5 11  4
 10 16  9
  2  8  1
  7 13  6

When you execute the above outer product expression you will see the
four separate lines displayed below the expression.  These four lines
are the rows of a table.  You will note that the numbers in these rows
line up vertically.  The aligned vertical lists are the columns of the
table.  This table contains all combinations of sums of elements from
the list on the left with elements from the list on the right.  For
example, the number at the thi       

So, the extraneous characters are on the ends of the words.  We will  
continue this example in the exercises.                               

Ex 8 Use the Drop primitive and the Each operator to remove one       
character from the end of each word.  Which of the resulting character
vectors still contain extraneous characters? Suggest ways to get rid  
of all extraneous characters at once.                                 

Ex 9 Insert an extra space between two words in the sentence s, and   
call the new sentence s0.  For example:                               

	s0û"Partition Count  is a dyadic function, while Partition is monadic."

Partition s0:                                                         

	w0û(Ú1,s0=' ')Ús0                                                    

Examine w0, and explain how the extra blank in s is manifested in w0. 
How would you remove it from the w0?                                  

Ex 10 Partition the vector s0 of Ex 9 as follows:                     

	w1û(Ú1,s0Å' ,.')Ús0                                                  

Examine w1, and explain how the punctuation characters, as well as the
extra blank, are manifested in w1.  How would you remove these        
characters from w1?                                                   

Ex 11 Suppose the leading character is a blank, i.e.  form            

	s1û' ',s                                                             

Describe the result of                                                

	w2û(Ú1,s1Å' ,.')Ús1                                                  

Ex 12 How would you define a function to partition a sentence into    
words, when the punctuation characters can be commas, periods, and    
semicolons, and when there can be multiple blanks between words, and  
zero or mare blanks at the beginning and end of the sentence?         


5b.  Raze and Rake                                                    

The primitives Raze and Rake apply to nested arrays and bring all     
elements up level 0 and 1, respectively.                              

./usr/share/doc/aplus-fsf-doc/html/tutorials/ScalarFunctions.html0000644000000000000000000010607310750123133024014 0ustar rootroot  
                                    Scalar Functions
Summary

1.  Introduction

2.  Constants

2a.  Numeric Constants

2b.  Character Constants

2c.  Symbol Constants

2d.  Nested Constants

3.  Scalar Functions

4.  Arithmetic Scalar Functions

5.  Operators

5a.  Reduction

5b.  Outer Product

5c.  Scan

5d.  Inner Product

6.  Selection and Assignment

7.  Relational Scalar Functions

8.  Logical Scalar Functions

8a.  Reduction Revisited

8b.  Scan Revisited

9.  Elementary Algebraic and Transcendental Scalar Functions

10.  Miscellaneous Scalar Functions

10a.  Absolute Value and Residue

10b.  Signum

10c.  Floor and Minimum

10d.  Ceiling and Maximum

10e.  Roll

11.  Tables

Table 1.  Scalar Functions

Table 2.  Operators on Scalar Functions


1.  Introduction

This tutorial is for the reader who has little or no experience with
programming in APL-like programming languages.  The scalar functions
exhibit many of the qualities that make A+ an effective programming
language, while at the same time being generally familiar, so this is
a good place to start.

As you will learn, many program fragments in A+ can be stated in a few
expressions that do not include explicit control statements.  This
expressiveness sometimes depends on using A+ primitive functions in
ways that are not apparent from their definitions.  So, don't expect
to see all or even most uses of the A+ primitive functions in these
tutorials.  The tutorials are meant to introduce you to the language
and some of its uses, but when you're done many surprises will still
lie ahead.  Who would want it otherwise?

This tutorial is made up of textual descriptions and A+ examples.  To
execute the examples conveniently you should set up your Emacs
environment to have two visible buffers, one holding the tutorial and
the other an A+ session.  If you are currently reading this in Emacs,
simply press F4.

The examples consist of indented A+ expressions and their values.
Sometimes the text refers to the values, and it is helpful to have
them handy, but the main reason they are displayed is to help you
become familiar with A+ in the Emacs environment.  In the later
tutorials the values usually do not appear in the text.  You should
evaluate the indented expressions, and compare the results in the A+
session with those in the text.

For example, when you see a display of the form

	1 2+3 4
 4 6

the indented expression 1 2+3 4 is the one to bring into the A+
session for evaluation.  The second expression, 4 6, is the result of
executing the indented expression and should not be brought into the
A+ session for evaluation.

To bring individual expressions from the tutorial into the A+ session,
place the cursor on the expression and press F2.  When an expression
is brought into A+ in this way, it is automatically evaluated, and