[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Axiom-mail] RE: AXIOM / TeXmacs problems (bugs?)
From: |
Bill Page |
Subject: |
[Axiom-mail] RE: AXIOM / TeXmacs problems (bugs?) |
Date: |
Mon, 8 Dec 2003 01:06:55 -0500 |
On Sunday, December 07, 2003 10:36 PM Bertfried Fauser
[mailto:address@hidden wrote:
>
> On Sun, 7 Dec 2003, Bill Page wrote:
>
> > I have no problem entering muli-line commands with TeXmacs and
> > Axiom. I use just shift+Enter. In fact I have posted several
> > examples of exactly this at the Axiom web site (unfortunately still
> > not available! :((
>
> Dear Bill,
>
> if I try to define functions and type things like
>
> newfunction(x,y) ==
> t := x
> x := y
> y := t
>
> which is a swap of its arguments, I get an error, since all is
> put into a single line and AXIOM does not recognize piles and
> the program structure (the compiler fails with an error, when
> I invokle the function the first time), this does _not_ happen
> if I use the commandline AXIOM and the ' _' trick as described
> in Jenks & Sutor.
>
Jenks and Sutor describe the use of underscore (_) on page
27 section 1.3.8. This is only required if you type directly
into the interpreter of if you use a front-end like emacs that
(by default) sends the new lines (Enter) in the buffer directly
to Axiom. The _ at the end of a line of input is what tells
Axiom to ignore the new line character and simply continue the
input line. This is not needed when you use Axiom since Axiom
distinquishes between Enter (new line) and shift-Enter
(equivalent to _ Enter).
This does not have anything to do with "piles". Please refer
to Jenks and Sutor page 112, section 5.2. Piles are a way of
representing blocks by using indentation in .input files,
i.e. when using
)read file.input
This method is not available for use during interactive
input, i.e. when using TeXmacs or when typing directly
into the interpreter. You must instead use the syntax
( expression1; expression2; ... ; expressionN )
So you could write your example function above as
newfunction(x,y) == (
t := x;
x := y;
y := t
)
In Axiom the parenthesis ( ) play the same role as
begin-end braces { } in some other languages. Note that
in this case the indentation is not important - only
just a means of displaying the structure.
If you type this function directly into the interpreter,
then each line (except the last must end in _. When you
type it in TeXmacs, you just key shift+Enter instead
of Enter.
When you type it into a text file using emacs, then you
would normally use the "pile" notation in which case
it would look exactly you wrote it without the ( ) and
the indentation becomes very significant to the meaning.
But I do not understand your function. This function
simply returns the value of x and does not do anything
else useful. The parameters x and y are local to the
function just like t. Specifically, it does *not* do
what you intend - swap the arguments. You need to read
chapter 6 of Jenks and Sutor on functions and macros.
But the following is a quick synopsis.
In Axiom a function f is a higher-order object (in
the categorial sense) of type
f:A->B
which takes an object of type A and computes a new object
of type B. It is not normally executed for its side-
affects (if any). So we can write
swap(x) == [x.2,x.1]
which when applied as
swap([1,2])
is interpreted as a function
swap:List Integer -> List Integer
which returns the first two elements of a list in
reverse order
[2,1]
Or for an example of a function which does have side-
effects (see for example Jenks and Sutor, page 159). The
function
swap2(x) == (
t := x.1
x.1 := x.2
x.2 := t
)
when applied to
k:=[10,20,30]
is interpreted as an object of type
swap2:List Integer -> Integer
It returns the value
10
and has the side-effect of changing k
[20, 10, 30]
In Axiom we can do something like what I think you
intended by writing
macro swap(x,y) == (
t := x;
x := y;
y := t;
[x,y]
)
A macro is simply a text substitution. So
swap(a,b)
is just an abbreviation equivalent to writing
t:=a;
a:=b;
b:=t;
[a,b]
This does have the effect of swapping the values
of a and b. For example if
a:=1
b:=2
then
swap(a,b)
swap(a,b)
returns
[2,1]
[1,2]
> The same happens if if then else constructions or nested
> for statemenst are used.
In interactive input if statements also must use the ( )
block notation. For example, the example on page 160 of
Jenks and Sutor in this notation is:
bubbleSort(m) == (
n := #m;
for i in 1 .. (n-1) repeat (
for j in n .. (i+1) by -1 repeat (
if m.j < m.(j-1) then (
swap(m,j,j-1)
)
)
);
m
)
>
> Newertheless, I don't mind to have two windows open and
> to use a text file for my libary functions ;-).
Yes, you can do that. You can even use TeXmacs to write
such text files. But writing library functions is quite
different than using Axiom purely in an interactive
mode. In fact as Tim Daly has pointed out, these are
in fact somewhat different languages having a different
syntax but essentially the same semantics.
> I have currently no time to present examples, sorry, but
> I will be off from KN for a couple of days and in a hurry
> to prepare myself... If examples of failure are needed,
> I can send them next week.
>
I hope the examples that I give above (and those in the
Jenks and Sutor book) are helpful. Let's discuss it some
more when you have time.
Regards,
Bill Page.
- [Axiom-mail] RE: AXIOM / TeXmacs problems (bugs?),
Bill Page <=