我可以将符号列表分配给Guile中的元素列表吗?

时间:2014-01-24 01:59:12

标签: scheme guile

我正在编写一些获取设定长度列表的guile代码,我需要为列表中的每个元素定义一个变量。 目前,我必须做这样的事情:

(define (foo l)
  (let ((e-1 (car l))
        (e-2 (cadr l))
        (e-2 (caddr l))
        ; ...
        (e-n (list-ref (- n 1)
                       l)))
    (compute)))

这让超级乏味。无论如何我可以做这样的事情吗?

(define (foo l)
  (symbol-def e-1 e-2 e-3 e-4 e-n l)
  (compute))

编辑:提出更具针对性的问题。

1 个答案:

答案 0 :(得分:0)

特定于Guile,我找到了ice-9 match module,其格式如下:

(match lst
    ((pattern) expr))

示例:

(use-modules (ice-9 match))

(let ((l '(test foo bar)))
  (match l
    ((head second third)
     second)))

; returns `foo`
相关问题