4 ms·
You can’t mention logic programming without talking about the one most folks have interacted with: make. Facts are files and rules are rules. Make will explor
by jnwatson 6y ago
You can’t mention logic programming without talking about the one most folks have interacted with: make.
Facts are files and rules are rules. Make will explore deep chains of rules to find a path to building the targets.
I once (ab)used make so that the mere inclusion of a non-existent header would autogenerate it from a series of different templates combining human-readable structures, marshaling it into binary, then converting it into something a C compiler can read. Importantly, the process was recursive, as the source for a template might have to go through transformation itself.
The key is I never taught make about the whole process. Each individual step in the process is a rule that transforms from one file extension to another. Make automatically searches for a path through the rules, even 9 or 10 deep.
- 1996 6y agoI think the term you're looking for is constraint propagation. That's a nice programming paradigm, unfortunately a bit obscure now.
- philzook 6y agoTwo fun blogs posts in this vein https://bentnib.org/posts/2015-04-17-propositions-as-filenames-essence-of-make.html https://bentnib.org/posts/2015-04-17-propositions-as-filenam... http://conal.net/blog/posts/the-c-language-is-purely-functional http://conal.net/blog/posts/the-c-language-is-purely-functio...
- vram22 6y agoThe classic Kernighan and Pike book, The Unix Programming Environment[1], has a good example of advanced make usage (cascading / recursive makes, multiple (and implied) rules, sources and targets, etc.), along the lines of your example, in the chapter at the end of the book on hoc[2], the higher order calculator. They build multiple, incrementally more powerful versions of hoc in that chapter, as a case study to tie together many key topics in the book. [1] https://en.m.wikipedia.org/wiki/The_Unix_Programming_Environment https://en.m.wikipedia.org/wiki/The_Unix_Programming_Environ... [2] https://en.m.wikipedia.org/wiki/Hoc_(programming_language) https://en.m.wikipedia.org/wiki/Hoc_(programming_language)
- ww520 6y agoMake uses dependency graph to track the make rules. Topological Sort can turn however deep dependent rule network into a simple linear ordered list of steps to perform. The matching files are then fed through this list one step at a time and run the matching rules against the files. Repeat the process for newly generated files.
- dls2016 6y agoI skimmed at first and thought the author was going to talk about the implementation of dependency resolution in apt-get.
- saagarjha 6y agoRelated: make obviously makes a big dependency graph to keep track of this stuff. Is there a good way to make it show this? How do you debug these kinds of constructions?
- OakNinja 6y agoBased on my experience of creating MakeMe (https://GitHub.com/OakNinja/MakeMeFish https://GitHub.com/OakNinja/MakeMeFish) I would say the only way of creating that graph would be to write a make clone with this feature. While make is an awesome tool, it really lacks good insights.
- fanf2 6y agoBSD make has lots of debugging options, so you can ask it to print the dependency graph amongst other things https://www.freebsd.org/cgi/man.cgi?query=make https://www.freebsd.org/cgi/man.cgi?query=make If you use GNU make, check out remake http://bashdb.sourceforge.net/remake/ http://bashdb.sourceforge.net/remake/ which is GNU make patched with debugging support
- joe_the_user 6y agoI never thought about make as a logic program. But considering this seems to explain a lot. Like SQL, make is an integral part of the programming world ... that most people want as little as possible to do with and which some people violently hate and a few people enjoy playing with. And I think this shows language that just tell the computer "what you want" and not how to get that something tend to not scale with the length of the command or the amount of data processed. SQL was originally created to be something like a human-friendly, natural language interface, if you can believe it. And it's sort of friendly if you only use one or two command-words but after that it gets extremely frustrating. So the connection is interesting.