Hi all,

I thought this is a useful example for language extensions:


It shows how 'redef' can be used to redefine a function in terms of

Here, the arithmetic operators +, -, *, / and ** are overloaded to
behave differently when the arguments are cons-pairs (i.e. handle the
uncertainty terms). Arithmetics with normal numbers continue to work as

The distinction is handled by checking the two variables 'R' (result)
and 'N' (next argument):

   (if2 (atom R) (atom N)
      (+ R N)              # Handle the normal case
      ...                  # Handle the extended case

The point is that at the end of the day, you can write functions like

   (de distance (X1 Y1 X2 Y2)
         (+ (** (- X1 X2) 2.0) (** (- Y1 Y2) 2.0))
         0.5 ) )

which behave correctly depending on the argument type.

This mechanism might be used to implement other application-specific
mixed-mode arithmetics, e.g by using the rational numbers of

- Alex
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe

Reply via email to