Replies: 4 comments 2 replies
-
It looks like OP wanted to solve it without (explicit) recursion, so here is my attempt: :- use_module(library(lists)).
:- use_module(library(dif)).
main(R) :-
replacement([1,2,-1,4,5,-1,-1,8,9,10], [3,6,7,8,9,10], R-_).
replacement(S, P, R-X) :- foldl(repl, R, S, P, X).
repl(P, -1, [P|Ps], Ps).
repl(S, S, Ps, Ps) :- dif(S, -1). I don't get how recursion isn't declarative though and what's bad about it. At the end everything is running on a CPU which isn't declarative. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Speaking of declarativity, Prolog has declarative pointers (a.k.a. logic variables, of course)! I'm only a very naive Prolog user, but I wanted to use them here (even if in a cumbersome way); I wanted something close to a "Locally defined global identifier" (Michael Hanus) (functional) logic design pattern, I think...
|
Beta Was this translation helpful? Give feedback.
-
I opened both issues in order to run In #2708, the goal is to replace In triska/clpz#36, I want to use the directive The end goal is to be able to rewrite
And hopefully all the tools around the meta-interpreter get better in relation to goal/term expansion. |
Beta Was this translation helpful? Give feedback.
-
Dear all,
today I came across a discussion asking for:
A Prolog formulation is straight-forward:
Yielding for example:
In the course of the discussion, I noticed also that the implementation of declarative constructs is brought up. In my opinion, the current implementation of any language construct is not a sensible argument for or against the construct itself. There are constructs that cannot be implemented in Prolog at all without adequate building blocks. An example for this is the SICStus-compatible
setup_call_cleanup/3
fromlibrary(iso_ext)
. This predicate must guarantee thatSetup
is performed protected from interrupts, something that cannot be expressed in pure Prolog. Yet the construct is available, and eminently sensible and useful as a building block for even higher-level constructs such asphrase_from_file/[2,3]
inlibrary(pio)
.As another example, take
library(clpz)
: There is a lot of room for improvements in the way the library is implemented, see for example the discussions in #2708 and triska/clpz#36 for preliminary observations. Is that a sensible argument against any of the predicates the library exports? In my opinion, no. If it were, then we may as well point for example at the generated binary code of Scryer Prolog and hold it as an argument against Prolog itself. Does the unreadable binary code, or even the produced WAM code, of the Scryer Prolog compiler make any Prolog program worse in any respect? In my opinion, no, because that code does not appear in any way when using the system. In the same way, the implementation of any CLP(ℤ) construct is invisible to Prolog programs that use the library. The point of the library interface is that the implementation can be improved without further notice, and if anyone notices any kind of defect in the implementation, then I hope we can work together to improve it!Thank you and all the best,
Markus
Beta Was this translation helpful? Give feedback.
All reactions