I want the code to: use the predicate load_files/2 with a string stream. To make a stream from a string, I used open_string/2. When compiling the code of the string, I used the option [stream(Stream)] but I don’t understand what the first argument “Files” is for. As the document said, I just put an arbitrary atom as Files.
But what I’m getting is: I got an error message " Syntax error: Unbalanced operator".
I will not try to answer your question directly because I don’t use load_files/2 in the manner you note to have enough confidence an answer would be correct, however
sometimes seeing actual examples helps.
The first example is the one closest to the code you noted in your question; not saying this is what you seek but a working example of how the predicates you noted work together.
The code that implements the stream option
Note: Many of the snippets above are zoomed in to show the use of the load_files/2 predicate. To truly understand what is happening in the code click on the link to see the file and then look at the predicate(s) that make use of the noted code.
I got the source of the error. As you said, it is not a problem about “Files” but the string streamed. In the dynamic code generation, it met an exceptional state and did not generate a code correctly. So the string of the code was syntactically wrong.
Good Note that generating program text and compiling this is typically not the best solution. Typically there are more efficient ways to get the right stuff into Prolog that is not sensitive to syntax issues and therefore not sensitive to injection attacks. It all depends what you are trying to do though …
Thank you for your explanation. I tried to construct terms but variables become different and I couldn’t find the best way to unifying different variables. Also in my case, I don’t need to worry about injection attacks because this code generation is used in computation. My project is making a new solver for constrained dynamic programming problems. Currently, using string is an easy way to deal with variables. I am not sure it is computationally efficient, though.