The "problem" I am facing is that if I use the SWI-Prolog module system, defining modules and using them in other modules, if an imported module changes SWI-Prolog does not take it in consideration when loading the importing module. For example:
% file topmod.pl
:- module(topmod, [thetop/0]).
:- use_module(bottommod).
thetop :-
thebottom(S),
format('This is the top~nAnd this is ~w~n', [S]).
% file bottommod.pl
:- module(bottommod, [thebottom/1]).
thebottom('the bottom').
If I now load them:
?- [thetop].
% bottommod compiled into bottommod 0.00 sec, 2 clauses
% topmod compiled into topmod 0.00 sec, 6 clauses
true.
?- thetop.
This is the top
And this is the bottom
true.
If I now change the file:
% file bottommod.pl changes
- thebottom('the bottom').
+ thebottom('the foobar').
?- [thetop].
% topmod compiled into topmod 0.00 sec, 1 clauses
true.
?- thetop.
This is the top
And this is the bottom
true.
?- module(bottommod).
true.
?- listing.
thebottom('the bottom').
true.
How should I force Prolog to consult all the imported modules and the modules they import, short of using consult?
You can use SWI-Prolog make/0 predicate to reload all modified source files since last loaded.
Related
#!/usr/bin/dyalog -script
⍝ /usr/bin/dyalog is a symlink to /opt/mdyalog/18.0/64/unicode/mapl
factors←{⎕ML ⎕IO←1 ⋄ ⍵{ ⍵,(⍺÷×/⍵)~1}∊⍵{(0=(⍵*⍳⌊⍵⍟⍺)|⍺)/⍵}¨⍬{nxt←⊃⍵ ⋄ msk←0≠nxt|⍵ ⋄ ∧/1↓msk:⍺,⍵ ⋄ (⍺,nxt)∇ msk/⍵}⍵{ (0=⍵|⍺)/⍵}2,(1+2×⍳⌊0.5×⍵*÷2),⍵}
factors 20
Copied from https://dfns.dyalog.com/c_factors.htm
It works exactly as the example apart from the fact I am not able to to type it as separate lines and have to resort to ⋄'s
Using the example it instead results in
./.local/src/sandbox/apl/Main.apl
SYNTAX ERROR
factors←{⎕ML ⎕IO←1 ⍝ Prime factors of ⍵.
Another issue is using ] commands like ]display or ]box on
Using them always results in
./.local/src/sandbox/apl/Main.apl
VALUE ERROR: Undefined name: ⎕SE.UCMD
Try* adding setting DYALOG_LINEEDITOR_MODE to 1:
#!/usr/bin/dyalog -script DYALOG_LINEEDITOR_MODE=1
When running in script mode, SALT, and therefore user commands, are not initialised automatically. As per APLcart, you can enable both with:
(⎕NS⍬).(_←enableSALT⊣⎕CY'salt')
However, under program control, you're usually better off using proper functions than user commands. You can copy in the display and disp functions (which take an array and produce character matrices equivalent to what you'd see from ]display and ]box on) with:
'display' 'disp'⎕CY'dfns'
* Both -script and DYALOG_LINEEDITOR_MODE are experimental in version 18.0, while 18.2 (scheduled for release in March 2022) has dedicated #! script support.
I am using yosys to synthesize using the synth_ice40 command which calls ABC as well. In my Verilog code, I have used (* keep *) wire wire_1; Yosys does not optimize this but when it comes to ABC, it removes these unused wires. Is there anything equivalent to (* keep *) which could be used in Verilog which ABC does not optimize and remove the certain wires?
Any help would be appreciated.
Thanks,
Log:
`.44.2. Continuing TECHMAP pass.
No more expansions possible.
Removed 0 unused cells and 3 unused wires.
2.45. Executing OPT_LUT pass (optimize LUTs).
Discovering LUTs.
Number of LUTs: 1
2-LUT 1
Eliminating LUTs.
Number of LUTs: 1
2-LUT 1
Combining LUTs.
Number of LUTs: 1
2-LUT 1
Eliminated 0 LUTs.
Combined 0 LUTs.
<suppressed ~2 debug messages>
2.46. Executing TECHMAP pass (map to technology primitives).
2.46.1. Executing Verilog-2005 frontend: /usr/local/bin/../share/yosys/ice40/cells_map.v
Parsing Verilog input from /usr/local/bin/../share/yosys/ice40/cells_map.v' to AST representation. Generating RTLIL representation for module $lut'.
Successfully finished Verilog frontend.
2.46.2. Continuing TECHMAP pass.
Using template $paramod$lut\WIDTH=2\LUT=4'1000 for cells of type $lut.
No more expansions possible.
<suppressed ~14 debug messages>
Removed 0 unused cells and 2 unused wires.`
The problem
My code includes a module called Tests which defines the following:
broken :: SetRBT Int
broken = insertRBT 1 $ emptySetRBT (<)
I can evaluate broken in the REPL:
All> broken
RedBlackTree.RedBlackTree (_impl#==#Prelude.Eq#Prelude.Int) (_impl#==#Prelude.Eq#Prelude.Int) (_def#<#Prelude.Ord (_inst#Prelude.Ord#Prelude.Int)) (RedBlackTree.Tree RedBlackTree.Black 1 RedBlackTree.Empty RedBlackTree.Empty)
All>
I cannot, however, evaluate the RHS of broken's definition:
All> insertRBT 1 $ emptySetRBT (<)
PAKCS_Main_Exp.curry, line 3.18: Error:
Undefined type RedBlackTree.RedBlackTree
ERROR occurred during parsing!
All>
Or so I believed, until I tried attaching a type signature:
All> insertRBT 1 $ emptySetRBT (<) :: SetRBT Int
RedBlackTree.RedBlackTree (_impl#==#Prelude.Eq#Prelude.Int) (_impl#==#Prelude.Eq#Prelude.Int) (_def#<#Prelude.Ord (_inst#Prelude.Ord#Prelude.Int)) (RedBlackTree.Tree RedBlackTree.Black 1 RedBlackTree.Empty RedBlackTree.Empty)
All>
I'm fine with having to attach type signatures when needed, or more generally, to do whatever the error messages suggest I should do. But how would I know to interpret the above error message as meaning "you've got to attach a type signature"? More generally, what does that type error even mean, given that (see below) RedBlackTree is loaded?
What I am loading
Each time I start PAKCS I run :l All. That loads a module which reads, in relevant part,
module All ( module M
) where
import FiniteMap as M
import SetRBT as M
import RedBlackTree as M
import Tests as M
That idiom lets me load all the things that I need (there are others) without producing a long prompt.
If I run :modules it looks like RedBlackTree should be defined:
All> :modules
Currently loaded modules:
All (loaded from ./.curry/pakcs/All.pl)
Prelude (loaded from /home/jeff/logic/curry/install/pakcs-2.0.2/lib/.curry/pakcs/Prelude.pl)
FiniteMap (loaded from /home/jeff/logic/curry/install/pakcs-2.0.2/lib/.curry/pakcs/FiniteMap.pl)
SetRBT (loaded from /home/jeff/logic/curry/install/pakcs-2.0.2/lib/.curry/pakcs/SetRBT.pl)
RedBlackTree (loaded from /home/jeff/logic/curry/install/pakcs-2.0.2/lib/.curry/pakcs/RedBlackTree.pl)
Tests (loaded from ./.curry/pakcs/Tests.pl)
All>
You must tell the interpreter to add referenced modules.
All> :add RedBlackTree SetRBT
... some messages ...
All SetRBT RedBlackTree> insertRBT 1 $ emptySetRBT (<)
and it will work.
I would like to write a module that exports a predicate where the user should be able to access a predicate p/1 as a prefix operator. I have defined the following module:
:- module(lala, [p/1]).
:- op(500, fy, [p]).
p(comment).
p(ca).
p(va).
and load it now via:
?- use_module(lala).
true.
Unfortunately, a query fails:
?- p X.
ERROR: Syntax error: Operator expected
ERROR: p
ERROR: ** here **
ERROR: X .
After setting the operator precedence properly, everything works:
?- op(500, fy, [p]).
true.
?- p X.
X = comment ;
X = ca ;
X = va.
I used SWI Prolog for my output but the same problem occurs in YAP as well (GNU Prolog does not support modules). Is there a way the user does not need to set the precedence themselves?
You can export the operator with the module/2 directive.
For example:
:- module(lala, [p/1,
op(500, fy, p)]).
Since the operator is then also available in the module, you can write for example:
p comment.
p ça.
p va.
where p is used as a prefix operator.
I'm doing some optimization using a model whose number of constraints and variables exceeds the cap for the student version of, say, AMPL, so I've found a webpage [http://www.neos-server.org/neos/solvers/milp:Gurobi/AMPL.html] which can solve my type of model.
I've found however that when using a solver where you can provide a commandfile (which I assume is the same as a .run file) the documentation of NEOS server tells that you should see the documentation of the input file. I'm using AMPL input which according to [http://www.neos-guide.org/content/FAQ#ampl_variables] should be able to print the decision variables using a command file with the appearance:
solve;
display _varname, _var;
The problem is that NEOS claim that you cannot add the:
data datafile;
model modelfile;
commands into the .run file, resulting in that the compiler cannot find the variables.
Does anyone know of a way to work around this?
Thanks in advance!
EDIT: If anyone else has this problem (which I believe many people have based on my Internet search). Try to remove any eventual reset; command from the .run file!
You don't need to specify model or data commands in the script file submitted to NEOS. It loads the model and data files automatically, solves the problem, and then executes the script (command file) you provide. For example submitting diet1.mod model diet1.dat data and this trivial command file
display _varname, _var;
produces the output which includes
: _varname _var :=
1 "Buy['Quarter Pounder w/ Cheese']" 0
2 "Buy['McLean Deluxe w/ Cheese']" 0
3 "Buy['Big Mac']" 0
4 "Buy['Filet-O-Fish']" 0
5 "Buy['McGrilled Chicken']" 0
6 "Buy['Fries, small']" 0
7 "Buy['Sausage McMuffin']" 0
8 "Buy['1% Lowfat Milk']" 0
9 "Buy['Orange Juice']" 0
;
As you can see this is the output from the display command.