如何使用Scheme将数字/字符串列表转换为日期格式?

时间:2017-11-20 01:36:20

标签: scheme

如果我是一个列表,其中包含3个元素((“十月”2017年1月)(“十月”1990年第31期)(“六月”2003年5月))。如何将包含这些日期的列表作为字符串返回(“10/1/2017”“10/31/1990”“6/5/2003”)。现在我只能以格式返回第一个日期。我希望能够使用“map”功能,但我不确定如何在我的代码中使用它。

(define changeDate
    (lambda (date)
            (cond

                    ( (equal? (car(car date)) "January" ) (list 1 (car(cdr(car date))) (car(cdr(cdr(car date ))))) )
                    ( (equal? (car(car date)) "February" ) (list 2 (car(cdr(car date))) (car(cdr(cdr(car date ))))) )
                    ( (equal? (car(car date)) "March" ) (list 3  (car(cdr(car date))) (car(cdr(cdr(car date ))))) )
                    ( (equal? (car(car date)) "April" ) (list 4  (car(cdr(car date))) (car(cdr(cdr(car date ))))) )
                    ( (equal? (car(car date)) "May" ) (list 5  (car(cdr(car date))) (car(cdr(cdr(car date ))))) )
                    ( (equal? (car(car date)) "June" ) (list 6  (car(cdr(car date))) (car(cdr(cdr(car date ))))) )
                    ( (equal? (car(car date)) "July" ) (list 7  (car(cdr(car date))) (car(cdr(cdr(car date ))))) )
                    ( (equal? (car(car date)) "August" ) (list 8  (car(cdr(car date))) (car(cdr(cdr(car date ))))) )
                    ( (equal? (car(car date)) "September" ) (list 9  (car(cdr(car date))) (car(cdr(cdr(car date ))))) )
                    ( (equal? (car(car date)) "October" ) (list 10  (car(cdr(car date))) (car(cdr(cdr(car date ))))) )
                    ( (equal? (car(car date)) "November" ) (list 11  (car(cdr(car date))) (car(cdr(cdr(car date ))))) )
                    ( (equal? (car(car date)) "December" ) (list 12  (car(cdr(car date))) (car(cdr(cdr(car date ))))) )



            )
    ))

1 个答案:

答案 0 :(得分:0)

  1. (car date)中的所有changeDate表单更改为date - 这会将函数changeDate转换为对表单{的日期列表进行操作的表单("October" 1 2017) {1}}而不是那些在这些表格的列表上运作的

  2. 现在(map changeDate '(("October" 1 2017) ("October" 31 1990) ("June" 5 2003)))应该有效