lisp - What Racket function can I use to insert a value into an arbitrary position within a list? -
i know trivial implement, want racket live it's "batteries included" promise. looking function works this:
> (define (between lst item spot) (append (take lst spot) (cons item (drop lst spot)))) > (between '(1 3) 2 1) '(1 2 3)
does racket include such builtin?
here implementation based on stephen chang's comment (i swapped argument order little , renamed function too):
(define (insert-at lst pos x) (define-values (before after) (split-at lst pos)) (append before (cons x after)))
Comments
Post a Comment