We address how to write programs for distributed computing systems in which the network topology can change dynamically. Examples
of such systems, which we call ensembles, include programmable sensor networks (where the network topology can change due to failures in the nodes or links) and modular
robotics systems (whose physical configuration can be rearranged under program control). We extend Meld [1], a logic programming
language that allows an ensemble to be viewed as a single computing system. In addition to proving some key properties of
the language, we have also implemented a complete compiler for Meld. It generates code for TinyOS [14] and for a Claytronics
simulator [12]. We have successfully written correct, efficient, and complex programs for ensembles containing over one million
nodes.