Software Engineering discussion

9 views

Comments Showing 1-5 of 5 (5 new)    post a comment »
dateUp arrow    newest »

message 1: by [deleted user] (new)

Installation on my Mac: Not easy. Do this:

brew edit gnu-prolog

Make it look like this:

require 'formula'

class GnuProlog < Formula
url 'http://www.gprolog.org/gprolog-1.4.0....'
md5 'cc944e5637a04a9184c8aa46c947fd16'

skip_clean :all

def install
ENV.j1 # make won't run in parallel

Dir.chdir 'src' do
system "./configure", "--prefix=#{prefix}"
system "make"
system "make install-strip"
end
end
end

Then do this:

brew install gnu-prolog

----------

A definite blast from the past! In the mid 80s, Borland released Turbo Prolog, for something like $99, which was a bargin at the time. I was one of the many programmers who bought it, and then tried to figure out how to program in it. It was a definite paradigm shifter. The only other language I knew at the time that was conceptually even close to it was LISP. I learned a little (about up to this book's Day 3), and then never could think of an application for it, and I never when back to it.

I don't think I ever got to unification back then, and I am glad I learned it from this book. Overall, I think that Prolog is a terrible language to try and learn and program in. Debugging seems almost impossible from the poor error messages. I keep wanting to program in it as if it were a functional language, but functions don't return results via a return parameter, but through the call parameters, and this is a very awkward thing for me.

This is a language worth struggling with for conceptual reasons, but it is aimed at niche applications.

The Day 1 and 3 exercises were straightforward, as well as all the Day 2 exercises except for the sort. I spent a lot of time on it, mainly deciding on the best algorithm for this paradigm. I ended up with an insertion sort, but it took me a long time to get it working. The Day 3 sudoku exercise was basically just an extension of the book example, but I got really weird results until I filled in a little more of the puzzle. Ig anyone knows how to read the first output (it seems it is trying to tell me about alternate solutions), let me know!

sudoku([_, 6, _, 1, _, 4, _, 5, _,
_, _, 8, 3, _, 5, 6, _, _,
2, _, _, _, _, _, _, _, 1,
8, _, _, 4, _, 7, _, _, 6,
_, _, 6, _, _, _, 3, _, _,
7, _, _, 9, _, 1, _, _, 4,
5, _, _, _, _, _, _, _, 2,
_, _, 7, 2, _, 6, 9, _, _,
_, 4, _, 5, _, 8, _, 7, _],
Solution).

// strange output with the above puzzle
[_#3(3:9),6,_#39(3:9),1,_#75(2:7..8),4,_#111(2:7..8),5,_#147(7..9)]
[_#169(1:4:9),_#191(1:7:9),8,3,_#241(2:7),5,6,_#291(2:4:9),_#313(7:9)]
[2,_#349(3:5:7),_#371(3..5),6,_#415(7..8),9,_#459(4:7..8),_#481(3..4:8),1]
[8,_#531(1..2:5:9),_#553(1:5:9),4,3,7,_#625(2:5),_#647(1..2:9),6]
[_#683(1:4:9),_#705(1:9),6,8,5,2,3,_#821(1:9),_#843(7:9)]
[7,_#879(2..3:5),_#901(3:5),9,6,1,_#973(2:5:8),_#995(2:8),4]
[5,_#1045(1:8..9),_#1067(1:9),7,_#1111(1:4),3,_#1155(4:8),_#1177(4:6:8),2]
[_#1213(1:3),_#1235(1:3:8),7,2,_#1285(1:4),6,9,_#1335(4:8),_#1357(5:8)]
[6,4,2,5,9,8,1,7,3]

// after I filled in a few more values
[9,6,3,1,7,4,2,5,8]
[1,7,8,3,2,5,6,4,9]
[2,5,4,6,8,9,7,3,1]
[8,2,1,4,3,7,5,9,6]
[4,9,6,8,5,2,3,1,7]
[7,3,5,9,6,1,8,2,4]
[5,8,9,7,1,3,4,6,2]
[3,1,7,2,4,6,9,8,5]
[6,4,2,5,9,8,1,7,3]


message 2: by Erik (new)

Erik | 165 comments I liked reading this. Declarative languages are something I don't work with often (other than SQL or Google). This was a really well done chapter.

The limitations make me afraid of trying big problems that might blow up the stack, take an undetermined long time, or just be potentially buggy.


message 3: by Aleksander (new)

Aleksander Shtuk | 84 comments After reading first few sections of this chapter, first thing that came to my mind was Einstein's Problem.
(http://www.davar.net/MATH/PROBLEMS/EI...) . Same kind of setup: few facts, few rules, and the goal is to figure out how facts work together according to the rules.

Most challenging problem for me was Day 2, Problem 2 – finding smallest member of the list. Looking back, I think, my problem was a misunderstanding how rules and sub-rules are setup. Sorting came to me a lot faster – find smallest number in a list using rules from Problem 2, print that number, remove it from the list, then repeat with remaining list until it becomes empty.

Instead of doing problems for Day 3, that involved modifying Sudoku program already provided in chapter, I decided to work on a problem that I created for myself. Now I want to finish Day 3 problem and see if I get results similar to Brad's results or different.

I like Prolog – it's very different from languages I've been using so far. I can think of many problems such a declarative language would be perfect for. Though I'm wondering about its efficiency in terms of processing time for problems with large datasets with many facts and rules. According to the book Prolog was used for airline scheduling application, and I know that those are very resource consuming.


message 4: by [deleted user] (new)

I had not heard of Einstein's Problem before... interesting, and a perfect problem for Prolog. Here is another link about it http://en.wikipedia.org/wiki/Zebra_Pu... .


message 5: by Aleksander (new)

Aleksander Shtuk | 84 comments I think this is the one (Zebra Puzzle) that I did in my Discrete Mathematics course!


back to top