lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

scheme-question: restricted list inserting


From: Thomas Morley
Subject: scheme-question: restricted list inserting
Date: Sat, 16 Sep 2017 22:00:11 +0200

Hi all,

what's the best (less expensive) method to insert elements only at the
head of a list and between first and second element of said list.
But don't insert an element at list-end if the list is of length 1.

I do have:

(define (list-insert-first-and-third lst arg1 arg2)
  (if (pair? lst)
      (append
        (list arg1)
        (list (car lst))
        (if (pair? (cdr lst))
            (list arg2)
            '())
        (cdr lst))
      lst))

(display (list-insert-first-and-third '(1 2 3 4 5) "a" "b"))

--> (a 1 b 2 3 4 5)

This looks clumsy, though.

Any hint for a better code?


Thanks,
  Harm



reply via email to

[Prev in Thread] Current Thread [Next in Thread]