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

Annotation of OpenXM/src/asir-doc/parts/builtin/structure.texi, Revision 1.2

1.2     ! noro        1: @comment $OpenXM: OpenXM/src/asir-doc/parts/builtin/structure.texi,v 1.1 2000/09/25 06:25:11 noro Exp $
1.1       noro        2: \BJP
                      3: @node $B9=B$BN(B,,, $BAH$_9~$_H!?t(B
                      4: @section $B9=B$BN(B
                      5: \E
                      6: \BEG
                      7: @node Structures,,, Built-in Function
                      8: @section Structures
                      9: \E
                     10:
                     11: @menu
                     12: * newstruct::
                     13: * arfreg::
                     14: @end menu
                     15:
                     16: \JP @node newstruct,,, $B9=B$BN(B
                     17: \EG @node newstruct,,, Structures
                     18: @subsection @code{newstruct}
                     19: @findex newstruct
                     20:
                     21: @table @t
                     22: @item newstruct(@var{name})
                     23: \JP :: $B9=B$BNL>$,(B @var{name}$B$N9=B$BN$r@8@.$9$k(B.
                     24: \EG :: Creates a new structure object whose name is @var{name}.
                     25: @end table
                     26:
                     27: @table @var
                     28: @item return
                     29: \JP $B9=B$BN(B
                     30: \EG structure
                     31: @item name
                     32: \JP $BJ8;zNs(B
                     33: \EG string
                     34: @end table
                     35:
                     36: @itemize @bullet
                     37: @item
                     38: \JP $BL>A0$,(B @var{name} $B$G$"$k9=B$BN$r@8@.$9$k(B.
                     39: \EG This function creates an new structure object whose name is @var{name}.
                     40: @item
                     41: \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.
                     42: \EG A structure named @var{name} should be defined in advance.
                     43: @item
                     44: \BJP
                     45: $B9=B$BN$N3F%a%s%P$O1i;;;R(B @code{->} $B$K$h$jL>A0$G%"%/%;%9$9$k(B.
                     46: $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.
                     47: \E
                     48: \BEG
                     49: Each member of a structure is specified by its name using the operator
                     50: @code{->}. If the specified member is also an structure, the specification
                     51: by @code{->} can be nested.
                     52: \E
                     53: @end itemize
                     54:
                     55: @example
                     56: [0] struct list @{h,t@};
                     57: 0
                     58: [1] A=newstruct(list);
                     59: @{0,0@}
                     60: [2] A->t = newstruct(list);
                     61: @{0,0@}
                     62: [3] A;
                     63: @{0,@{0,0@}@}
                     64: [4] A->h = 1;
                     65: 1
                     66: [5] A->t->h = 2;
                     67: 2
                     68: [6] A->t->t = 3;
                     69: 3
                     70: [7] A;
                     71: @{1,@{2,3@}@}
                     72: @end example
                     73:
                     74: @table @t
                     75: \JP @item $B;2>H(B
                     76: \EG @item References
                     77: @fref{arfreg},
                     78: \JP @fref{$B9=B$BNDj5A(B}
                     79: \EG @fref{structure definition}
                     80: @end table
                     81:
                     82: \JP @node arfreg,,, $B9=B$BN(B
                     83: \EG @node arfreg,,, Structures
                     84: @subsection @code{arfreg}
                     85: @findex arfreg
                     86:
                     87: @table @t
                     88: @item arfreg(@var{name},@var{add},@var{sub},@var{mul},@var{div},@var{pwr},@var{chsgn},@var{comp})
                     89: \JP :: $B9=B$BN$KBN$9$k4pK\1i;;$rEPO?$9$k(B.
                     90: \EG :: Registers a set of fundamental operations for a type of structure.
                     91: @end table
                     92:
                     93: @table @var
                     94: @item return
                     95: \JP 1
                     96: \EG 1
                     97: @item name
                     98: \JP $BJ8;zNs(B
                     99: \EG string
1.2     ! noro      100: @item add  sub  mul  div  pwr  chsgn  comp
1.1       noro      101: \JP $B%f!<%6Dj5A4X?t(B
                    102: \EG user defined functions
                    103: @end table
                    104:
                    105: @itemize @bullet
                    106: @item
                    107: \JP @var{name} $B$J$k9=B$BN7?$KBP$9$k4pK\1i;;$rEPO?$9$k(B.
                    108: \BEG
                    109: This function registers a set of fundamental operations for a type
                    110: of structure whose name is @var{name}.
                    111: \E
                    112: @item
                    113: \JP $B$=$l$>$l$N4X?t$N;EMM$O<!$NDL$j$G$"$k(B.
                    114: \EG The specification of each function is as follows.
1.2     ! noro      115: @table @code
1.1       noro      116: @item add(A,B)
                    117: A+B
                    118: @item sub(A,B)
                    119: A-B
                    120: @item mul(A,B)
                    121: A*B
                    122: @item div(A,B)
                    123: A/B
                    124: @item pwr(A,B)
                    125: A^B
                    126: @item chsgn(A)
                    127: -A
                    128: @item comp(A,B)
                    129: 1,0,-1 according to the result of a comparison between A and B.
                    130: @end table
                    131: @end itemize
                    132:
                    133: @example
                    134: % cat test
                    135: struct a @{id,body@}$
                    136:
                    137: def add(A,B)
                    138: @{
                    139:   C = newstruct(a);
                    140:   C->id = A->id; C->body = A->body+B->body;
                    141:   return C;
                    142: @}
                    143:
                    144: def sub(A,B)
                    145: @{
                    146:   C = newstruct(a);
                    147:   C->id = A->id; C->body = A->body-B->body;
                    148:   return C;
                    149: @}
                    150:
                    151: def mul(A,B)
                    152: @{
                    153:   C = newstruct(a);
                    154:   C->id = A->id; C->body = A->body*B->body;
                    155:   return C;
                    156: @}
                    157:
                    158: def div(A,B)
                    159: @{
                    160:   C = newstruct(a);
                    161:   C->id = A->id; C->body = A->body/B->body;
                    162:   return C;
                    163: @}
                    164:
                    165: def pwr(A,B)
                    166: @{
                    167:   C = newstruct(a);
                    168:   C->id = A->id; C->body = A->body^B;
                    169:   return C;
                    170: @}
                    171:
                    172: def chsgn(A)
                    173: @{
                    174:   C = newstruct(a);
                    175:   C->id = A->id; C->body = -A->body;
                    176:   return C;
                    177: @}
                    178:
                    179: def comp(A,B)
                    180: @{
                    181:   if ( A->body > B->body )
                    182:     return 1;
                    183:   else if ( A->body < B->body )
                    184:     return -1;
                    185:   else
                    186:     return 0;
                    187: @}
                    188:
                    189: arfreg("a",add,sub,mul,div,pwr,chsgn,comp)$
                    190: end$
                    191: % asir
                    192: This is Risa/Asir, Version 20000908.
                    193: Copyright (C) FUJITSU LABORATORIES LIMITED.
                    194: 1994-2000. All rights reserved.
                    195: [0] load("./test")$
                    196: [11] A=newstruct(a);
                    197: @{0,0@}
                    198: [12] B=newstruct(a);
                    199: @{0,0@}
                    200: [13] A->body = 3;
                    201: 3
                    202: [14] B->body = 4;
                    203: 4
                    204: [15] A*B;
                    205: @{0,12@}
                    206: @end example
                    207:
                    208: @table @t
                    209: \JP @item $B;2>H(B
                    210: \EG @item References
                    211: @fref{newstruct},
                    212: \JP @fref{$B9=B$BNDj5A(B}
                    213: \EG @fref{structure definition}
                    214: @end table

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>