2011-02-28 69 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