An electrically-programmable diffraction grating. The programmable grating includes a substrate having a plurality of electrodes formed thereon and a moveable grating element above each of the electrodes. The grating elements are electrostatically programmable to form a diffraction grating for diffracting an incident beam of light as it is reflected from the upper surfaces of the grating elements. The programmable diffraction grating, formed by a micromachining process, has applications for optical information processing (e.g. optical correlators and computers), for multiplexing and demultiplexing a plurality of light beams of different wavelengths (e.g. for optical fiber communications), and for forming spectrometers (e.g. correlation and scanning spectrometers).