[BACK]Return to structure.texi CVS log [TXT][DIR] Up to [local] / OpenXM / src / asir-doc / parts / builtin

File: [local] / OpenXM / src / asir-doc / parts / builtin / structure.texi (download)

Revision 1.4, Thu Dec 18 10:26:20 2003 UTC (20 years, 5 months ago) by ohara
Branch: MAIN
CVS Tags: R_1_3_1-2, RELEASE_1_3_1_13b, RELEASE_1_2_3_12, RELEASE_1_2_3, RELEASE_1_2_2_KNOPPIX_b, RELEASE_1_2_2_KNOPPIX, KNOPPIX_2006, HEAD, DEB_REL_1_2_3-9
Changes since 1.3: +54 -1 lines

Add sections into the Risa/Asir manusl.
(vector, list, structure, asir grammer, and several functions.)

@comment $OpenXM: OpenXM/src/asir-doc/parts/builtin/structure.texi,v 1.4 2003/12/18 10:26:20 ohara Exp $
\BJP
@node $B9=B$BN(B,,, $BAH$_9~$_H!?t(B
@section $B9=B$BN(B
\E
\BEG
@node Structures,,, Built-in Function
@section Structures
\E

@menu
* newstruct::
* arfreg::
* struct_type::
@end menu

\JP @node newstruct,,, $B9=B$BN(B
\EG @node newstruct,,, Structures
@subsection @code{newstruct}
@findex newstruct

@table @t
@item newstruct(@var{name})
\JP :: $B9=B$BNL>$,(B @var{name}$B$N9=B$BN$r@8@.$9$k(B. 
\EG :: Creates a new structure object whose name is @var{name}.
@end table

@table @var
@item return
\JP $B9=B$BN(B
\EG structure
@item name
\JP $BJ8;zNs(B
\EG string
@end table

@itemize @bullet
@item
\JP $BL>A0$,(B @var{name} $B$G$"$k9=B$BN$r@8@.$9$k(B. 
\EG This function creates an new structure object whose name is @var{name}.
@item
\JP $B$"$i$+$8$a(B, @var{name} $B$J$k9=B$BN$,Dj5A$5$l$F$$$J$1$l$P$J$i$J$$(B. 
\EG A structure named @var{name} should be defined in advance.
@item 
\BJP
$B9=B$BN$N3F%a%s%P$O1i;;;R(B @code{->} $B$K$h$jL>A0$G%"%/%;%9$9$k(B.
$B%a%s%P$,9=B$BN$N>l9g(B, $B99$K(B @code{->} $B$K$h$k;XDj$rB3$1$k$3$H$,$G$-$k(B. 
\E
\BEG
Each member of a structure is specified by its name using the operator
@code{->}. If the specified member is also an structure, the specification
by @code{->} can be nested.
\E
@end itemize

@example
[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@}@}
@end example

@table @t
\JP @item $B;2>H(B
\EG @item References
@fref{arfreg},
\JP @fref{$B9=B$BNDj5A(B}
\EG @fref{structure definition}
@end table

\JP @node arfreg,,, $B9=B$BN(B
\EG @node arfreg,,, Structures
@subsection @code{arfreg}
@findex arfreg

@table @t
@item arfreg(@var{name},@var{add},@var{sub},@var{mul},@var{div},@var{pwr},@var{chsgn},@var{comp})
\JP :: $B9=B$BN$KBN$9$k4pK\1i;;$rEPO?$9$k(B. 
\EG :: Registers a set of fundamental operations for a type of structure.
@end table

@table @var
@item return
\JP 1
\EG 1
@item name
\JP $BJ8;zNs(B
\EG string
@item add  sub  mul  div  pwr  chsgn  comp
\JP $B%f!<%6Dj5A4X?t(B
\EG user defined functions
@end table

@itemize @bullet
@item 
\JP @var{name} $B$J$k9=B$BN7?$KBP$9$k4pK\1i;;$rEPO?$9$k(B. 
\BEG
This function registers a set of fundamental operations for a type
of structure whose name is @var{name}.
\E
\BJP
@item
$BEPO?$7$?$/$J$$4pK\1i;;$KBP$7$F$O0z?t$K(B 0 $B$rM?$($k(B.
$B$3$l$K$h$C$F0lIt$N1i;;$N$_$rMxMQ$9$k$3$H$,$G$-$k(B.
\E
@item
\JP $B$=$l$>$l$N4X?t$N;EMM$O<!$NDL$j$G$"$k(B. 
\EG The specification of each function is as follows.
@table @code
@item add(A,B)
A+B
@item sub(A,B)
A-B
@item mul(A,B)
A*B
@item div(A,B)
A/B
@item pwr(A,B)
A^B
@item chsgn(A)
-A
@item comp(A,B)
1,0,-1 according to the result of a comparison between A and B.
@end table
@end itemize

@example
% cat test
struct a @{id,body@}$

def add(A,B)
@{
  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;
@}

arfreg("a",add,sub,mul,div,pwr,chsgn,comp)$
end$
% asir
This is Risa/Asir, Version 20000908.
Copyright (C) FUJITSU LABORATORIES LIMITED.
1994-2000. All rights reserved.
[0] load("./test")$
[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@}
@end example

@table @t
\JP @item $B;2>H(B
\EG @item References
@fref{newstruct},
\JP @fref{$B9=B$BNDj5A(B}
\EG @fref{structure definition}
@end table

\JP @node struct_type,,, $B9=B$BN(B
\EG @node struct_type,,, Structures
@subsection @code{struct_type}
@findex struct_type

@table @t
@item struct_type(@var{name}|@var{object})
\JP :: $B9=B$BN$N<1JLHV9f$r<hF@$9$k(B. 
\EG :: Get an identity number of the structure of @var{object} and @var{name}.
@end table

@table @var
@item return
\JP $B@0?t(B
\EG an integer
@item name
\JP $BJ8;zNs(B
\EG string
@item object
\JP $B9=B$BN(B
\EG a structure
@end table

@itemize @bullet
@item
\BJP
$BL>A0$,(B @var{name} $B$G$"$k9=B$BN(B, $B$^$?$O(B @var{object} $B$N;X$99=B$BN$N<1JLHV9f$r<hF@$9$k(B. $B%(%i!<$N$H$-$O(B -1 $B$rJV$9(B.
\E
\BEG
@code{struct_type()} returns an identity number of the structure or -1 (if an error occurs).
\E
@end itemize

@example
[10] struct list @{h,t@};    
0
[11] A=newstruct(list);
@{0,0@}
[12] struct_type(A);
3
[13] struct_type("list");
3
@end example

@table @t
\JP @item $B;2>H(B
\EG @item References
@fref{newstruct},
\JP @fref{$B9=B$BNDj5A(B}
\EG @fref{structure definition}
@end table