Cover image for The Programming Language That Changed My Life!

The Programming Language That Changed My Life!

lukegarrigan profile image Luke Garrigan Updated on ・4 min read

tl;dr Prolog gave me a whole new perspective. Let me know programming languages that altered how you attack a problem!


Introduction to the language

I was in my second year of University studying Computer Science. I'd caught wind that the programming language for the Artificial Intelligence module wasn't a language we'd covered so far in the degree. I was excited, I thought I'd already gotten a decent grip on C, C++, Python, and Java so I was ready for anything. 😬

"Your first assignment will be to create an AI using Prolog".
What the fu*k is a Prolog were my precise thoughts. I thought I was pretty clued up on all the programming languages out there. Why are we learning a programming language I've never even heard of?

I went home, did some googling to try to find out what this Prolog thing was.
"Prolog is a logic programming language associated with artificial intelligence and computational linguistics". Right, AI, that's probably why we're learning it, or is it because the language was made in Marseille, France, and my Lecturer is French? 🤣

The following week we had our first introduction to the language, I quickly realised that no matter how well I knew C, C++, Python or Java it was not going to help me in understanding Prolog. It took me no time at all to grow hatred towards the language. It just doesn't. make. sense.

I went through countless tutorials, tried tonnes of example problems, took apart people's solutions to problems line by line, it just wasn't going in. I would take apart some code and trick myself into thinking I understood how it worked but when it actually came to coding in Prolog myself, my brain stopped.


I'd had enough of struggling with Prolog. After I'd exhausted all possible avenues on the internet to learn it I'd decided to actually listen to my Lecturer and get the recommended book.

Ivan Bratko book

Prolog Programming For Artificial Intelligence - Ivan Bratko. This book changed everything. I pretty much devoured the book in a day. I was hooked, the book had me wanting more. I went back to the coding problems I'd struggled on just a day before and could think of 20 different ways to solve it, I began to LOVE the language. In class, I went from the student who condemned everything about the qwerky language to Prologs biggest advocate.

What is Prolog?

Prolog is a logic programming language. You define relations which are known as Facts and Rules. You then query your knowledge base and it returns the output based on those facts and rules. Solutions are typically written by recursion, the program calls itself until some objective has been satisfied, which is often referred to as the base case or final state. Backtracking is another important feature of the language: when a subgoal is not satisfied prolog backtracks meaning it traces its steps backwards to the previous goal and tries to satisfy it.

What's so special about Prolog?

Prolog is one of those very rare languages where I'd say that a non-programmer would likely have as good as or if not better experience understanding it than a programmer. See us developers are so accustomed to imperative programming, telling the compiler what we want to happen, step by step. When we're forced to think declaratively (Writing code that describes what we want, our desired result but not necessarily how to get it) it hits our brains for six, well, mine at least.

Prolog gave me a whole new way of looking at a problem, it made me ask different questions. Rather than asking what is the next step, I think of the desired state and the processes involved to get to that state.

If you have a programming problem and you were tasked to solve it in 3 different languages be it Java, C#, C++. It is very likely that you would solve the problem pretty much exactly the same in each, taking the same steps to manipulate the input to get the desired output. Yes, I get you'd probably use different constructs of each language but likely the general approach would be the same. However, if you learn Prolog you can ask yourself "How would I solve this in Prolog". And although attempting to map your Prolog solution to that of an imperative solution might not necessarily be the best approach, it opens avenues for alternate possibilities and expands conceivable results.


This blog was really supposed to be a #discuss as I am mainly interested in hearing how learning new languages altered how you think about solving a problem. I know that learning Functional programming languages has profound impacts on some peoples outlook so I'd love to hear from you!

Follow me on twitter if you don't want to miss out on absolutely brilliant programming insight: 🤣 @luke_garrigan

Thank you, if you like my rambling check out my personal blogging site at https://codeheir.com/

Posted on by:

lukegarrigan profile

Luke Garrigan


English lad currently a C#/Java/VueJs/JavaScript developer. Extra dribbling can be found at https://www.codeheir.com Portfolio found at https://lukegarrigan.com


markdown guide

Awesome post, I had contact with Prolog at my Computer Science course, I struggled a lot with it. Maybe it's time to go back to it with this book that you recommend to give it another try.

For me every programming language that I experienced changed my life in some aspect.

  • C made me care a lot to resource management.
  • Assembly to understand even more how things work barebone. And also to be graceful for the existence of compilers and interpreters 😄
  • Java to understand the classic design patterns
  • Python to discover my passion for coding, the community, open-source, and to make me express myself with code better.
  • JavaScript and TypeScript helped me so much to understand events and how async work
  • Shell was the gateway to server task automation
  • Now elm developing my passion for functional programming

Each language exposed me to different ways of seeing things ☺


Very agree with you. Learnt foxpro and visual foxpro to understand more on data processing.

Learnt BASIC to know about structured thinking and modularity.

I don't have much time to study more. Now i want to learn python.

I glad i read this post on prolog, it challenged my mind and i appreciate this comment, it gives me insight on how the other programming languages bring impacts to you, at least for python. 😁🙏


Great spirit we should always try to learn something new from a programming language.


Completely agree. It seems me and you have had very similar learning paths!


Moreover, there's a language with syntax similar to Prolog, so learning Prolog might make it easier for you to learn the other one, too. Its name is Erlang and it's still used in production in many businesses.

fac(0)            -> 1;
fac(N) when N > 0 -> N * fac(N - 1).

Erlang (and OTP!) is nice indeed.

But the paradigm is different than Prolog's: in functional programming languages, you'll end up with a function you can call.

In Prolog - a declarative language - you'll end up with a bunch of predicates that can be solved. A system of (logical) equations that you can generate solutions for.


For anyone interested in knowing the business case for Erlang, WhatsApp uses it extensively. Might make a good case study!


It also powers newer versions of Chef Server.

Well as per this tweet Erlang powers more than 90% of Internet, once its in Cisco routers ;)

And now you have also Elixir, that runs on the same virtual machine, the BEAM.

Elixir is very cool, if I only had more time I'd be digging into it more!

Elixir is very cool, if I only had more time I'd be digging into it more!

I am playing now with it, and I am loving Live View :)

It seems that you work in embed systems, so you must already know the Nerves Project?

I have indeed! While I do have a few Raspberry Pis, I would like to see if I can get it running on some other boards...NXP makes some ARM Cortex A7 microcontrollers that should have enough memory to run this, and the Nvidia Jetson is another candidate. It will be quite an adventure porting it to a new platform, but I will definitely learn a lot!

Did not know about live view, very cool! I haven't played around with the web framework at all, but it looks really cool.

NXP makes some ARM Cortex A7 microcontrollers that should have enough memory to run this

In the words of Joe Armstrong, anything have enough memory to run Erlang/Elixir/Nerves, and this his because Erlang was made 30 years ago, and on that time computer where not having the processing power of this cheap boards.

I need to start playing with this boards to, must be a lot of fun ;)

Did not know about live view, very cool! I haven't played around with the web framework at all, but it looks really cool.

It's a big thing to replace Single Page Apps in a lot of use cases.


ooh lovely, sounds like a weekend challenge!


There's also Elixir which another language that runs on the Erlang VM, a bit similar to Prolog. But, If you wanna learn Erlang checkout out this book: learnyousomeerlang.com/content

Elixirs syntax is little nicer than Erlangs. Both of these are interoperable, they work on the same virtual machine called BEAM. And what they excel - are concurrency and resilience. They (elixir and erlang) are awesome candidates for languages to learn in the age of microservices.
One of the bigger recognizable companies that use Elixir is Discord. And Ericsson uses Erlang, but they are not as sexy ;)

Discord guys have a blog on Medium and it's pretty interesting.

Clarifications here though I'm a noob at Elixir. Elixir extends Erlang because you can invoke Erlang functions. Erlang was developed by Ericsson and is used for running the cellphone towers insuring uptime which also I think makes it great for microservices.


Honestly, I crap on Javascript a lot (sorry!), but it was the first language that gave me the freedom to explore and the autonomy to have fun with software... and it’s that freedom and fun that has kept me invested as a developer all those years!!! 🥰😍


Haha love this, we all crap on Javascript but we all seem to use it 😂 and secretly love it really!


I had the privilege of being taught prolog by prof. Bratko. He had a knack for explaining problems so that everyone understood them, no matter the diffuculty.


Oh wow that’s amazing! I envy you, his book completely saved me. What a guy.


Lisps. All of them. Scheme changed how I write JavaScript (and any language with functions), Common Lisp changed the way I think about programming - literally. I see more languages that read themselves instead of machines that do stuff. It was weird. It still is.


This is why I can't keep my eye off projects like Nim and Julia. They somehow managed to ALGOLize lisp-style metaprogramming.


Yes, these two are doing it right, and is a very unfortunate myth that you need S-expressions in order to do an AST-level metaprogramming comfortably.

I even demonstrated it with a C syntax, just for giggles: github.com/combinatorylogic/clike

Feel free to browse that project and everything else there, pretty much all the stuff I'm working on is related to static metaprogramming one way or another. Also, take a look at the generated docs and a small tutorial


Lisp! Emacs!

I still am totally surprised when I explain "but you can totally rewrite the editor while it's running" and most Software Engineers just blink at you as if you said "THE MOON IS MADE OF COWS" or something similarly weird and non-sensical.


Python tuples and sets made immutability and typescript enums make a lot more sense to me.

Good post! It's good for experienced coders to remember what it's like to be totally lost when learning. We take a lot for granted working in similar languages so often


Very interesting post. When I started my classss for computer sciences back in 1988, for few weeks I wasn't even comfortable touching the computer. Eventually the same field changed my life and I was considered a very good developer. Then came the change of era from procedural languages to OOP with GUI based interfaces to write software in VB, I lost it there and could not handle OOP concepts with such a programming interface. Anyway, ky career never required me to ever worry about writing code anymore. But I guess once a programmer always a programmer. I developed that itch lately for writing software and I realized I am way behind and all of this is completely new to me. Lately I have started reading again and took Python as first one to get myself comfortable. Reason was that while it has OOP concepts, it also has a procedural language style. Not sure if all this would bring some change in my life or not (_)


Thank you for your comment. I have had the same thought about moving from a programming job into a management role, I think I'd really miss coding!


At the age of about 50 where I have seen great success in my career working in senior management roles for fortune 100 companies, I still feel that I took up management roles very early in life.


I "learned" Prolog in school. We were about it for about half a year in our CS course. And I was fascinated with the language and I did not have the same issues as you had, but that may be, because I was not yet firmly into imperative programming.

On the other hand, after some more years, when I was firmly in the grasp of IP and I was learning C# 4.0, it was lambdas and Linq2SQL, that were very hard on my brain.

Now I really like them and when I was dabbling a bit into F#, my first thought was just "Oh ... everything is a lambda here".


My first and foremost language was Ruby. Probably if not Ruby I wouldn't even bother learning programming but I was so captivated and inspired by Ruby code, its elegance and expressiveness coupled with interesting "everything is an object" model that I stick to it. Then I discovered Rails, web development and things got rolled further!


Followed. And now you got me wanting to take a closer look at Prolog.

Edit: I enjoy Python programming. I don't have anything insightful to say right off the bat, except that Python, at least to me, more closely mirrors human logical control-flow (my introduction to programming was COBOL, then I really cut my teeth on C#).


Thank you, do it! I can't recommend it enough.


I had to study Prolog for my Expert systems class and once I got my head around it, pretty much the way you described, I loved it and ended up using it for my MSc project. An NLP system to learn Spanish that corrected grammar, it was super fun. I keep thinking about trying something else with it.


That project sounds awesome! Every now and then I go to ic.unicamp.br/~meidanis/courses/mc... to get back up to speed with Prolog as I love the language so much 😃


The best thing about learning a radically different language is going back to the language you "have to" use (job or other constraints) and finding that you can translate what you've learned into the old syntax.

For me, this was writing Python "as if" it were a functional language—becoming very aware of mutable state and limiting it, making better use of list comprehensions, and reasoning about types even though the language doesn't enforce types.

Languages open us up to new ideas, but once we have them, we can take them back to the mainstream. I don't know if that's possible with something as different as Prolog, but I'd like to see it!


The best thing about learning a radically different language is going back to the language you "have to" use (job or other constraints) and finding that you can translate what you've learned into the old syntax.

YES, couldn't have put this any better.


Its worth noting that Prolog and SQL actually have a LOT in common. Both are declarative languages structured around tables of fact tuples and relationships between them. And then you give it a specification and it returns a set of tuples that match the specification. Prolog of course does a whole lot more (and it perhaps does it an injustice to make the comparison), but if you really boil down to it, the two are very similar. It'd be nice if makers of new databases had another look at prolog. If you wanna go 'past' SQL, maybe Prolog is in fact the future!


I studied Prolog in 2003 in the university course Declarative programming. Before that I didn’t even hear about this kind of different programming paradigm. I had good experiences with Java, C and C++.
The professors and PhD students who led the course of Declarative programming wrote a quite detailed book about the language and how the Prolog interpreters work. But I struggled with it a lot in the first weeks. We had small homeworks and a final closing homework - we needed to solve a quite complicated puzzle with Prolog. Those were challenging. But in the end it completely changed the way I was thinking about solving problems with programming.
There was another language taught during the course of Declarative programming: SML (Standard Meta Language). It’s a functional programming language.


Second that. The only language that had an even more substantial effect on my approach to problem solving is a limited Prolog subset, Datalog.


I learned prolog at university, final assignment was a game which was quite fun. But I didn't use it after that. I also had the luck that I didn't do a lot of programming yet at the time, so it wasn't so hard to learn.


So my theory, in your case is correct 😄 that the less you know of imperative programming the easier you'll pick it up!


BASIC defined my future life, Python brought me back to the path and currently with C# I'm having feeling that only now I'm starting to understand some elementary things :D I would say learning every new language change a little how you think about solving problems.


There's loads of cool Prolog code out there:

At LPA, we augmented Prolog with Flex which provides frame-based reasoning and forward-chaining production rules

Nowadays, we see a lot of projects which combine Prolog and Python - seems a good combination


Thanks for taking me back to 1984, Luke. My final year project at university was a bridge (the card game) playing system in prolog. It took a while to set up the basics of dealing the cards and playing a card but after that I spent the rest of the year adding and tweak the "rules" to make better decisions. Such fun. I'm a python nut these day and should really look at ways of integrating prolog into the decision making sections of my systems. Can you recommend the best way to integrate prolog into python?


I'm glad it made you reminisce a little, and that project sounds like a lot of fun!
I have very little experience writing python in recent years so I couldn't recommend of any ways to integrate prolog into python without some googling.


I felt exactly like you when I first met Prolog. It was in a AI class and in the beginning I was shocked with that new way of coding. When I finally understood that coding in a declararative language is like describe how we think and take conclusions, a new world of possibilities have opened to me. As my professor always said, Prolog is like an automated theorem prover, so working with processes which require deduction and inference becomes much more effective and simple.
Currently I am working with a framework/interpreter for a Prolog-like language (AgentSpeak), it's called Jason and it is designed for Multi-agent systems.


Ah, this really took me back. CS 2003.
Prolog and logic languages in general are so different than anything you've ever experienced. Prolog was the one we focused on as an example of a logic language in language / compiler design. It's great! It'll challenge the way you think of writing code.


One of those eye-widening languages was Elm for me. Definitely check it out!


Oh really, I've been wanting to put some more time into functional languages for a while now. Maybe I'll jump into Elm!


I highly recommend that you go for it ;-)


my "change my life" language is Lisp. similarly, as a uni frosh in EE, i was learning Fortran. hanging out in one of the computer labs, a grad student suggested i look at the language. Lisp was the language that made me fall in love with programming. 2 years later i had switched to CS. 40-some languages later, Lisp is still a fave


Prolog was interesting but I always had difficulty seeing it as something that could solve everyday problems. Haskell melted my brain a bit, all the things I thought I knew about functional programming were secretly just whispers in the dark.


Prolog can help a lot with solving everyday problems. Just keep in mind that you can embed Prolog into pretty much any language (with a different degree of clumsiness, of course). See Clojure core.logic or MiniKanren for multiple Scheme implementations for example.

A standalone Prolog is a weird beast with few real world applications. An embedded Prolog is a power tool applicable everywhere.

For example, I often use elements of Prolog to implement code analysis passes and optimisations in compilers, and this way it's often an order of magnitude shorter than any ad hoc solution. I use Prolog to encode decision making systems and to explain their decisions (or generate a code from them). I use Prolog with a CLP(FD) to do all sorts of constraint solving problems, from making time tables to scheduling multi-cycle operations in a high level hardware synthesis.

Once you start thinking in Prolog, all problems start to look like nails suitable for this hammer.


Great post. I haven't taken a shot at prolog, but your talk above reminds me of how I felt when working in OpenGL (GLSL) 15 or so years ago for general purpose GPU programming. The frustrating part is that it wasn't your normal programming, everything was executed in parallel, and a lot of creativity was involved in getting your expected result. The exciting part was that I got to use all of the linear algebra, calc & physics to apply to my actual programming.... I can't say that for my day job in javascript world


Funny it's an old programming language I had to learn at engineering school, frankly I had preferred pure math; Now I don't hate prolog and happy you just need to add "AI" to anything and it becomes sexy again ;)

What really hooked me was when I also learned Grafcet diagram method which - contrary to UML being only a language - helps implement complex real time automation with state machines and it is agnostic from any programming languages though you can implement it with any programming languages including assembly language and PLC.

Maybe I'll try to implement with Prolog since I'm working on crafting a grafcet UI Kit at grafcet.online


britannica.com/technology/LISP-com... -

I was a Computer Science student from 1975-1979. At that time, Lisp was the only programming language that had any remote concepts that led to useful artificial intelligence development. If you read up on Lisp, you'll see that it was intended to be a list processing language, and it certainly had an influence in the development of software artificial intelligence.

Other than an academic introduction to it long ago, I've had relatively few practical excursions into AI, and I'm now retired, so I read and observe mostly to understand how technologies are likely to impact my every day life.


Modula-2 for me in the 1970s.
I loved the separation of Definition & Implementation modules. Being forced to think through and define the Definition modules before coding the Implementation modules provided a both a rigorousness, portability and collaboration I'm not sure you even see in today's languages!

I could publish my Definition modules and others could use them without caring how I implemented them.

Later I could change the coding of the Implementation modules and as long as the Definition module didn't change collaborators were never affected.

Great language


Try out picat-lang.org/. It's a Prolog style language with built in solvers


I have been learning programming languages my entire professional life and have made a couple of half-hearted attempts to learn Prolog in the past. On the encouragement of your article, I have started the Prolog stream at exercism.io


You can use RETE rule engines which are better than Prolog at handling hundreds of rules.
You get out of that imperative trap and you delegate control to the rule compiler to decide
the rule evaluation order.

The runtime takes care of executing your rules until the output stops changing.

I wrote a couple of apps using this and it's a very good approch when you know that your system
will have to adapt to future changes. Rules are independent and it's easier to add/remove individual
decoupled rules than reworking a 💩 pile of code all intertwined.


Nice #discuss :)

My thought changing experiences were with:

  • declarative languages: first SQL, then more recently DSLs for DevOps tooling - check out Azure RM, AWS cloudformation or Terraform.
  • parallel processing: VHDL & Verilog for hardware, Occam & Modula-2 in software - my first experience of native parallel processing support and learning all about synchronisation and shared storage.

Firth I'm real thankful for what you've written here, it's real nice to see that someone really likes it as me, but sometime I took myself wondering if there is someone who professionally use it or not. This kind of questions came to me because when I'm searching for something, all appears to be too old and no one using it, but at the same time I've seen thing that really made me joyful like this page jiprolog.com/ this guy is doing big stuff here, but do you know some modern applications using prolog? or someone who really use it? thank you!!!


Well I never looked into Prolog, but I came to know it existed when I felt in Love with Elixir, and when I went to discover more about the Elixir background I learned that its built on top of the battle tested Erlang, that by its turn have its first compiler coded in Prolog.

If you want to take a look to a new database, that have the server code 99% in Prolog, just see TerminusDB Server in Github.

Now I am curious about your Prolog book ;)


Great job at introducing the idea behind prolog. It would help me now to explore the language.