How to Reverse a List?

前端 未结 7 2177
有刺的猬
有刺的猬 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:54

    This is a reverse function in Racket which I like much better that Scheme. It uses the match pattern matching function only.

    (define/match (rev l)
        [('()) '()]
        [((list a ... b)) (cons b (rev a))])
    
    > (rev '(a (b c d) e))
    '(e (b c d) a)
    

提交回复
热议问题