Functions as lists

Yesterday’s challenge from Programming Praxis challenges us to rebuild a data structure near and dear to any Lisper’s/Schemer’s/Racketer’s1/functional programmer’s heart: lists. The idea presented in their sample solution uses two element vectors, directly mimicking the general internal structure of Scheme’s lists. How about we do something a bit stranger? 😄

read more...


Swap list nodes

It’s been rather a while since I’ve worked out a Programming Praxis problem, but they posted a new one yesterday, so now seems as good a time as any. The problem is relatively simple:

Given a linked list, swap the kth node from the head of the list with the kth node from the end of the list.

Since all lists in Scheme are linked lists, that part seems easy enough. To make the problem a little more interesting however, I’m going to work it out in a purely functional manner: no mutation.

read more...