2011-02-28 88 views
1

我一直在考慮一個struct一起工作的工作:球拍/方案:與結構

(struct Binding (id (value #:mutable))) 

這個結構表示一個變量綁定,如(set! x 3)在那裏我會想到ID = x和值= 3

如何創建和初始化此結構?我如何獲得idvalue的值並設置值爲value

+2

回覆:教科書請求。你見過「如何設計程序」嗎?它由Racket的作者撰寫,它在亞馬遜上有五顆星,最重要的是,它可以通過htdp.org在線獲得。 – 2011-02-28 16:53:29

回答

3
> (struct Binding (id (value #:mutable))) 
> (define b (Binding 'x 123)) 
> (Binding-id b) 
'x 
> (Binding-value b) 
123 
> (set-Binding-value! b 456) 
> (Binding-value b) 
456 

(另見structs文檔頁。)

+0

非常感謝! :-) – Schemer 2011-03-02 04:26:42