[ << ] [ < ] [ Up ] [ > ] [ >> ] [Top] [Contents] [Index] [ ? ]

## 6.7 Structures

 [ << ] [ < ] [ Up ] [ > ] [ >> ] [Top] [Contents] [Index] [ ? ]

### 6.7.1 `newstruct`

newstruct(name)

:: Creates a new structure object whose name is name.

return

structure

name

string

• This function creates an new structure object whose name is name.
• A structure named name should be defined in advance.
• Each member of a structure is specified by its name using the operator `->`. If the specified member is also an structure, the specification by `->` can be nested.
```[0] struct list {h,t};
0
[1] A=newstruct(list);
{0,0}
[2] A->t = newstruct(list);
{0,0}
[3] A;
{0,{0,0}}
[4] A->h = 1;
1
[5] A->t->h = 2;
2
[6] A->t->t = 3;
3
[7] A;
{1,{2,3}}
```
References

 [ << ] [ < ] [ Up ] [ > ] [ >> ] [Top] [Contents] [Index] [ ? ]

### 6.7.2 `arfreg`

:: Registers a set of fundamental operations for a type of structure.

return

1

name

string

add sub mul div pwr chsgn comp

user defined functions

• This function registers a set of fundamental operations for a type of structure whose name is name.
• The specification of each function is as follows.
`add(A,B)`

A+B

`sub(A,B)`

A-B

`mul(A,B)`

A*B

`div(A,B)`

A/B

`pwr(A,B)`

A^B

`chsgn(A)`

-A

`comp(A,B)`

1,0,-1 according to the result of a comparison between A and B.

```% cat test
struct a {id,body}\$

{
C = newstruct(a);
C->id = A->id; C->body = A->body+B->body;
return C;
}

def sub(A,B)
{
C = newstruct(a);
C->id = A->id; C->body = A->body-B->body;
return C;
}

def mul(A,B)
{
C = newstruct(a);
C->id = A->id; C->body = A->body*B->body;
return C;
}

def div(A,B)
{
C = newstruct(a);
C->id = A->id; C->body = A->body/B->body;
return C;
}

def pwr(A,B)
{
C = newstruct(a);
C->id = A->id; C->body = A->body^B;
return C;
}

def chsgn(A)
{
C = newstruct(a);
C->id = A->id; C->body = -A->body;
return C;
}

def comp(A,B)
{
if ( A->body > B->body )
return 1;
else if ( A->body < B->body )
return -1;
else
return 0;
}

end\$
% asir
This is Risa/Asir, Version 20000908.
[11] A=newstruct(a);
{0,0}
[12] B=newstruct(a);
{0,0}
[13] A->body = 3;
3
[14] B->body = 4;
4
[15] A*B;
{0,12}
```
References

 [ << ] [ < ] [ Up ] [ > ] [ >> ] [Top] [Contents] [Index] [ ? ]

### 6.7.3 `struct_type`

struct_type(name|object)

:: Get an identity number of the structure of object and name.

return

an integer

name

string

object

a structure

• `struct_type()` returns an identity number of the structure or -1 (if an error occurs).
```[10] struct list {h,t};
0
[11] A=newstruct(list);
{0,0}
[12] struct_type(A);
3
[13] struct_type("list");
3
```
References

 [ << ] [ < ] [ Up ] [ > ] [ >> ]

This document was generated on December 18, 2018 using texi2html 5.0.