As far as the nearby statement that maybe I didn't learn dissection correctly, that may indeed be the case, but was also my original point: perhaps the real problem is that nobody knows how to TEACH functional/logical programming right, and that's why they have not caught on in the mainstream despite being around several decades. I'd love to "get" the benefits, but it just won't click. Sometimes you have to teach programmers how to think, not just what to think.
SWI-Prolog's debugger can be invoked conditionally whenever you want from inside your running application. I've used it many times, and the code is simply:
(Condition -> gtrace ; true)
It's true that you could stick a write there, but you would have to think about what pieces of data you will need. Your mileage may vary. I've found this style a lot more useful than "traditional" debuggers where you set breakpoints beforehand and hope you hit them, as you say.> As far as the nearby statement that maybe I didn't learn dissection correctly, that may indeed be the case
The point was more specifically that you didn't learn Prolog properly (or at all) and don't realize that it forces you to dissect your code. As I said, in Prolog you cannot nest loops. You cannot nest loops. It's hard to write a big non-dissected piece of code if you cannot nest loops.
> perhaps the real problem is that nobody knows how to TEACH functional/logical programming right
I agree with regards to logic programming. We need better free tutorials. I don't particularly like the linked one, it feels like it doesn't start at a beginner's level. I would be interested if anyone who didn't know any Prolog before has managed to learn Prolog from it.
We got our introduction to it via the Tarkis' World book (90's edition).
Re: "in Prolog you cannot nest loops...It's hard to write a big non-dissected piece of code if you cannot nest loops." -- But nesting is good for modularity. It's sometimes called "step-wise refinement", which is a brilliant abstraction that is usually easy and natural to comprehend. Nesting is how we have been splitting up society since the dawn of civilization: countries, states, counties, cities, etc. (or equiv.) Similar for big militaries. (Maybe this is a meta form of Conway's law? Either way Conway was on to something.)
https://www.reddit.com/r/programming/comments/7pbkfv/great_f...
More recently, two university instructors started to use this book in courses that assume no previous knowledge about the language:
Andrej Bauer in his specialist elective course Principles of Programming Languages at the University of Ljubljana:
https://ucilnica.fri.uni-lj.si/course/view.php?id=67
Norbert Zeh in his Principles of Programming Languages lectures at Dalhousie University in Canada:
https://web.cs.dal.ca/~nzeh/Teaching/3136/index.html
Much of my current work is aimed towards making the teleteaching environment GUPU available in a free Prolog system:
https://www.complang.tuwien.ac.at/ulrich/gupu/
This will help a lot to teach Prolog to beginners in a scalable way.
On a rather personal, and maybe controversial, note: I regard the self-taught Prolog master as prevalent as for example the self-taught piano, chess or Zen master. In my experience, learning Prolog properly requires dedicated guidance, and it would be highly unusual to achieve mastery without it.
Where would you find such a master, though... If you are not studying at a university where Prolog is taught, you're pretty much out of luck, I think. (I am assuming that asking questions in newsgroups/IRC/etc is not a substitute for it.)
As in other disciplines, if you are elsewhere, you may have to move to get close to a master. This is not so unusual, is it? Vienna is a nice city for studying logic, and does attract students from all over the world!
> In my experience, learning Prolog properly requires dedicated guidance, and it would be highly unusual to achieve mastery without it.
There are two readings of this sentence. An unkind spirit might think you are saying that Prolog books cannot make you a master for some inherent reason related to Prolog, independent of any book. Whereas I would say that there is no inherent reason, it's just that currently existing Prolog books cannot make you a master because they are simply not very good. Or in other words, yes, guidance may be needed. But can it really not be guidance from a book?
In addition, for social and other reasons, you cannot write down in a book everything that advanced Prolog students should know. As a consequence, some things are better said than written, and I therefore think that a book alone is unlikely to be sufficient.
What do you mean here? My earlier comment was jokular, but you can definitely nest loops in Prolog:
...
deconstruct([L|Ls],Acc1,Bind):-
deconstruct(L,Acc1,Acc2)
,deconstruct(LS,Acc2,Bind).
...
etc. That's a nested loop, right there.Do you mean it in the sense that it's still the same predicate rather than a consecutive change of scopes?
foo_bar(Foo, Bar) :-
foo_bar_aux(Foo, Bar, 0).
foo_bar_aux(Foo, Bar, N) :-
...
Which in a language like OCaml would be hiding the loop in a recursive function defined inside the main one: let foo_bar foo =
let rec foo_bar_aux n =
...
in
foo_bar_aux 0
So yes, I think this is what you mean by being the same predicate rather than a "change of scopes".Of course there are many loop-like things that you can nest. If the arguments align just right, you can also use `maplist(maplist(maplist(baz)), ...)` instead of three auxiliary predicates, but I don't encounter many cases where this is possible or desirable.
You may want to try working with network before making this statement, when you cannot step through a function because of timeouts. Or maybe even looking at tracing debuggers, like strace, ltrace, or Erlang's gdb, which all do little more than "printing things to the console".
Logging (and logging-like tools) is a very important way of debugging services, you know.
I use logging to log problems that would happen on a user machine or server where I can't open the debugger and see it. When an error happens on a server or a customer machine and I can't use the debugger I have to guess the problematic section and put lots of logging and try to reproduce, then add more logging and so on until I find the problem.
Debugger are much better but I notice my other colleagues do not use them and prefer the console.log or similar
In my personal opinion and observation, the hierarchical step-wise refinement approach is quicker for most developers to grasp, learn, and debug. Maybe if those of us who don't see the grokkability benefits try it for 50 years, it will finally click. But you better hope to be in management by then because the programming field doesn't like "old people". I'm just the messenger.
It is like recursion, some problems can be solved nice with recursion but you do not use recursion everywhere. Also you can use a library in your favorite programming language and not use prolog, examples were presented in this thread.
My point is that a good programmer should know about the concept not to use it everywhere, I never had the chance to use prolog so far for my work.
Btw I am also past the stage where I have a favorite language and OS, every piece of software has it's issues.
Again I am just a noob, I learned Prolog and did some basic things years ago, a cool page I used to learn was this tutorial that implements a text based game , more refreshing then the tutorials with puzzles or the familiry
http://www.amzi.com/AdventureInProlog/a1start.php
The situation is maybe similar with GA(genetic algorithms) when you learn it you have some simple examples, when you want to solve a real problem things get complex fast(how to encode the problem,what fitness function should I use ...)