Inserting in to a list.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bobevil13
    New Member
    • Apr 2006
    • 2

    Inserting in to a list.

    Okay, so I know that I am new to this language, but I am currently working on one problem that I have. I have been trying to write a procedure insert-at! that destructively inserts a given element into a list in a specified position. Assume that the positions are numbered from 0, and that the position specified is always 0 or positive. If the position is greater than the length of the list the procedure should return the list itself. It should work like this:
    >>> (insert-at! 'k 3 '(b c m n))
    (b c m k n)
    >>> (insert-at! 'a 0 '(b c d e))
    (a b c d e)
    >>> (insert-at! 'a 7 '(b c d e))
    (b c d e)

    That is what my text says and I cannot figure it out, can anybody give me some code for this so I can understand better?
Working...