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

1.3     ! ohara       1: @comment $OpenXM: OpenXM/src/asir-doc/parts/builtin/structure.texi,v 1.2 2003/04/19 15:44:59 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}.
1.3     ! ohara     111: \E
        !           112: \BJP
        !           113: @item
        !           114: $BEPO?$7$?$/$J$$4pK\1i;;$KBP$7$F$O0z?t$K(B 0 $B$rM?$($k(B.
        !           115: $B$3$l$K$h$C$F0lIt$N1i;;$N$_$rMxMQ$9$k$3$H$,$G$-$k(B.
1.1       noro      116: \E
                    117: @item
                    118: \JP $B$=$l$>$l$N4X?t$N;EMM$O<!$NDL$j$G$"$k(B.
                    119: \EG The specification of each function is as follows.
1.2       noro      120: @table @code
1.1       noro      121: @item add(A,B)
                    122: A+B
                    123: @item sub(A,B)
                    124: A-B
                    125: @item mul(A,B)
                    126: A*B
                    127: @item div(A,B)
                    128: A/B
                    129: @item pwr(A,B)
                    130: A^B
                    131: @item chsgn(A)
                    132: -A
                    133: @item comp(A,B)
                    134: 1,0,-1 according to the result of a comparison between A and B.
                    135: @end table
                    136: @end itemize
                    137:
                    138: @example
                    139: % cat test
                    140: struct a @{id,body@}$
                    141:
                    142: def add(A,B)
                    143: @{
                    144:   C = newstruct(a);
                    145:   C->id = A->id; C->body = A->body+B->body;
                    146:   return C;
                    147: @}
                    148:
                    149: def sub(A,B)
                    150: @{
                    151:   C = newstruct(a);
                    152:   C->id = A->id; C->body = A->body-B->body;
                    153:   return C;
                    154: @}
                    155:
                    156: def mul(A,B)
                    157: @{
                    158:   C = newstruct(a);
                    159:   C->id = A->id; C->body = A->body*B->body;
                    160:   return C;
                    161: @}
                    162:
                    163: def div(A,B)
                    164: @{
                    165:   C = newstruct(a);
                    166:   C->id = A->id; C->body = A->body/B->body;
                    167:   return C;
                    168: @}
                    169:
                    170: def pwr(A,B)
                    171: @{
                    172:   C = newstruct(a);
                    173:   C->id = A->id; C->body = A->body^B;
                    174:   return C;
                    175: @}
                    176:
                    177: def chsgn(A)
                    178: @{
                    179:   C = newstruct(a);
                    180:   C->id = A->id; C->body = -A->body;
                    181:   return C;
                    182: @}
                    183:
                    184: def comp(A,B)
                    185: @{
                    186:   if ( A->body > B->body )
                    187:     return 1;
                    188:   else if ( A->body < B->body )
                    189:     return -1;
                    190:   else
                    191:     return 0;
                    192: @}
                    193:
                    194: arfreg("a",add,sub,mul,div,pwr,chsgn,comp)$
                    195: end$
                    196: % asir
                    197: This is Risa/Asir, Version 20000908.
                    198: Copyright (C) FUJITSU LABORATORIES LIMITED.
                    199: 1994-2000. All rights reserved.
                    200: [0] load("./test")$
                    201: [11] A=newstruct(a);
                    202: @{0,0@}
                    203: [12] B=newstruct(a);
                    204: @{0,0@}
                    205: [13] A->body = 3;
                    206: 3
                    207: [14] B->body = 4;
                    208: 4
                    209: [15] A*B;
                    210: @{0,12@}
                    211: @end example
                    212:
                    213: @table @t
                    214: \JP @item $B;2>H(B
                    215: \EG @item References
                    216: @fref{newstruct},
                    217: \JP @fref{$B9=B$BNDj5A(B}
                    218: \EG @fref{structure definition}
                    219: @end table

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