Next: , Previous: , Up: 代码风格   [Contents][Index]


22.5.3 数据类型和模式匹配

经典的Lisp倾向于用列表表示所有的东西,然后用carcdrcadr等手动浏览它们。这种风格有几个问题,特别是难以阅读,易出错,并且妨碍生成合适的类型错误报告。

Guix code should define appropriate data types (for instance, using define-record-type*) rather than abuse lists. In addition, it should use pattern matching, via Guile’s (ice-9 match) module, especially when matching lists (see Pattern Matching in GNU Guile Reference Manual); pattern matching for records is better done using match-record from (guix records), which, unlike match, verifies field names at macro-expansion time.