It’s exam time

I haven’t been blogging for a while as it’s exam period. It’s also been busy busy at 24seven. The new product which name you will never guess right.

Today’s paper is on programming, it’s (so-call) advanced concepts. Honestly the whole course’s been a mess but never mind that. I did 3 questions on Java, 2 question on SML and 1 question on Prolog. The Java questions are quite easy. Most of what I studied came out. I planned to do 3 questions out of the 5 Java questions and it went well.

What caught me in a surprise is Prolog which is quite hard, especially the last question which was basically some professor wanting to read some opinion. If I were a computing journalist, I probably choose that question.

SML isn’t that hard. What I studied came out, what I didn’t study I chose not to do. And I quickly went home and I try to see if the average function I wrote work in SML. And it did:

[code lang=”ocaml”]fun average x =
fun sum [] = 0.0
| sum (h::t) = h + sum t;
fun count [] = 0.0
| count (h::t) = 1.0 + count t;
sum x / count x

I wrote this function very neatly on the paper. I never had so much sense of achievement writing an SML function.

An alternate way of writing would be probably:

[code lang=”ocaml”]fun average x = foldl op+ 0.0 x / real (length x);[/code]

You gotta love foldl sometimes.

Tomorrow’s paper is database. I probably won’t do too well for that. Lots of memorizing to do and my memory’s failing me.

Finished my Prolog assignment

I finally handed in my prolog assignment. I don’t think I do a good job but at least the document itself looks good. I can’t stress how important presentations are for assignments. I very much doubt the markers actually look at your code and see if it’s working or now. In fact I can imagine markers just giving an A for an assignment that looks right. It’s all about presentation sometimes.

Gone is yestermonth’s assignment, four more to go.

Any Prolog experts around?

I need to create a Prolog crossword puzzle for a school assignment. I don’t want a Prolog solution, I have a couple but I couldn’t understand what it means so it’s kinda pointless for me. Does anyone have any tips to completing this task? Perhaps which in built predicate I should be looking out for or something? I am using SWI-Prolog 5.6.64 for this assignment.


[Note that all comment will not be shown here. Sorry about that. I’ll reply directly to your email address.]

Prolog calls me a creep

Creep is someone unpleasantly strange or eccentric and Prolog is calling me that.

Prolog calling me a creep
Prolog calling me a creep

[code lang=”bash”]41 ?- q5([1, 2], 1, A).
ERROR: is/2: Arguments are not sufficiently instantiated
^ Exception: (8) 1 is _G372-1 ? No previous search
^ Exception: (8) 1 is _G372-1 ? No previous search
^ Exception: (8) 1 is _G372-1 ? Unknown option (h for help)
^ Exception: (8) 1 is _G372-1 ? Unknown option (h for help)
^ Exception: (8) 1 is _G372-1 ? creep[/code]

What is this “creep” business? In SWI Prolog, the implementation of Prolog which this dictionary uses for the syntax of its examples, when you press return at the end of a line of tracing, Prolog prints “creep” on the same line, and then prints the next line of trace output on the next line. Pressing return again produces “creep” again and another line of tracing, and so on. (Source)

Introduction to Prolog

Prolog is a logic programming language. It is a general purpose language often associated with artificial intelligence and computational linguistics. It has a purely logical subset, called “pure Prolog”, as well as a number of extralogical features.

Having its roots in formal logic, and unlike many other programming languages, Prolog is declarative: The program logic is expressed in terms of relations, and execution is triggered by running queries over these relations. Relations and queries are constructed using Prolog’s single data type, the term. Relations are defined by clauses. Given a query, the Prolog engine attempts to find a resolution refutation of the negated query. If the negated query can be refuted, i.e., an instantiation for all free variables is found that makes the union of clauses and the singleton set consisting of the negated query false, it follows that the original query, with the found instantiation applied, is a logical consequence of the program. This makes Prolog (and other logic programming languages) particularly useful for database, symbolic mathematics, and language parsing applications. Because Prolog allows impure predicates, checking the truth value of certain special predicates may have some deliberate side effect, such as printing a value to the screen. This permits the programmer to use some amount of conventional imperative programming when the logical paradigm is inconvenient. (Everything above is from Wikipedia)

Jud and Mike, get into character as they play the inventors of the programming language known as “Prolog”, in the “Introduction to Prolog”

Intoruction to Prolog *updated

I don’t know why someone would do this. But I was looking for some prolog videos and found this.