How to Reverse a List?

前端 未结 7 2190
有刺的猬
有刺的猬 2020-12-03 06:28

What is the function to a list in Scheme? It needs to be able to handle nested lists.

So that if you do something like (reverse \'(a (b c d) e)) you\'ll

7条回答
  •  日久生厌
    2020-12-03 06:55

    My solution:

    (define (rvrs ls)
      (if (null? ls)
        empty
        (append (rvrs (cdr ls)) (cons (car ls) empty))))
    

提交回复
热议问题