CLIPS load and run program from file - clips

I'm using CLIPS (http://clipsrules.sourceforge.net/) for a university project, but I cannot run program directly from files, in this case I don't want to use the prompt to insert FACTS and RULES.
right now I'm doing this.
I open CLIPS ... CLIPS> appear on prompt
Load the file (load "FILE_PATH")
All FACTS, Rules and defFacts were inserted
Type (run) to let the program run and applies rules

Place the commands you want executed in a file. For example, the contents of run.bat is the following:
(load file1.clp)
(load file2.clp)
(reset)
(run)
If you're using a command line version, you can execute the contents of the batch file using one of the following two commands:
clips -f run.bat
clips -f2 run.bat
Using the -f option will echo the commands to the command prompt. Using the -f2 option will execute the commands without echoing the commands to the command prompt.
Alternately, you can also embed CLIPS within a C program as described within the Advanced Programming Guide, http://clipsrules.sourceforge.net/OnlineDocs.html.

Related

Modify textblock by external script in vim [duplicate]

This question already has answers here:
Replace vim selection with output of shell command
(4 answers)
Closed 1 year ago.
While editing files I often encounter the following task: I have a standalone script that takes input and outputs a modified version of it (could be sort, could be a sed script, could be a more complicated python script) and I want to run it on a block of text within vim.
This answer explains how to feed a text block to an external script and I assume that one can similarly read a script's output into a file using :r. But how can I do both: feed text out of vim to an external script and its output back into vim?
You can filter a block of text in vim using the normal mode commant
!{motion}. For instance, to use the external sort tool on the text below
(ignoring the fact that vim has it's own sort for now):
b
a
d
c
use !ip (external command !, inside paragraph), which will take you to
the command line with a prepopulated command line prompt (mine looked like
:.,.+4!) where you simply type whatever external tool (e.g. :.,.+4!sort)
you want to send the text to as stdin. The resulting stout will replace the
selected lines:
a
b
c
d

Gimp batch usage on macOS doesn't read script fu file

I'm trying to make my first steps with Gimp batch processing, but I'm stuck at the very beginning. I'm getting this error:
z80crews-iMac:~ z80crew$ /Applications/GIMP-2.10.app/Contents/MacOS/gimp -i -b '(do-it "france.png" "spain.png")' -b '(gimp-quit 0)'
batch command experienced an execution error:
Error: eval: unbound variable: do-it
do-it is the name of my function to execute. This function is defined in a file that's stored in ~/.gimp-2.10/scripts.
z80crews-iMac:~ z80crew$ cat ~/.gimp-2.10/scripts/gimp-combine-images.scm
(define (do-it fname-one fname-two)
)
z80crews-iMac:~ z80crew$ /Applications/GIMP-2.10.app/Contents/MacOS/gimp -v
GNU Image Manipulation Program Version 2.10.12
Additional info: Defining do-it right on the command line works:
z80crews-iMac:~ z80crew$ /Applications/GIMP-2.10.app/Contents/MacOS/gimp -i -b '((define (do-it fname-one fname-two)) (do-it "france.bigcities.png" "france.cities.png")' -b '(gimp-quit 0)'
batch command executed successfully
Other things I tried:
I tried to pass the script as an argument to gimp.
I opened the Gimp application and stored my script fu script in the directories that are shown in Preferences > Folders > Scripts.
I'm obviously missing something easy, but I can't find out what it is.
It seems this is the way to go:
I opened the Gimp application and stored my script fu script in the directories that are shown in Preferences > Folders > Scripts.
This time I launched and closed GIMP (the application with the GUI) after having put my script in /Users/USERNAME/Application Support/GIMP/2.10/scripts. This was the first path that GIMP lists in Preferences > Folders > Scripts.

PyClips clips.BatchStar() and Clips (batch ...) do not work together

I have three files:
1.) A python filetest.py:
import clips
PATH_TO_CLP_FILE = r'd:\temp\batch_bug.clp'
clips.BatchStar(PATH_TO_CLP_FILE)
clips.PrintFacts()
2.) A file batch_bug.clp:
(assert (asdf0))
(batch "D:\\temp\\batchbug2.clp")
(assert (asdf1))
(printout t (facts))
And finally a file batchbug2.clp:
(assert (fdsa))
Running python test.py results in the following output:
f-0 (initial-fact)
f-1 (asdf0)
f-2 (asdf1)
For a total of 3 facts.
[ENVRNMNT8] Environment data not fully deallocated.
[ENVRNMNT8] MemoryAmount = 22.
[ENVRNMNT8] MemoryCalls = 1.
This is not what I expected because there is no (fdsa) fact, i.e. calling (batch "D:\\temp\\batchbug2.clp") did not work. In addition, there are the [ENVRNMNT8] messages. What is going on here?
EDIT:
I found out about the CLIPS batch*(...) command. And using this instead of the batch(...) works as expected. Why is that?
The batch command opens a file and uses its contents when requests are made for characters from standard input (the keyboard). When you're using CLIPS interactively, character requests are made from standard input by the read/evaluate/print loop (the CLIPS> command prompt) as well as any read or readline function calls in your code.
When you embed CLIPS as in done in this PyCLIPS example, there is no read/evaluate/print loop so the only requests for characters from standard input are going to come from the read and readline functions. Since this example doesn't make any character requests from standard input, the contents of the batch file is never processed.
The batch* command opens a file, directly parses its contents for commands, and then immediately executes them--No requests for characters from standard input need to be made for the commands to execute.
The batch command is useful for running test cases from the command prompt because you can simulate all keyboard input. The batch* command is useful for running command scripts when you don't have immediate access to the command prompt (either because you're embedding CLIPS or CLIPS is currently executing) or you don't want the executed commands and their return values echoed to standard output.
The ENVRNMNT8 error message occurs when CLIPS exits and it determines that all allocated memory has not been properly freed. In this case, there's a bug in the deallocation code for an unprocessed batch file that doesn't free a string containing the batch file name (for CLIPS 6.30). A fix has been checked into the CLIPS SVN repository at SourceForge.

Creating a new image with scriptfu

I'm experimenting with script-fu, trying to teach myself how to use it. I have the following basic script, which I thought would create, then display, a new image:
(define (script-fu-test)
(let*
(
(image (car (gimp-image-new 10 10 RGB)))
)
(gimp-display-new image)
(gimp-context-pop)
)
)
I'm calling the script like so:
./gimp-2.8 -i -b '(script-fu-test)'
and it's failing, like so:
batch command experienced an execution error:
Error: ( : 32662) Procedure execution of gimp-display-new failed
anyone have a hint about what i might be messing up here?
I'm running this on a Mac OS X (ie /Applications/Gimp.app/Contents/MacOS/gimp-2.8)
When I try to use a simplified version of your code, I get the following results:
$ gimp -b '(gimp-display-new (car (gimp-image-new 10 10 RGB)))'
batch command executed successfully
$ gimp -i -b '(gimp-display-new (car (gimp-image-new 10 10 RGB)))'
batch command experienced an execution error
Note that in the first case there's no -i, so the user interface is a available. In the second case, there's a -i, so there's no user interface. You can't use gimp-display-new without an interface. That you can't use gimp-display-new in no-interface mode is also mentioned in:
RE: Script can't connect to Perl Server on the gimp-perl mailing list
Make sure you start up gimp in batch mode with this line:
gimp --no-interface --batch '(extension-perl-server 1 0 0)' &
But it also means you can't do gimp-display-new, which is extremely
useful for debugging. I use interactive gimp when writing new image
generation code, and then --no-interface during production.
The "Linux LaTeX-PDF HOW-TO" by Udo Schuermann, which says:
Note, the "1" as the first argument in the commands refers to the fact that this script is to run in non-interactive mode. I've commented out the (gimp-display-new img) command; if you ran this in interactive mode it would not just prompt you for various parameters but would also produce an image window to show you the result. But we definitely do not want to bother with visible stuff and interactive operations in this project. Onwards we go:"

Stata command line arguments in batch mode

A helpful FAQ from Stata describes that arguments can be passed to do files. My do file looks like this:
* program.do : Program to fetch information from main dataset
args inname outname
save `outname', emptyok // file to hold results
insheet using `inname', comma clear names case
// a bunch of processing
save `outname', replace
According to the FAQ, this script can be run using do filename.csv result.dta. When I run this command from within Stata, everything works fine. The program is long, however, so I want to run it in batch mode. Stata has another FAQ about batch mode.
Combining the information from these webpages, I type the following at my Unix prompt:
$ nohup stata -b do program.do filename.csv result.dta &
Stata starts up, but it terminates with the following error:
. save `outname', emptyok // file to hold results
invalid file specification
r(198);
A little experimentation tells me that Stata is never receiving the two arguments when I run the program in batch mode. What is the solution to this problem? (i.e. how do you pass arguments to a do file when running it in batch mode?)
The thread below may be helpful:
http://www.stata.com/statalist/archive/2012-09/msg00609.html
In Windows, if my program Test.do is:
args a b
display "`a'"
display "`b'"
I can run it in batch mode in Windows by simply typing:
"c:\Stata13\stata.exe" /e do "c:\Scripts\Test.do" Test Script
And it will display (within Stata):
Test
Script
So I wonder whether the nohup is what's preventing your program from working.

Resources