2007-12-11 22:36:40 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								USING:  help.syntax  help.markup  kernel  prettyprint  sequences 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								quotations math ;
 
							 
						 
					
						
							
								
									
										
										
										
											2007-09-20 18:09:08 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								IN:  combinators.lib 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								HELP:  generate 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-11 22:36:40 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ $values { "generator"  quotation } { "predicate"  quotation } { "obj"  object  } }
							 
						 
					
						
							
								
									
										
										
										
											2007-09-20 18:09:08 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								{ $description "Loop until the generator quotation generates an object that satisfies predicate quotation."  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ $unchecked-example
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    "! Generate a random 20-bit prime number congruent to 3 (mod 4)" 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-11 20:51:58 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    "USING: combinators.lib math math.miller-rabin prettyprint ;" 
							 
						 
					
						
							
								
									
										
										
										
											2007-09-20 18:09:08 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								    "[ 20 random-prime ] [ 4 mod 3 = ] generate ." 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    "526367" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								HELP:  ndip 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-11 22:36:40 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ $values { "quot"  quotation } { "n"  number  } }
							 
						 
					
						
							
								
									
										
										
										
											2007-09-20 18:09:08 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								{ $description "A generalisation of "  { $link dip  } " that can work "  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"for any stack depth. The quotation will be called with a stack that " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"has 'n' items removed first. The 'n' items are then put back on the " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"stack. The quotation can consume and produce any number of items." 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ $examples
							 
						 
					
						
							
								
									
										
										
										
											2008-03-11 20:51:58 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  { $example "USING: combinators.lib kernel prettyprint ;"  "1 2 [ dup ] 1 ndip .s"  "1\n1\n2"  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  { $example "USING: combinators.lib kernel prettyprint ;"  "1 2 3 [ drop ] 2 ndip .s"  "2\n3"  }
							 
						 
					
						
							
								
									
										
										
										
											2007-09-20 18:09:08 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ $see-also dip  dipd } ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								HELP:  nslip 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-11 22:36:40 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ $values { "n"  number  } }
							 
						 
					
						
							
								
									
										
										
										
											2007-09-20 18:09:08 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								{ $description "A generalisation of "  { $link slip } " that can work "  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"for any stack depth. The first "  { $snippet "n"  } " items after the quotation will be " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"removed from the stack, the quotation called, and the items restored." 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ $examples
							 
						 
					
						
							
								
									
										
										
										
											2008-03-11 20:51:58 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  { $example "USING: combinators.lib prettyprint ;"  "[ 99 ] 1 2 3 4 5 5 nslip .s"  "99\n1\n2\n3\n4\n5"  }
							 
						 
					
						
							
								
									
										
										
										
											2007-09-20 18:09:08 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ $see-also slip nkeep } ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								HELP:  nkeep 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-11 22:36:40 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ $values { "quot"  quotation } { "n"  number  } }
							 
						 
					
						
							
								
									
										
										
										
											2007-09-20 18:09:08 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								{ $description "A generalisation of "  { $link keep  } " that can work "  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"for any stack depth. The first "  { $snippet "n"  } " items after the quotation will be " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"saved, the quotation called, and the items restored." 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ $examples
							 
						 
					
						
							
								
									
										
										
										
											2008-03-11 20:51:58 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  { $example "USING: combinators.lib kernel prettyprint ;"  "1 2 3 4 5 [ drop drop drop drop drop 99 ] 5 nkeep .s"  "99\n1\n2\n3\n4\n5"  }
							 
						 
					
						
							
								
									
										
										
										
											2007-09-20 18:09:08 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ $see-also keep  nslip } ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								HELP:  && 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-11 22:36:40 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ $values { "quots"  "a sequence of quotations with stack effect "  { $snippet "( ... -- ... ? )"  } } { "?"  "a boolean"  } }
							 
						 
					
						
							
								
									
										
										
										
											2007-09-20 18:09:08 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								{ $description "Calls each quotation in turn; outputs "  { $link f  } " if one of the quotations output "  { $link f  } ", otherwise outputs "  { $link t  } ". As soon as a quotation outputs "  { $link f  } ", evaluation stops and subsequent quotations are not called."  } ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								HELP:  || 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-11 22:36:40 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ $values { "quots"  "a sequence of quotations with stack effect "  { $snippet "( ... -- ... ? )"  } } { "?"  "a boolean"  } }
							 
						 
					
						
							
								
									
										
										
										
											2007-09-20 18:09:08 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								{ $description "Calls each quotation in turn; outputs "  { $link t  } " if one of the quotations output "  { $link t  } ", otherwise outputs "  { $link f  } ". As soon as a quotation outputs "  { $link t  } ", evaluation stops and subsequent quotations are not called."  } ;