2012-12-21 1 views

답변

1

일반적인 색인 생성을 table에 넣기 만하면됩니다. 이전에 할당되지 않은 이름 Y은 이되며 색인이 지정된 항목 Y[a]에 할당됩니다.

restart: 
Y[a]:=211: 

Y[a]; 
          211 

Y[b]; 
          Y[b] 

assigned(Y[a]); 
          true 

assigned(Y[b]); 
         false 

eval(Y); 
         table([a = 211]) 

, 그것은 Y[b] 아직 할당되지 않은 경우 Y[b] 반환 NULL 접근이 설명한 기능을 얻기 위해 포장의 작은 비트입니다,

사용자 정의의 수 등 모든 것을 말해 두 겠는데 Maple은 table이 더 일반적으로 색인 될 수 있도록 keysymbol 인 오류 검사 및 제한을 제거 (또는 제거)합니다.

restart: 

addKeyValuePair:=proc(containerRef::{indexed,symbol}, L::list) 
    if nops(L) <> 2 then 
    error "expecting list with two entries"; end if; 
    if not type(L[1], symbol) then 
    error "expecting list with symbol as first entry"; end if; 
    containerRef[L[1]]:=L[2]; 
    NULL; 
end proc: 

searchByKey:=proc(containerRef::{indexed,symbol}, key::name) 
    if assigned(containerRef[key]) then 
    containerRef[key]; 
    else 
    NULL; 
    end if; 
end proc: 

addKeyValuePair(Y, [a, 4.5]); 

searchByKey(Y, a); 
          4.5 

searchByKey(Y, b); 

searchByKey(Q, b); 

addKeyValuePair(Y, [a, 211]); 

searchByKey(Y, a); 
          211 

addKeyValuePair(Y, [c]); 
Error, (in addKeyValuePair) expecting list with two entries 

addKeyValuePair(Y, [2.34, 211]); 
Error, (in addKeyValuePair) expecting list with symbol as first entry 

table은 변경 가능한 데이터 구조입니다. 그것은 last_name_eval 타입이며 결과적으로 프로 시저 호출에 인수로 "참조로"전달됩니다.

관련 문제