Implemented the foreach statement. Added tests for factor and foreach. Fixed a bug in factor where the relations and tuple which were arguments to func were not stored in RefPtrs; this would cause a use-after-free for certain factor expressions.