# How many of you realize that SWI-Prolog is an excellent, genuinely excellent language?

**URL:** <https://swi-prolog.discourse.group/t/how-many-of-you-realize-that-swi-prolog-is-an-excellent-genuinely-excellent-language/4694>\
**Category:** Nice to know\
**Created:** [November 30, 2021, 9:09pm UTC](https://swi-prolog.discourse.group/t/how-many-of-you-realize-that-swi-prolog-is-an-excellent-genuinely-excellent-language/4694 "2021-11-30T21:09:38Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![swi](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@swi](https://swi-prolog.discourse.group/u/swi)\
**Post date:** [December 2, 2021, 5:58am UTC](https://swi-prolog.discourse.group/t/how-many-of-you-realize-that-swi-prolog-is-an-excellent-genuinely-excellent-language/4694/4 "2021-12-02T05:58:44Z")

</div>

# The beauty of SWI-Prolog - hotloading code

Just along the lines of what has been posted, recently I had a long running process (hours and hours) and I needed to correct a small issue. I couldn’t stop the process. Well…SWI-Prolog came to the rescue: it is able to hot load code on the fly!

Here is a little example.

```prolog
:- use_module(library(prolog_server)).
:- prolog_server(4333,[]).

longrunning :-
    flag(counter,C,C+1),
	format('~w blippy blops so far~n',[C]),
	sleep(3),
	longrunning.

```

Run this in one terminal window:

```prolog
26 ?- longrunning.
...
232306 blippy blops so far
232307 blippy blops so far
232308 blippy blops so far
232309 blippy blops so far
232310 blippy blops so far
232311 blippy blops so far

```

Now, those numbers are getting hard to read, wouldn’t it be nice if I could just fix the output, printing easier to read numbers, **without stopping the process**?

Well, SWI-Prolog does it!  
In your favorite editor fix the format/2 statement changing this:

```prolog
	format('~w blippy blops so far~n',[C]),

```

to this:

```prolog
	format('~D blippy blops so far~n',[C]),

```

Save the file, and now we can hotload the code! In another terminal, run this:

```prolog
$ telnet localhost 4333 % yes, ssh is supported with the libssh addon
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Welcome to the SWI-Prolog server on thread client@localhost.localdomain

1 ?- make.
...

```

Now look at the output in the first terminal 😁 :

```prolog
26 ?- longrunning.
...
232306 blippy blops so far
232307 blippy blops so far
232308 blippy blops so far
232309 blippy blops so far
232310 blippy blops so far
232311 blippy blops so far
232312 blippy blops so far
232313 blippy blops so far
232,314 blippy blops so far % right here the code was hotloaded
232,315 blippy blops so far
232,316 blippy blops so far
232,317 blippy blops so far
232,318 blippy blops so far
232,319 blippy blops so far

```

I have only been able to do this with erlang in the past.  
Certainly, SWI-Prolog is a gem.

* * *

**EDIT**

By @EricGT

This reply and its replies were moved to a new topic.

> [@Hotloading code](https://swi-prolog.discourse.group/t/hotloading-code/4710):
>
> Re-posting this as a new topic in the Nice To know category, as @EricGT suggested. The beauty of SWI-Prolog - hotloading code Just along the lines of what has been posted, recently I had a long running process (hours and hours) and I needed to correct a small issue. I couldn’t stop the process. Well…SWI-Prolog came to the rescue: it is able to hot load code on the fly! Here is a little example. :- use\_module(library(prolog\_server)). :- prolog\_server(4333,[]). longrunning :- flag(counter,…

---

_[View the full topic](https://swi-prolog.discourse.group/t/how-many-of-you-realize-that-swi-prolog-is-an-excellent-genuinely-excellent-language/4694)._
