How to change prompt_alternatives_on flag in prolog from .plrc? - prolog

I can change prompt_alternatives_on flag in the REPL.
But how do I change this flag in .plrc?
Then I get
permission to modify static_procedure `set_prolog_flag/2'
Goal: To not get the "More?" text for all the answers all the time. By changing the flag.

Put :- (a colon and a hypen) in front of the line to execute it when the file is loaded.
:- set_prolog_flag(key, value).
This is true of any line of code in any source file that you want to have evaluated when the file is loaded instead of considered a new fact or rule (which causes the error because it attempts to redefine set_prolog_flag/2).

Related

What's "auto" value in "AC_ARG_ENABLE"?

I've been checking whether which files of some open source components are used during compile.
But, I don't know well about autotools, autoconf, etc.. so, I want to know the "auto" value means in AC_ARG_ENABLE(). Here is an example.
AC_ARG_ENABLE(launchd, AS_HELP_STRING(--description--),enable_launchd=$enableval,enable_launchd=auto)
If "--enable-launchd" option is given, run the command "enable_launchd=$enableval", right??
But if not, run the command "enable_lauchd=auto".
What is a value of the "auto"?
If "--enable-launchd" option is given, run the command
"enable_launchd=$enableval", right??
Right.
But if not, run the command
"enable_lauchd=auto".
Yes.
What is a value of the "auto"?
"auto" has no significance in that command other than as itself. It is the value assigned to variable enable_launchd.
You may well find that configure.ac later checks for that value and performs additional processing if it is seen, or you might find that it just emits it as-is into an external file.

syntax error: expression expected

I'm going through a learn Prolog tutorial. I pulled a single line from the example:
happy(yolanda).
and put it into an XGP file. When I compile it I get:
syntax error: expression expected
This same line works ok when I load it into swipl so I guess there's some difference there.
How can I run happy(yolanda) and get a Yes that she is happy in XGP?
I think there was a bad character that showed up when I copy-pasted the code from the website into the .pl file. I deleted all the whitespace and the file started to compile.
  happy(yolanda).
Once the file is saved then in the Evaluate Query box you can run happy(yolanda). and it will say 'Success' just as #lurker said.

What does this Windows bat command mean?

I read the following command from the batch file to run Maven on Windows mvn.bat:
if not "_%M2_HOME:~-1%"=="_\" goto checkMBat
And
if "%#eval[2+2]" == "4" goto 4NTArgs
What does this batch script mean?
ADD 1
As I tried, it seems _%M2_HOME:~-1% returns the _ plus the last 1 letter of the environment variable "_%M2_HOME%. But what's the name of this syntax?
%VAR:~-1% gets the last character in the envvar. The first snippet verifies that the envvar M2_HOME doesn't end with \. Note: Maven's docs say,
Note: For Maven 2.0.9, also be sure that the M2_HOME doesn't have a '\' as last character.
This might be related. They probably want to prepend M2_HOME to subdir names and always include a dirsep. The variable substitution in "_%...%" is unaffected by the initial underscore. Experessing it that way just ensures that the underscore is at the beginning of the output. I can't say for certain, but it may have been expressed that way to avoid a backslashed quote, e.g. "\".
The second is not any CMD/batch that I'm familiar with. The comment (assuming this comes from mvn.bat) says "4NT shell", which I take to mean that this batch file could be run in the Take Command Console which probably has extensions to MS CMD features. For example, %#eval[...] probably does numeric evaluation in 4NT. This would effectively be a check to see if the script were running in a 4NT shell.
The first one takes the last character of %M2_HOME%, adds an underscore to the front, and checks to see if the resulting string is _\ - in short, it checks that the last character of %M2_HOME% is a backslash by using substrings.
The second one is how you determine if 4NT is installed on your computer; if it is, there will be a variable function called #eval.
I found the explanation to "_%M2_HOME:~-1%" below link. It's a variable substring operation.
http://ss64.com/nt/syntax-substring.html

Stata delimit in command line

I am working on a .do file created by someone else. This person used a semicolon delimiter in the entire file. I am trying to go through this file and see what is going on. I like to do this by selecting a portion of the code and hitting the "Execute Selection (do)" button. However, the delimiter seems to be messing up this. Are there any workarounds for me?
Suppose your do-file looks like this:
#delimit ;
set obs
10 ;
gen x = _n ;
gen y = x^2 ;
gen z = x
^3;
Anytime you highlight a selection and press "Execute selection (do)", Stata creates a temporary, self-contained do-file, with default delimit at cr and runs that:
"When a do-file begins execution, the delimiter is automatically set to
carriage return, even if it was called from another do-file that set the
delimiter to semicolon."
It does not sequentially run those commands from the console. Therefore, if you select the first 2 commands in the do-file above, the temporary do-file includes a call to #delimit whereas if you selected the last 2 commands, the temporary do-file would not have this call and would throw a syntax error for two line commands.
One solution could be to copy-paste selections to a fresh do-file that just had the #delimit command at the beginning, and then run that.
You could also write a script to rid your do-file of semicolons. If a line does not end in a semicolon, then append the next line to the end of the current line, and check this line again. Depending on how complex the syntax is in your do-file, this would be more or less difficult.
Another option is comment out the lines you have already ran by enclosing them with /* */ and to use exit; where you want to stop. You do have to be a little careful with local macros.

Using Shell to Check Whether a File Exists, and only if it does, Execute a Set of Commands

I have a few lines of code in Stata. I'd like the lines to be executed only if the .txt file to which the lines refer exist a priori. I am wondering whether there is a shell command that I can use for this that I can embed in an if statement.
For example might something like the following exist and be possible:
insheet using "file.txt" if ('file.txt')
My intent is to say insheet the file file.txt only if it exists. My concern is that the program would otherwise stop, fail, die, or whatever you call it due to a syntax error if I have that insheet statement but the file does not exist.
Immediate answer is No. There is nothing like that syntax for several reasons.
The if qualifier tests whether some condition is true separately for each observation and whether a file exists is not an appropriate condition for testing observation by observation.
The quite different if command tests once and once only whether something is true and might seem more appropriate. In practice it is not used for this purpose, but to learn more, see help ifcmd.
Stata has no special syntax based on paired identical single quotes ' '.
However, Stata provides a separate construct here
confirm file file.txt
In practice that is going to stop a do-file or program whenever the file does not exist and the file does not exist. A general scheme to catch the error is something like
capture confirm file file.txt
if _rc == 0 insheet using file.txt
else {
<code if the file does not exist>
}
capture is to be thought of as eating the return code from the confirm command. In general the return code _rc from any command is 0 if the command was valid and executed and some non-zero value otherwise. Sometimes one tests for a specific non-zero code. Experiment shows that file not found is return code 601. The main reason for looking up error codes (in [P] error) is to deliver official-looking error messages, but in practice knowing the zero/non-zero rule is the main detail under this heading.
The example here uses == to test for equality.
Note that insheet using file.txt is not strictly a syntax error if the file does not exist. As far as Stata's language is concerned, that is legal syntax. However, that is a fine distinction: it is an error in every ordinary sense.
(LATER) It would be possible to short-circuit the entire process
capture insheet using file.txt
if _rc != 0 {
<code if the file does not exist>
}
as in this case the non-existence of the file is the presumed explanation for any failure of the insheet command. If, however, the insheet call were more complicated, with a varlist and/or options, then failure of the command could arise for other reasons. So in general separating out a check for the existence of the file seems a better strategy.
The confirm command has what you're looking for.
capture confirm file "file.txt"
if !_rc { # if the file exists, confirm will return error code 0
insheet using "file.txt"
}
Alternatively, you could put a capture before the insheet command, which will catch the syntax error. Check the [P] manual for more on capture and confirm.

Resources