Like this:
> (my-append (list 1 2) 3)
'(1 2 3)
I know append in racket is actually to concatenate two list.
And cons just add an element to the head of a list instead of tail
Does anyone have ideas about this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In Pyton, the
append()method modifies the list in-place:Racket’s lists are immutable by default, the closest thing to an in-place
append()requires you to use mutable lists, and you have to pack the element to be appended in a list of its own:Notice that using immutable lists with the
appendprocedure will produce a new list, leaving the original list untouched – so it wouldn’t be “like Python”:In fact, Scheme’s
appendprocedure behaves just like Python’s+operation between lists:Come to think of it, Python’s
append()might have a misleading name – in most functional programming languages, the append operation is always defined between two lists, whereas in Python it’s an operation between a list and an element. Maybeadd()would have been a better name, like Java’sadd()operation of theListinterface.