Hi,

I sent a message asking for help a couple of weeks ago. Thanks to those =
who responded. I have a more concrete question:

I am trying to write a simple recursive function to build binary trees =
from a List object. My test tree is the following:

treeList :=3D [e,[5,1],[[a,[1,1],b], [1,1], [c,[1,2],d]]]

Each nested level contains a list of three elements, which are to become =
the left branch, value, and right branch of the tree, respectively. For =
internal nodes, the value of the tree is a two-element list representing =
the left- and right branch lengths. The leaves of the tree are to be =
binary trees with a Symbol as the value (a to e) and empty left - and =
right branches. Here is my code:

buildTree(lst: List Any):BTREE(Any) =3D=3D binaryTree(buildTree(lst.1), =
lst.2, buildTree(lst.3))

buildTree(val:Symbol):BTREE(Any) =3D=3D binaryTree(val)

However, calling buildTree(treeList) doesn't work. The second rule =
overwrites the first rule, even though the arguments are of different =
types. I'm still getting my head around how types are specified in =
Axiom, so any assistance would be greatly valued.

Thanks in advance,

Simon.

Simon Blomberg, BSc (Hons), PhD, MAppStat.

Lecturer and Consultant Statistician

School of Biological Sciences

The University of Queensland

St. Lucia Queensland 4072

Australia

T: +61 7 3365 2506

email: S.Blomberg1_at_uq.edu.au

http://www.uq.edu.au/~uqsblomb/<=
/A>

Policies:

1. I will NOT analyse your data for you.

2. Your deadline is your problem.

The combination of some data and an aching desire for

an answer does not ensure that a reasonable answer can

be extracted from a given body of data. - John Tukey.

Hi Bill,

Thanks for that! I really needed to know about dom. Many years ago, I =
used XLisp-Stat as my primary programming platform, so I am used to car, =
cdr and friends. I have a question. In your code there is the =
clause:

car dom(lst.1)=3D'List::SExpression

When and how does this get evaluated? When I type it in to the =
interpreter, I get:

(21) -> car dom(treeList.1) =3D 'List::SExpression

(21) Variable=3D List

Which does not get evaluated to a Boolean False. What gives? I think I =
understand the rest of your code. Thanks again.

Simon.

Simon Blomberg, BSc (Hons), PhD, MAppStat.

Lecturer and Consultant Statistician

School of Biological Sciences

The University of Queensland

St. Lucia Queensland 4072

Australia

T: +61 7 3365 2506

email: S.Blomberg1_at_uq.edu.au

http://www.uq.edu.au/~uqsblomb/<=
/A>

Policies:

1. I will NOT analyse your data for you.

2. Your deadline is your problem.

The combination of some data and an aching desire for

an answer does not ensure that a reasonable answer can

be extracted from a given body of data. - John Tukey.

-----Original Message-----

From: Bill Page [mailto:bill.page@newsynthesis.=
org]

Sent: Tue 7/04/2009 2:01 PM

To: Simon Blomberg

Cc: axiom-mail@nongnu.org

Subject: Re: [Axiom-mail] Programming with BTREEs.

Simon,

Here is one solution:

(1) -> )r treelist.input

buildTree(lst:List Any):BTREE(Any) =3D=3D binaryTree( _

(car dom(lst.1)=3D'List::SExpression =3D> =
buildTree(lst.1); _

binaryTree(lst.1)),_

lst.2,_

(car dom(lst.3)=3D'List::SExpression =3D> =
buildTree(lst.3);_

binaryTree(lst.3)))

Function declaration buildTree : List Any -> BinaryTree =
Any has been

added to workspace.

&=
nbsp; &n=
bsp; &nb=
sp; &nbs=
p; Type: Void

(2) -> treeList :=3D [e,[5,1],[[a,[1,1],b], [1,1], [c,[1,2],d]]]

(2) [e,[5,1],[[a,[1,1],b],[1,1],[c,[1,2],d]]]

&=
nbsp; &n=
bsp; &nb=
sp; &nbs=
p; Type: List Any

(3) -> buildTree(treeList)

(3) [e,[5,1],[[a,[1,1],b],[1,1],[c,[1,2],d]]]

&=
nbsp; &n=
bsp; &nb=
sp; &nbs=
p; Type: BinaryTree Any

---

'Any' is a very special type in Axiom. It is probably not a good =
place

to start to learn about types - or maybe it is if you can tolerate =
the

complexity of this answer :-)

Explanation:

Overloaded function names are not supported in the Axiom =
interpreter.

They are only available when writing in the library compiler =
language

called SPAD. But even if you wrote in SPAD, the function as you =
wrote

it originally would not work because in SPAD, types are static - =
that

is they are decided at the time you compile the program, not at the

time you run it. What you wrote requires dynamic type.

The type 'Any' is used to dynamically encapsulate values of any type

as a single type and that way avoid much of the type-checking

mechanism that would otherwise make this sort of routine rather

awkward. It is sometimes referred to in computer science literature =
as

"duck typing".

There are several ways to query the real type of the value

encapsulated as a value of type Any. This can be done by the =
function

'dom' which returns something in "Lisp form" called an =
s-expression.

In the case of a value of type List, the first component of the

s-expression (obtained by the function 'car') is the literal symbol

List.

The way to read the expression:

(car dom(lst.1)=3D'List::SExpression =3D> =
buildTree(lst.1); _

binaryTree(lst.1)),_

is:

Check if the first item in lst is a List.

If it is, call 'buildTree' recursively with the value.

Otherwise call 'binaryTree' with the value.

Ref:

(4) -> )show Any

(4) -> )show SExpression

Regards,

Bill Page.

On Mon, Apr 6, 2009 at 9:55 PM, Simon Blomberg =
<s.blomberg1@uq.edu.au> wrote:

> Hi,

>

> I sent a message asking for help a couple of weeks ago. Thanks to =
those who

> responded. I have a more concrete question:

>

> I am trying to write a simple recursive function to build binary =
trees from

> a List object. My test tree is the following:

>

> treeList :=3D [e,[5,1],[[a,[1,1],b], [1,1], [c,[1,2],d]]]

>

> Each nested level contains a list of three elements, which are to =
become the

> left branch, value, and right branch of the tree, respectively. For =
internal

> nodes, the value of the tree is a two-element list representing the =
left-

> and right branch lengths. The leaves of the tree are to be binary =
trees with

> a Symbol as the value (a to e) and empty left - and right branches. =
Here is

> my code:

>

> buildTree(lst: List Any):BTREE(Any) =3D=3D =
binaryTree(buildTree(lst.1), lst.2,

> buildTree(lst.3))

> buildTree(val:Symbol):BTREE(Any)=A0 =3D=3D binaryTree(val)

>

> However, calling buildTree(treeList) doesn't work. The second =
rule

> overwrites the first rule, even though the arguments are of =
different types.

> I'm still getting my head around how types are specified in Axiom, =
so any

> assistance would be greatly valued.

>

> Thanks in advance,

>

> Simon.

>

> Simon Blomberg, BSc (Hons), PhD, MAppStat.

> Lecturer and Consultant Statistician

> School of Biological Sciences

> The University of Queensland

> St. Lucia Queensland 4072

> Australia

> T: +61 7 3365 2506

> email: S.Blomberg1_at_uq.edu.au

> http://www.uq.edu.au/~uqsblomb/<=
/A>

>

> Policies:

> 1.=A0 I will NOT analyse your data for you.

> 2.=A0 Your deadline is your problem.

>

> The combination of some data and an aching desire for

> an answer does not ensure that a reasonable answer can

> be extracted from a given body of data. - John Tukey.

>

>

> _______________________________________________

> Axiom-mail mailing list

> Axiom-mail@nongnu.org

> http://lists=
.nongnu.org/mailman/listinfo/axiom-mail

>

>

I am the rawest beginner at Axiom -- so new that I haven't yet successfully installed it. I am not yet familiar with the appropriate venues for requesting help, so my apologies if this e-mail has been posted incorrectly. Here's my problem:

I have downloaded the file axiom-ubuntu-mar2009-bin.tgz. from the website http://axiom.axiom-developer.org/axiom-website/download.html. When trying to decompress that file I received error messages from Ubuntu 8.10's decompression program as well as from WinZip 10.0 (running under Windows XP). The message from WinZip read "Invalid compressed data -- unable to inflate", but WinZip does display a list of files.

The same thing happened after I downloaded a second and third time, and after downloading on a second computer. The files that WinZip lists after it achieves what appears to be a partial decompression are significantly less in number than the 6570 files listed in a successful decompression of axiom-ubuntu-jan2009-bin.tgz.

My conclusion is that the archive file axiom-ubuntu-mar2009-bin.tgz has been corrupted and needs to be replaced. Who do I contact (name and e-mail address) about this conclusion?

Greg Grunberg

grunberg@wans.net

I have downloaded the file axiom-ubuntu-mar2009-bin.tgz. from the website http://axiom.axiom-developer.org/axiom-website/download.html. When trying to decompress that file I received error messages from Ubuntu 8.10's decompression program as well as from WinZip 10.0 (running under Windows XP). The message from WinZip read "Invalid compressed data -- unable to inflate", but WinZip does display a list of files.

The same thing happened after I downloaded a second and third time, and after downloading on a second computer. The files that WinZip lists after it achieves what appears to be a partial decompression are significantly less in number than the 6570 files listed in a successful decompression of axiom-ubuntu-jan2009-bin.tgz.

My conclusion is that the archive file axiom-ubuntu-mar2009-bin.tgz has been corrupted and needs to be replaced. Who do I contact (name and e-mail address) about this conclusion?

Greg Grunberg

grunberg@wans.net