Hi Giuseppe, Giuseppe Di Guglielmo wrote: > Dear all, > I attached a small test. In the code, I'm trying to retrieve the result for > the submitted constraint. Why does the 'ec_queue_read' function not collect > any data from the standard output (or error)? > ... > #include "eclipseclass.h" > > #include <iostream> > using namespace std; > > main() > { > char buf[1024]; > int n; > > ec_set_option_int(EC_OPTION_IO, MEMORY_IO); > ec_init(); > > ec_post_string("compile(clp_utils)"); > > ec_post_string("integer_t(U, -128, 127), (U #= 11), search_int_func( U > )"); > I am not sure if I understood you correctly -- are you expecting ec_queue_read in your following code to return the results from the goals you have just posted? Your previous message about `permanent variables' suggest you think ec_resume() is the same as executing a query at the toplevel in an interactive ECLiPSe -- this is not correct. They are different: 1. The ECLiPSe toplevel prints the bindings to any variables in the query; no such printing is done when you execute posted goals during ec_resume(). You need to explicitly write any outputs in the goals that are executed. Since your second posted goal does not do any outputs, there is nothing for ec_queue_read() to read. 2. Interactive ECLiPSe backtrack to the toplevel after executing each query at the toplevel. No automatic backtracking is done when you return from ec_resume() (unless the posted goal(s) failed). If the posted goals succeeded, any further posted goals will be executed at the next ec_resume without the backtracking of the However, the parsing of the goals (when you post the goals as string) is done independently at each ec_resume(), so you cannot link the variables from the posted goals to each other. A more general comment about what you are doing: it is probably not a good idea to try to post goals as strings and read the outputs back as strings, unless your posted goals and outputs are simple. This is particularly the case with posting multiple goals and multiple ec_resume(). There are several reason for this: a) It is easy to make errors in your post goals, e.g. in the syntax, because of various differences, such as the need for quoting. It is particularly easy to make errors if you are constructing the goals in your program. There is no easy way to debug such errors. For example, did you really intend to post the goal write(Hello) (which writes a variable with the name Hello) rather than write("Hello") (write the string Hello) in: ec_post_string("write(Hello)"); The goal also happens to write Hello to the output because ECLiPSe writes the source name of the variable when it is not instantiated. To post write("Hello"), you will need to correctly quote the inner quotation marks. This is one reason why you should keep the goal simple, or you should use exdr format, as Andrea and Joachim have suggested. b) You cannot link the variables in different posted goals to each other if you are post the goals as strings (or exdr format). You can link the variables if you use the lower level representation of ECLiPSe terms(EC_refs etc.), but it is tedious (and thus easy to get wrong) to build complex goals. You may want to look at the FAQ `How do I create and pass constraints to ECLiPSe from an external language?' at http://eclipse-clp.wiki.sourceforge.net/FAQ for more disccusion on this issue. Cheers. Kish > ec_resume(); > > while( (n = ec_queue_read(1, buf, 1024)) > 0 ) // DOES NOT WORK! > { > buf[n] = 0; > cout << "eclipse: " << buf << "\n"; > } > > #if 0 > n = ec_queue_read(2, buf, 1024); > buf[n] = 0; > cout << "eclipse error returned: " << buf << ".\n"; > #endif > > ec_cleanup(); > exit(0); > } > --- > > Giuseppe > > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------------ > Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA > -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise > -Strategies to boost innovation and cut costs with open source participation > -Receive a $600 discount off the registration fee with the source code: SFAD > http://p.sf.net/sfu/XcvMzF8H > > > ------------------------------------------------------------------------ > > _______________________________________________ > ECLiPSe-CLP-Users mailing list > ECLiPSe-CLP-Users_at_lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/eclipse-clp-users -- This e-mail may contain confidential and privileged material for the sole use of the intended recipient. Any review, use, distribution or disclosure by others is strictly prohibited. If you are not the intended recipient (or authorized to receive for the recipient), please contact the sender by reply e-mail and delete all copies of this message. Cisco Systems Limited (Company Number: 02558939), is registered in England and Wales with its registered office at 1 Callaghan Square, Cardiff, South Glamorgan CF10 5BT.Received on Sat Feb 14 2009 - 22:57:38 CET
This archive was generated by hypermail 2.2.0 : Thu Feb 02 2012 - 02:31:58 CET