Previous Up Next

8.3.1  Context-dependent functions.

The + operator.

The + operator is infixed and ’+’ is its prefixed version. The + operator will add numbers (see Section 7.3.2), concatenate strings (see Section 5.2.13), and convert a number to a string if necessary. Addition makes sense for other objects, and + can flexibly deal with them; the result of using the + operator depends on the nature of its arguments.

Examples

1+2+3+4

or:

'+'(1,2,3,4)

or:

(1,2)+(3,4)

or:

(1,2,3)+4)
     
10           

(See Section 6.1.9.)

1+i+2+3*i

or:

'+'(1,i,2,3*i)
     
3+4 i           
[1,2,3]+[4,1]

or:

[1,2,3]+[4,1,0]

or:

'+'([1,2,3],[4,1])
     

5,3,3
          
[1,2]+[3,4]

or:

'+'([1,2],[3,4])
     

4,6
          
[[1,2],[3,4]]+[[1,2],[3,4]]
     


    24
    68


          
[1,2,3]+4

or:

'+'([1,2,3],4)
     
▯ 1,2,7▯           

(This is a polynomial; see Section 11.1.1.)

[1,2,3]+(4,1)

or:

'+'([1,2,3],4,1)
     
▯ 1,2,8 ▯           
"Hel"+"lo"

or:

'+'("Hel","lo")
     
“Hello”           
The -, * and / operators.

The -, * and / operators (and their prefixed versions ’-’, ’*’ and ’/’), like the + operator, are flexible and operate on compound objects (such as lists and sequences), but do not concatenate strings.

Examples of - and ’-’.

(1,2)-(3,4)
     
−4           
(1,2,3)-4
     
2           
[1,2,3]-[4,1]

or:

[1,2,3]-[4,1,0]

or:

'-'([1,2,3],[4,1])
     

−3,1,3
          
[1,2]-[3,4]

or:

'-'([1,2],[3,4])
     

−2,−2
          
[[3,4],[1,2]]-[[1,2],[3,4]]
     


    22
    −2−2


          
[1,2,3]-4

or:

'-'([1,2,3],4)
     
▯ 1,2,−1▯           
[1,2,3]-(4,1)
     
▯ 1,2,−2 ▯           

Examples of * and ’*’.

(1,2)*(3,4)

or:

(1,2,3)*4

or:

1*2*3*4

or:

'*'(1,2,3,4)
     
24           
1*i*2*3*i

or:

'*'(1,i,2,3*i)
     
−6           
[10,2,3]*[4,1]

or:

[10,2,3]*[4,1,0]

or:

'*'([10,2,3],[4,1])
     
42           

These compute the scalar product.

[1,2]*[3,4]

or:

'*'([1,2],[3,4])
     
11           

These compute the scalar product.

[[1,2],[3,4]]*[[1,2],[3,4]]
     


    710
    1522


          
[1,2,3]*4

or:

'*'([1,2,3],4)
     

4,8,12
          
[1,2,3]*(4,2)

or:

'*'([1,2,3],4,2)

or:

[1,2,3]*8
     

8,16,24
          
(1,2)+i*(2,3)

or:

1+2+i*2*3
     
3+6 i           

Examples of / and ’/’.

[10,2,3]/[4,1]
     



5
2
,2


          
[1,2]/[3,4]

or:

'/'([1,2],[3,4])
     



1
3
,
1
2



          
1/[[1,2],[3,4]]

or:

'/'(1,[[1,2],[3,4]]
     





    −21
    
3
2
1
2





          
[[1,2],[3,4]]*1/[[1,2],[3,4]]
     


    10
    01


          
[[1,2],[3,4]]/[[1,2],[3,4]]
     


    11
    11


          

(This is term-by-term division.)


Previous Up Next