编写可移植的Scheme代码的最佳方法?
在 Common Lisp 中,我可以有条件地排除或包含不同实现的代码,如下所示:
#+sbcl (use-sbcl-cool-feature)
#-sbcl (use-my-own-not-so-cool-version)
这样我可以通过隔离不可移植位来编写可移植代码。
在Scheme中如何做到这一点?有没有办法像这样询问Scheme解释器或编译器的名称(甚至它实现的标准)?
(cond ((r6rs?)
(make-eq-hashtable))
((gambit?)
(make-table))
;; other cases here
(#t (make-my-inefficient-hash-table))
我知道我可以将所有可能的不可移植代码片段包装在不同的过程中,然后具有如下所示的兼容性包:
;; in my-libs-gambit.scm:
(define make-hash-table make-table)
同样对于 my-libs-[other-schemes-here].scm
这是唯一的方法吗?
我不会尝试在Scheme中制作一个完全可移植的应用程序,但如果我能让我的程序在两个或三个不同的实现中运行,那就太好了。
In Common Lisp I can conditionally exclude or include code for different implementations like this:
#+sbcl (use-sbcl-cool-feature)
#-sbcl (use-my-own-not-so-cool-version)
This way I can write portable code by isolating the non-portable bits.
How can this be done in Scheme? Is there a way to ask the Scheme interpreter or compiler its name (or even which standard it implements) like this?
(cond ((r6rs?)
(make-eq-hashtable))
((gambit?)
(make-table))
;; other cases here
(#t (make-my-inefficient-hash-table))
I know I could wrap all possible non-portable pieces of code in different procedures and then have compatibility packages like this:
;; in my-libs-gambit.scm:
(define make-hash-table make-table)
And simlarly for my-libs-[other-schemes-here].scm
Is that the only way to do it?
I wouldn't try to make a completely portable application in Scheme, but it would be nice if I could make my progams run in two or maybe three different implementations.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
演讲幻灯片,作者:Dorai Sitaram这个话题。
遵循此处给出的指示也可能有所帮助。
Slides of a talk by Dorai Sitaram on this topic.
Following the directions given here also might help.