Comment by dkjaudyeqooe
Comment by dkjaudyeqooe 4 days ago
Generally speaking, the advantage of logic programming is that it's (more) declarative: you describe the problem and it derives a solution.
Comment by dkjaudyeqooe 4 days ago
Generally speaking, the advantage of logic programming is that it's (more) declarative: you describe the problem and it derives a solution.
I’d argue that is not the most ideal Prolog solution. More like it’s simply a recursive implementation of an imperative solution.
For fractals you’ll want to be able to recognize and generate the structures. It’s a great use case for Definite Clause Grammars (DCGs). A perfect example of this would be Triska’s Dragon Curve implementation. https://www.youtube.com/watch?v=DMdiPC1ZckI
Adding late to this, as I didn't get to actually look at this video yesterday.
I would still agree that you can do better than the examples I'm finding, but I am not entirely clear why/how the dragon curve is honestly any better here? The prolog, notably, does not draw the curve. Just being used to generate the sequence of characters that describes it. But... that is already trivial in normal code.
Actually drawing it will get you something like this: https://rosettacode.org/wiki/Dragon_curve#Prolog. Contrast that with the Logo version and you can see how the paradigm of the programming language can make a giant difference in how the code solution looks.
Ish? Is only really true if what you are programming can be seen as a search for the completion of a statement?
For an easy example to consider, what would the logical program look like that described any common fractal? https://rosettacode.org/wiki/Koch_curve#Prolog shows that... it is not necessarily a win for this idea.
For the general task asked in the OP here, I would hope you could find an example in rosettacode that shows prolog gets a good implementation. Unfortunately, I get the impression some folks prefer code golf for these more so than they do "makes the problem obvious."