Method: Cons#append

Defined in:
lib/cons.rb

#append(list, *rest) ⇒ Object

The append method returns a new list that is the concatenation of the copies. lists are left unchanged; the list structure of each of lists except the last is copied. The last argument is not copied; it becomes the cdr of the final dotted pair of the concatenation of the preceding lists, or is returned directly if there are no preceding non-empty lists.

Cf. <clhs.lisp.se/Body/f_append.htm>



288
289
290
291
292
293
294
295
296
297
298
299
300
301
# File 'lib/cons.rb', line 288

def append list, *rest
  result = self.copy_tree
  if rest.empty? or rest.nil?
    if list.kind_of? Cons
      result.the_last.cdr = list.copy_tree
    else # list is not a list
      result.the_last.cdr = list
    end
    return result
  else
    result.the_last.cdr = list.copy_tree
    return result.append *rest
  end
end