[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


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


is interpreted as a function

  swap:List Integer -> List Integer

which returns the first two elements of a list in
reverse order


Or for an example of a function which does have side-
effects (see for example Jenks and Sutor, page 159). The

  swap2(x) == (
    t := x.1
    x.1 := x.2
    x.2 := t

when applied to


is interpreted as an object of type

  swap2:List Integer -> Integer

It returns the value


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;

A macro is simply a text substitution. So


is just an abbreviation equivalent to writing


This does have the effect of swapping the values
of a and b. For example if






> 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 (

> 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.

Bill Page.

reply via email to

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