?- foldl(\A^B^C^(A mod 2 =:= 1 -> C is B+A ; C=B), [1,2,3,4,5], 0, R).
you need ?-pack_install(lambda). ?-[library(lambda)]. for this to work.
--
You received this message because you are subscribed to the Google Groups "SWI-Prolog" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swi-prolog+...@googlegroups.com.
Visit this group at http://groups.google.com/group/swi-prolog.
For more options, visit https://groups.google.com/d/optout.
Cute! Maybe I should add library(lambda) to SWISH?
People, you completely confused me. What libraries should I use, they are standard or not, what libraries are better, what is right and what is wrong, what are best practices... Now I understand why many beginners are disappointing in prolog. After learning how to solve famous logical puzzles and games (that are already solved billion times), beginner needs handy tools for routine practical problems (such like fold of a list) and best practices to use it, that are really hard to find. No one want write its own decision for every usual problem. Other languages show how easy they allow to solve standard tasks and, that are most important, only right way to do it, but swi-prolog don't. Do not misunderstand me please, I talk from a beginner's position.
--
You received this message because you are subscribed to the Google Groups "SWI-Prolog" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swi-prolog+...@googlegroups.com.
--
I did not try to start an argument, just help. I am not certain what you mean by "As for swi-prolog, you can use something like this (in better case): <code snippet> for many years". The example you show here, from the SWISH notebook that Jan linked, is followed by two more examples, the second of those is not something you can easily do with Haskell anyway (as far as I know).Good luck!
I think you should consider at least two facts:
1) Prolog and logic programming in general is an utterly different paradigm if you have never seen it before, so do not be disappointed if it involves a *significant* learning curve: IME, it takes weeks to get started, months to start getting things done, and years to become proficient with it.
2) You are comparing Prolog with Haskell, but Haskell is a functional language, so you are really comparing the proverbial apples and oranges...
HTH,
Julio
Thank you. I mean, it is hard for beginner to find right functions and libraries, so he writes his own realizations. In that SWISH link the first code snippet is bad and followed by good examples. I read many materials about prolog but I never met this good example before. Probably, it because there are many implementations of prolog, and authors do not present useful functions and tricks in their papers, only common things that are in any prolog.
Take CLP(FD) constraints as a single example: It is easy for you, as a beginner, to understand constraints and use them, and you would not want to code in Prolog without them (see the DCG question for example). Yet, I assure you that people who have only slightly more experience than you will go out of their way to argue (and I am using the word loosely) against using constraints in exactly those cases you need.
?- time(phrase(as_ugly(1000000), Cs)), time(phrase(as_ugly(N), Cs)).% 5,000,001 inferences, 0.619 CPU in 0.620 seconds (100% CPU, 8077299 Lips)
% 4,000,001 inferences, 0.506 CPU in 0.507 seconds (100% CPU, 7903051 Lips)
Cs = [a, a, a, a, a, a, a, a, a|...],
N = 1000000
?- time(phrase(as(1000000), Cs)), time(phrase(as(N), Cs)).
% 168,000,000 inferences, 18.958 CPU in 18.978 seconds (100% CPU, 8861660 Lips)
% 400,278,639 inferences, 169.491 CPU in 169.671 seconds (100% CPU, 2361658 Lips)
ERROR: Out of global stack
```I believe CLP(FD) is a /huge/ innovation. I use it on a weekly if not daily basis. But as soon as I start to process larger amounts of data I find myself going back to the code and trading declarativeness for speed. Do you believe these performance issues can be resolved over time? If that could be the case then I see no further reason to not simple replace is/2 with #=/2 in all Prolog implementations everywhere.---Wouter.
Best,
On Thursday, November 19, 2015 at 8:16:10 AM UTC, Wouter Beek wrote:
Do you believe these performance issues can be resolved over time? If that could be the case then I see no further reason to not simple replace is/2 with #=/2 in all Prolog implementations everywhere.
I believe CLP(FD) is a /huge/ innovation. I use it on a weekly if not daily basis. But as soon as I start to process larger amounts of data I find myself going back to the code and trading declarativeness for speed. Do you believe these performance issues can be resolved over time? If that could be the case then I see no further reason to not simple replace is/2 with #=/2 in all Prolog implementations everywhere.
5,000,001 inferences, 0.437 CPU in 0.437 seconds (100% CPU, 11452954 Lips)
2,000,001 inferences, 0.172 CPU in 0.172 seconds (100% CPU, 11641945 Lips)On Thursday, November 19, 2015 at 4:22:45 PM UTC, Markus Triska wrote:
For now, just consider the simple principle: For integer arithmetic, (is)/2 can always be replaced by (#=)/2 with typically very acceptable overhead. That's one of the most important design goals of library(clpfd). After all, who wants to use Prolog without proper support for integers??
But you have to keep in mind that is/2 is not simply some kind of limited version of #=/2: it is rather a functional thing. IOW, declarative integer arithmetic is fine as long as the underlying notion is that of *relations*, but I would suggest it is *not* the way to go if the underlying notion rather is one of pure *functions*... No?
(Indeed performance is the *last* problem.)
On Thursday, November 19, 2015 at 7:01:35 PM UTC, Wouter Beek wrote:
But you have to keep in mind that is/2 is not simply some kind of limited version of #=/2: it is rather a functional thing. IOW, declarative integer arithmetic is fine as long as the underlying notion is that of *relations*, but I would suggest it is *not* the way to go if the underlying notion rather is one of pure *functions*... No?
I'm sorry I do not get this point. Can you expand on it or give an example? I'm not sure what a pure function is.
(Indeed performance is the *last* problem.)FMPOV that depends a lot on the use case. I want to perform non-trivial reasoning over a collection of 40 billion ground statements. That does generally not work with non-performant tools.