| [ << ] | [ < ] | [上] | [ > ] | [ >> ] | [冒頭] | [目次] | [見出し] | [ ? ] |
6.7.1 newstruct | ||
6.7.2 arfreg | ||
6.7.3 struct_type |
| [ << ] | [ < ] | [上] | [ > ] | [ >> ] | [冒頭] | [目次] | [見出し] | [ ? ] |
newstruct:: 構造体名が nameの構造体を生成する.
構造体
文字列
-> により名前でアクセスする.
メンバが構造体の場合, 更に -> による指定を続けることができる.
[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}}
| [ << ] | [ < ] | [上] | [ > ] | [ >> ] | [冒頭] | [目次] | [見出し] | [ ? ] |
arfreg:: 構造体に体する基本演算を登録する.
1
文字列
ユーザ定義関数
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}$
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}
| [ << ] | [ < ] | [上] | [ > ] | [ >> ] | [冒頭] | [目次] | [見出し] | [ ? ] |
struct_type:: 構造体の識別番号を取得する.
整数
文字列
構造体
[10] struct list {h,t};
0
[11] A=newstruct(list);
{0,0}
[12] struct_type(A);
3
[13] struct_type("list");
3
| [ << ] | [ < ] | [上] | [ > ] | [ >> ] |
この文書は10月 29, 2025にtexi2html 5.0を用いて生成されました。