"logtalk_load" to reload files with changes

Help requests on developing Logtalk applications

Moderator: Paulo Moura

Post Reply
shengcer
Posts: 21
Joined: Wed Aug 14, 2013 7:54 pm

"logtalk_load" to reload files with changes

Post by shengcer » Thu Aug 15, 2013 2:18 am

Here is like what I have

%% this is file foo.lgt
:- object(foo) .
%% some predicates/facts
:- end_object .

%% this is file bar.lgt
:- object(bar) .
%% some predicates/facts
:- end_object .

%% this is file load.lgt
:- initialization(logtalk_load(['foo', 'bar'])) .

Let's say I have loaded load.lgt with
?- logtalk_load('load') .

I have made some changes to both load.lgt and foo.lgt, if I run
?- logtalk_load('load')
again, then both foo.lgt and load.lgt will be reloaded. However if only foo.lgt has some changes made, running logtalk_load('load.lgt') will not trigger any reload. Is there a way to reload a modified file which is loaded through a "loader".

I am using logtalk3, so reload flag is not an option.

Paulo Moura
Logtalk developer
Posts: 475
Joined: Sat May 05, 2007 8:35 am
Location: Portugal
Contact:

Re: "logtalk_load" to reload files with changes

Post by Paulo Moura » Thu Aug 15, 2013 9:51 am

Assuming that you're using Logtalk 3.00.0 Alpha 21 or later, simply use the logtalk_make/0 built-in predicate for reloading source files modified since the last time they are loaded:

Code: Select all

| ?- logtalk_make.
There is also a short alias for this predicate, {}/0, so you can also type:

Code: Select all

| ?- {}.
Your loader file is not the one being changed, so Logtalk knows that's up-to-date. Not sure what would be the best solution here as loader files are just normal source files that happen to load other files. One option would be to reintroduce something like the old "reload" flag to mark files that should always be reload. On POSIX systems, typing:

Code: Select all

$ touch loader.lgt
would also work but it cumbersome.
Paulo Moura
Logtalk developer

shengcer
Posts: 21
Joined: Wed Aug 14, 2013 7:54 pm

Re: "logtalk_load" to reload files with changes

Post by shengcer » Thu Aug 15, 2013 1:22 pm

This is what I figured too, which is indeed awkward :-(

Code: Select all

:- initialization((
  shell('touch load.lgt'),
  logtalk_load('load')
)) .
Curious of why logtalk 3 got rid of reload flag...?
Paulo Moura wrote:Assuming that you're using Logtalk 3.00.0 Alpha 21 or later, simply use the logtalk_make/0 built-in predicate for reloading source files modified since the last time they are loaded:

Code: Select all

| ?- logtalk_make.
There is also a short alias for this predicate, {}/0, so you can also type:

Code: Select all

| ?- {}.
Your loader file is not the one being changed, so Logtalk knows that's up-to-date. Not sure what would be the best solution here as loader files are just normal source files that happen to load other files. One option would be to reintroduce something like the old "reload" flag to mark files that should always be reload. On POSIX systems, typing:

Code: Select all

$ touch loader.lgt
would also work but it cumbersome.

Paulo Moura
Logtalk developer
Posts: 475
Joined: Sat May 05, 2007 8:35 am
Location: Portugal
Contact:

Re: "logtalk_load" to reload files with changes

Post by Paulo Moura » Thu Aug 15, 2013 5:09 pm

Note that if you're using SWI-Prolog as the back-end compiler for Logtalk, you can also simply type "make" to reload both modified Logtalk and Prolog source files.
Paulo Moura
Logtalk developer

shengcer
Posts: 21
Joined: Wed Aug 14, 2013 7:54 pm

Re: "logtalk_load" to reload files with changes

Post by shengcer » Thu Aug 15, 2013 6:34 pm

I am kinda reluctant to use make/0, this along with listing/0 sometimes would cause jvm crash through jpl...
Paulo Moura wrote:Note that if you're using SWI-Prolog as the back-end compiler for Logtalk, you can also simply type "make" to reload both modified Logtalk and Prolog source files.

Paulo Moura
Logtalk developer
Posts: 475
Joined: Sat May 05, 2007 8:35 am
Location: Portugal
Contact:

Re: "logtalk_load" to reload files with changes

Post by Paulo Moura » Thu Aug 15, 2013 7:17 pm

shengcer wrote:I am kinda reluctant to use make/0, this along with listing/0 sometimes would cause jvm crash through jpl...
Paulo Moura wrote:Note that if you're using SWI-Prolog as the back-end compiler for Logtalk, you can also simply type "make" to reload both modified Logtalk and Prolog source files.
I'm only suggesting SWI-Prolog make/0 or Logtalk logtalk_make/0 during development, when editing your source files. I also would not try it via JPL.
Paulo Moura
Logtalk developer

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest