Question: Something is undefined but so what?

Quote:

> I've written an html document with my question explained at length. I dont

> know if it works to post this as an attachment. If it didnt get through

> somebody please tell me. >>>My box did and now theyre backwards.

> I should start by saying that I dont know much about languages. Maybe I

> should be looking for a language called something other than 'functional'

> In a nutshell, Im looking for a language that doesnt automatically barf at

> something being undefined. The reason I want this is that it seems to me

> that if declared but undefined functions are just pushed through the symbol

> manipulator in the vain hope that they might eventually get a value, such

> functions provide a lovely way of handling dimensions and units. If dollar

> was an undefined function, 2 * dollar should be 2 * dollar, and not 'ugh!'

> The attachment explains this better.

> I cant believe nobody has thought along these lines before. Maybe if the

> idea is persued further it runs aground, or maybe theres a pile of source

> code sitting waiting for me somewhere.

> Any ideas?

Aubrey Jaffer has written and assembled a delightful library of Scheme

procedures called "SLIB". His home page is:

http://swissnet.ai.mit.edu/~jaffer/index.html

And the SLIB page is:

http://swissnet.ai.mit.edu/~jaffer/SLIB.html

One of the modules of SLIB is the commutative ring module. Here is a

quote from the SLIB manual on this module:

<blockquote>

Scheme provides a consistent and capable set of numeric functions.

Inexacts implement a field; integers a commutative ring (and Euclidean

domain). This package allows the user to use basic Scheme numeric

functions with symbols and non-numeric elements of commutative rings.

(require 'commutative-ring)

The commutative-ring package makes +, -, *, /, and ^ careful in the

sense that any non-numeric arguments which it cannot reduce appear in

the expression output. In order to see what working with this package

is like, self-set all the single letter identifiers (to their

corresponding symbols).

(define a 'a)

...

(define z 'z)

Or just (require 'self-set). Now for some sample expressions:

(* (+ a b) (+ a b)) => (+ (* 2 a b) (^ a 2) (^ b 2))

(* (+ a b) (- a b)) => (- (^ a 2) (^ b 2))

(* (- a b) (- a b)) => (- (+ (^ a 2) (^ b 2)) (* 2 a b))

(* (- a b) (+ a b)) => (- (^ a 2) (^ b 2))

(/ (+ a b) (+ c d)) => (+ (/ a (+ c d)) (/ b (+ c d)))

(/ (+ a b) (- c d)) => (+ (/ a (- c d)) (/ b (- c d)))

(/ (- a b) (- c d)) => (- (/ a (- c d)) (/ b (- c d)))

(/ (- a b) (+ c d)) => (- (/ a (+ c d)) (/ b (+ c d)))

(^ (+ a b) 3) => (+ (* 3 a (^ b 2)) (* 3 b (^ a 2)) (^ a 3) (^ b 3))

(^ (+ a 2) 3) => (+ 8 (* a 12) (* (^ a 2) 6) (^ a 3))

Use of this package is not restricted to simple arithmetic

expressions:

(require 'determinant)

(determinant '((a b c) (d e f) (g h i))) =>

(- (+ (* a e i) (* b f g) (* c d h)) (* a f h) (* b d i) (* c e g))

The commutative-ring package differs from other extension mechanisms

in that it automatically, using properties true of all commutative

rings, simplifies sum and product expressions containing non-numeric

elements. One need only specify behavior for + or * for cases where

expressions involving objects reduce to numbers or to expressions

involving different non-numeric elements.

Currently, only +, -, *, /, and ^ support non-numeric elements.

Expressions with - are converted to equivalent expressions without -,

so behavior for - is not defined separately. / expressions are handled

similarly.

This list might be extended to include quotient, modulo, remainder,

lcm, and gcd; but these work only for the more restrictive Euclidean

(Unique Factorization) Domain.

</blockquote>

I use SLIB mainly with SCM, Jaffer's solid and fast Scheme implementation,

but most of SLIB works with most Scheme implementations.

onr