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

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

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