axiom-developer
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Axiom-developer] Variable scope (was Questions)


From: Stefan Dirnstorfer
Subject: [Axiom-developer] Variable scope (was Questions)
Date: Thu, 08 Jan 2004 05:00:05 +0100
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624

I did some further investigation in my intended type of variable binding and found out, that it does work in Maple and Haskell, but not in Axiom and Lisp. My function 'cons' was ment to produce a
constant function. Here is the example produced with Maple:

MAPLE
-----

cons:= c -> (x-> c);


                         cons := c -> x -> c

[ This is the constant function 6, where Axiom produced x -> G1234
cons (6);

                                x -> 6

[ A linear function could be created in the same way
lin:= m -> (x-> m*x);


                         lin := m -> x -> m x

[ And with slope two
lin(2);

                               x -> 2 x

[ This one is tricky, but Maple can add functions. Support for this
feature is primitive, since the result is not simplified to x-> 2x + 3
f:=cons(3)+lin(2);

                      f := (x -> 3) + (x -> 2 x)

[ And, to prove it is a function:
f(2);


                                  7

This plain example might seem useless, but refers to one of the
fundamential programing techniques in functional languages.


HASKELL
-------

Here is the same example in Haskell:
cons :: a -> (a -> a)
cons c = \x -> c

cons 3 2 does evaluate to 3.


LISP
----

Emacs-Lisp deals differently with this situation:
(defun constant (c) (lambda (x) (c)))

(constant 3)
;; (lambda (x) (c))

(apply (constant 3) '(2))
;; Symbol's function definition is void: c


AXIOM
-----

The Lisp evaluation is just equivalent to what Axiom does. It transforms a->b->a into a->b->#1. I do wonder where comes the unbound variable from, where there is initially none?


In my eyes the Maple binding does make more sense, but there is certainly no bug in either algebra system. I am still curious if there is a workaround in Axiom.


Regards,
Stefan



David MENTRE wrote:
Stefan Dirnstorfer <address@hidden> writes:


1) Here Axiom seems not to correctly bind the variable c

(2) -> cons:= c+->(x+->c)
 (2)  c +-> x +-> c
                                                     Type:
AnonymousFunction


I don't understand your example. What are you trying to build?


Yours,
d.








reply via email to

[Prev in Thread] Current Thread [Next in Thread]