removing last element of a list(scheme)

后端 未结 6 857
忘了有多久
忘了有多久 2021-02-07 18:17

So I have to remove the last element of a list in scheme.

For example, let\'s say I have a list (1 2 3 4). I need to return:

(1 2 3)
         


        
6条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-07 18:42

    I would do a recursive function that goes down the list and attaches the element (using cons) if the element after it is not the last, and appends nothing if it isn't.

    I haven't done scheme for years though so that's as far as I can go.

    Someone can run with how to implement it (unless it's homework then they probably shouldn't!)

提交回复
热议问题