1/* BEGIN LICENSE BLOCK 2 * Version: CMPL 1.1 3 * 4 * The contents of this file are subject to the Cisco-style Mozilla Public 5 * License Version 1.1 (the "License"); you may not use this file except 6 * in compliance with the License. You may obtain a copy of the License 7 * at www.eclipse-clp.org/license. 8 * 9 * Software distributed under the License is distributed on an "AS IS" 10 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 11 * the License for the specific language governing rights and limitations 12 * under the License. 13 * 14 * The Original Code is The ECLiPSe Constraint Logic Programming System. 15 * The Initial Developer of the Original Code is Cisco Systems, Inc. 16 * Portions created by the Initial Developer are 17 * Copyright (C) 1997-2006 Cisco Systems, Inc. All Rights Reserved. 18 * 19 * Contributor(s): 20 * 21 * END LICENSE BLOCK */ 22 23/* 24 * ECLiPSe LIBRARY MODULE 25 * 26 * $Id: eg_cc_yield.cc,v 1.3 2012/02/25 13:47:56 jschimpf Exp $ 27 * 28 * 29 * IDENTIFICATION: cc_yield.c 30 * 31 * AUTHOR: Joachim Schimpf 32 * AUTHOR: Stefano Novello 33 * 34 * CONTENTS: name/arity 35 * 36 * DESCRIPTION: 37 * Example of minimal main using external embed interface. 38 */ 39 40#include "eclipseclass.h" 41#include <iostream> 42 43 44int 45main(int argc,char ** argv) 46{ 47 ec_init(); 48 EC_ref X_or_Cut; 49 int res; 50 long x; 51 52 post_goal("between(1,99,1,X), writeln(X),\ 53 (X>5 -> \ 54 yield(X, Cont), \ 55 ( Cont == stop -> exit_block(abort) ; true )\ 56 ; \ 57 true \ 58 )"); 59 res = EC_resume(X_or_Cut); 60 61 for (;;) 62 { 63 switch (res) 64 { 65 case EC_succeed: 66 std::cout << "succeeded\n"; 67 post_goal("fail"); 68 res = EC_resume(X_or_Cut); 69 continue; 70 71 case EC_fail: 72 std::cout << "failed\n"; 73 break; 74 75 case EC_throw: 76 std::cout << "aborted\n"; 77 post_goal("writeln(new_goal_after_abort)"); 78 res = EC_resume(X_or_Cut); 79 continue; 80 81 case EC_yield: 82 std::cout << "yielded\n"; 83 if (EC_succeed == EC_word(X_or_Cut).is_long(&x) && x>6) 84 res = EC_resume(EC_atom("stop"), X_or_Cut); 85 else 86 res = EC_resume(EC_atom("cont"), X_or_Cut); 87 continue; 88 89 default: 90 std::cout << "bad return code: " << res << "\n"; 91 break; 92 } 93 break; 94 } 95 96 ec_cleanup(); 97 exit(0); 98} 99 100