Knowing which genes contribute to natural variation in learning and memory would help us understand how differences in these cognitive traits evolve among populations and species. We show that a natural polymorphism at the foraging (for) locus, which encodes a cGMP-dependent protein kinase (PKG), affects associative olfactory learning in Drosophila melanogaster. In an assay that tests the ability to associate an odor with mechanical shock, flies homozygous for one natural allelic variant of this gene (forR) showed better short-term but poorer long-term memory than flies homozygous for another natural allele (fors). The fors allele is characterized by reduced PKG activity. We showed that forR-like levels of both short-term learning and long-term memory can be induced in fors flies by selectively increasing the level of PKG in the mushroom bodies, which are centers of olfactory learning in the fly brain. Thus, the natural polymorphism at for may mediate an evolutionary tradeoff between short- and long-term memory. The respective strengths of learning performance of the two genotypes seem coadapted with their effects on foraging behavior: forR flies move more between food patches and so could particularly benefit from fast learning, whereas fors flies are more sedentary, which should favor good long-term memory.