我正在 PLT Scheme 中编写一个应用程序(A juggling pattern animator),它接受 Scheme 表达式作为某些字段的值。我正在尝试编写一个小型文本编辑器,它可以让我将表达式“分解”成仍然可以评估但包含数据作为手动调整的文字的表达式。
例如,
(4hss->sexp "747")
是一个生成合法模式的函数调用。如果我评估并打印它,它就会变成
(((7 3) - - -) (- - (4 2) -) (- (7 2) - -) (- - - (7 1)) ((4 0) - - -) (- - (7 0) -) (- (7 2) - -) (- - - (4 3)) ((7 3) - - -) (- - (7 0) -) (- (4 1) - -) (- - - (7 1)))
它可以作为字符串“读取”,但不会与函数“评估”相同。当然,对于这个声明,我需要的很简单
(quote (((7 3...
但其他例子并非微不足道。例如,这个包含打印为向量的结构:
pair-of-jugglers
; -->
(#(struct:hand #(struct:position -0.35 2.0 1.0) #(struct:position -0.6 2.05 1.1) 1.832595714594046) #(struct:hand #(struct:position 0.35 2.0 1.0) #(struct:position 0.6 2.0500000000000003 1.1) 1.308996938995747) #(struct:hand #(struct:position 0.35 -2.0 1.0) #(struct:position 0.6 -2.05 1.1) -1.3089969389957472) #(struct:hand #(struct:position -0.35 -2.0 1.0) #(struct:position -0.6 -2.05 1.1) -1.8325957145940461))
我已经想到了至少三种可能的解决方案,但没有一个是我非常喜欢的。
在我再次开始做不好的递归梦之前帮助我。