Group Admins

  • Profile picture of Karim
  • Profile picture of Jean


Public Group active 9 hours, 59 minutes ago

User group for OpenMusic and computer-aided composition. Visit the Forum for discussions.

Function to swap elements in a list

Author 1 Subscribed Users |
David Gerard Matthews
David Gerard Matthews


I’m not sure if I’m reinventing the wheel here or not, but I could not find an easy way to simply swap two elements in a list. For example, given the list (1 2 3 4 5 6 7), I couldn’t find a simple way to swap the first and second elements to (2 1 3 4 5 6 7) without doing some unwieldy patching. So, wanting to avoid the unwieldy patching I had been doing for years, I created a little Lisp function to do it. The main concern was to have a simple solution I could use in recursive loops. I’ve attached the function here for perusal. Again, forgive me if this duplicates functionality already found elsewhere. If not, maybe someone will find it useful.



October 10, 2017 at 21:40 #24046

You must be logged in to reply to this topic.

Log in now