next up previous contents index
Next: Comparison Operators Up: Built in functions Previous: Declaring and Using Modules   Contents   Index

Mathematical Operators

If both arguments are numeric, perform the mathematical operation; otherwise, perform a string concatenation (join)

X+Y

addition if either arg is non-numeric, concatenate with no separator
  1+2 => 3
  a+2 => a2
  '1'+2 => '12'
  number('1')+2=>3
X-Y

subtraction if either arg is non-numeric, concatenate using "-" as separator.
  3-2 => 1
  3-a => '3-a'
  '3'-2 => '3-2'
  number('3')-2=>1
X*Y

multiplication if NEITHER arg is non-numeric, concatenate using "*" as separator

if Y is numeric, and X is non-numeric, concatenate X Y times

  2*2 => 4
  a*2 => aa
  2*a => '2*a'
  '2'*2 => '22'
  foo*(2*2) => foofoofoofoo
X/Y

If both arguments are numbers, returns X divided by Y. If both numbers are integers, returns an integer if division is exact, otherwise returns float.

If either argument is non-numeric, returns an atom from concatenating X and Y with "/" as separator

  6/2 => 3
  a/b => 'a/b'
  '6'/2 => '6/2'
X**Y

If both arguments are numbers, returns X to the power of Y.

If either argument is non-numeric, returns an atom from concatenating X and Y with "**" as separator

  2**3 => 8
  2**'3' => '2**3'
X++Y

Appends two lists. Arguments are converted to length-1 lists if they are not already lists
  [a b c]++[d e f] => [a b c d e f]
-X

If X is a number, returns 0-X. If X is non-number, concatenates "-" and X
  -2 => -2
  -2 * 2 => -4
  -'2' => '-2'
  -'2' * 2 => '-2-2'
/X

Concatenates "/" and X
  /1 => '/1'
  /x/y/z => '/x/y/z'
X >& Y

returns an atom from concatenating X and Y with ">&" as separator
  foo >& 'foo.err' => 'foo>&foo.err'
X.Y

returns an atom from concatenating X and Y with "." as separator
  a.b => 'a.b'
  a.b.c => 'a.b.c'
number(X)

converts X to a number
  number('1') => 1
  number(1) => 1
  number(a) EXCEPTION

Exceptions: as prolog atom_number/2


next up previous contents index
Next: Comparison Operators Up: Built in functions Previous: Declaring and Using Modules   Contents   Index
chris mungall 2006-02-09