Setting swi homedir without setting the env variable

View: New views
11 Messages — Rating Filter:   Alert me  

Setting swi homedir without setting the env variable

by Victor NOEL :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

I was wondering if it was possible to tell where is the swi
homedir to swi-prolog, without setting the SWI_HOME_DIR environment
variable.

I noticed that each time I tried to use swi-prolog with java, I
had problem with this.

I couldn't find an option for the executable, but maybe there is a
predicate that I can call with -f option to set this before pl is
started ?

I am actually trying to make a clean wrapper (based on jpl for
now) for swipl and logtalk for Scala (a functional programming
language based on java) and I am at the point where I am trying
to find the best way to distribute all of it in a jar file
(swi-pl library + my code) and the last problem I have is to
set this variable :)

Thanks you.

Victor


signature.asc (196 bytes) Download Attachment

Re: Setting swi homedir without setting the env variable

by Jan Wielemaker :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Victor,

On Tuesday 22 April 2008 17:19:05 Victor NOEL wrote:
> I was wondering if it was possible to tell where is the swi
> homedir to swi-prolog, without setting the SWI_HOME_DIR environment
> variable.

There are several ways the SWI-Prolog kernel uses to try and find its
home. SWI_HOME_DIR is the first and therefore the most simple and
portable one.  What is wrong with it?  Isn't it possible to set it
from Java?

> I noticed that each time I tried to use swi-prolog with java, I
> had problem with this.
>
> I couldn't find an option for the executable, but maybe there is a
> predicate that I can call with -f option to set this before pl is
> started ?

It needs it's home before that, as the homedir is where it finds the
compiled Prolog boot code.

> I am actually trying to make a clean wrapper (based on jpl for
> now) for swipl and logtalk for Scala (a functional programming
> language based on java) and I am at the point where I am trying
> to find the best way to distribute all of it in a jar file
> (swi-pl library + my code) and the last problem I have is to
> set this variable :)

If using an environment variable isn't portable (enough), I'm happy to
provide a --home=Dir option to PL_initialise().  All I want is a clear
answer that using the environment doesn't work for Java.  I understand
some systems don't define the notion of environment, but SWI-Prolog is
not very likely to run on these anyway.

        Cheers --- Jan



------------
For further info, please visit http://www.swi-prolog.org/

To unsubscribe, send a plaintext mail with "unsubscribe prolog <e-mail>"
in its body to majordomo@...

Re: Setting swi homedir without setting the env variable

by Victor NOEL :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, Apr 22, 2008 at 08:21:33PM +0200, Jan Wielemaker wrote:

> Victor,
>
> On Tuesday 22 April 2008 17:19:05 Victor NOEL wrote:
> > I was wondering if it was possible to tell where is the swi
> > homedir to swi-prolog, without setting the SWI_HOME_DIR environment
> > variable.
>
> There are several ways the SWI-Prolog kernel uses to try and find its
> home. SWI_HOME_DIR is the first and therefore the most simple and
> portable one.  What is wrong with it?  Isn't it possible to set it
> from Java?
I tried for some times to look for a way to modify environment
variables of the running application from java, but it looks like
it is not possible. The only solution I can find was to use JNI to
call setenv but I don't think it is very portable, and I am not
even sure it will work (I didn't try to implement it)

> If using an environment variable isn't portable (enough), I'm happy to
> provide a --home=Dir option to PL_initialise().  All I want is a clear
> answer that using the environment doesn't work for Java.  I understand
> some systems don't define the notion of environment, but SWI-Prolog is
> not very likely to run on these anyway.

As far as I know, there is no way to do it from java, so, I think
that using an option for PL_initialise() is the best idea, at
least in my case.

>
> Cheers --- Jan

When I will be finished with this library, I will post on the list
to present it to people that may be interested by it and I hope
get some comments on it :)

Thanks for your help,

Victor


signature.asc (196 bytes) Download Attachment

Re: Setting swi homedir without setting the env variable

by Jan Wielemaker :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wednesday 23 April 2008 11:57, Victor NOEL wrote:
> As far as I know, there is no way to do it from java, so, I think
> that using an option for PL_initialise() is the best idea, at
> least in my case.

Added support for --home=DIR to the latest GIT version.

        --- Jan


------------
For further info, please visit http://www.swi-prolog.org/

To unsubscribe, send a plaintext mail with "unsubscribe prolog <e-mail>"
in its body to majordomo@...

Re: Setting swi homedir without setting the env variable

by Victor NOEL :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, Apr 23, 2008 at 01:34:11PM +0200, Jan Wielemaker wrote:
>
> Added support for --home=DIR to the latest GIT version.

I got it, make some tests, and it looks like it works well with
command line pl, but I couldn't get it to work with java.

Can you confirm me that the following code will initialize
swi-prolog in a good way :

String[] initArgs = new String[] {"pl", "--home=\"/users/stages/noel/Stage/Code/stage/repo/scalogtalk/swipl/\""};
println("a");
jpl.JPL.setDefaultInitArgs(initArgs);
println("b");
if (!jpl.JPL.init()) println("already init");
else println("init");

When I run this kind of code, I get this error :
a
b
[FATAL ERROR:
        Saved state has incompatible save version]

It really looks like --home is not used ... But if I call in a
console :
pl --home="/users/stages/noel/Stage/Code/stage/repo/scalogtalk/swipl/"

It works

Thanks,

Victor


signature.asc (196 bytes) Download Attachment

Re: Setting swi homedir without setting the env variable

by Jan Wielemaker :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wednesday 23 April 2008 16:05, Victor NOEL wrote:

> On Wed, Apr 23, 2008 at 01:34:11PM +0200, Jan Wielemaker wrote:
> > Added support for --home=DIR to the latest GIT version.
>
> I got it, make some tests, and it looks like it works well with
> command line pl, but I couldn't get it to work with java.
>
> Can you confirm me that the following code will initialize
> swi-prolog in a good way :
>
> String[] initArgs = new String[] {"pl",
> "--home=\"/users/stages/noel/Stage/Code/stage/repo/scalogtalk/swipl/\""};

You don't need the \" in there.  In your commandline argument they
are removed by the shell, but there is no shell in between anymore to
do that.  This will look for a path holding " in it.

        Cheers --- Jan

> println("a");
> jpl.JPL.setDefaultInitArgs(initArgs);
> println("b");
> if (!jpl.JPL.init()) println("already init");
> else println("init");
>
> When I run this kind of code, I get this error :
> a
> b
> [FATAL ERROR:
>         Saved state has incompatible save version]
>
> It really looks like --home is not used ... But if I call in a
> console :
> pl --home="/users/stages/noel/Stage/Code/stage/repo/scalogtalk/swipl/"
>
> It works
>
> Thanks,
>
> Victor


------------
For further info, please visit http://www.swi-prolog.org/

To unsubscribe, send a plaintext mail with "unsubscribe prolog <e-mail>"
in its body to majordomo@...

Re: Setting swi homedir without setting the env variable

by Victor NOEL :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, Apr 23, 2008 at 05:13:46PM +0200, Jan Wielemaker wrote:
> > String[] initArgs = new String[] {"pl",
> > "--home=\"/users/stages/noel/Stage/Code/stage/repo/scalogtalk/swipl/\""};
>
> You don't need the \" in there.  In your commandline argument they
> are removed by the shell, but there is no shell in between anymore to
> do that.  This will look for a path holding " in it.
>

I already tried without it (and I verified again before answering :)
and it doesn't work.

Victor


signature.asc (196 bytes) Download Attachment

Re: Setting swi homedir without setting the env variable

by Jan Wielemaker :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wednesday 23 April 2008 17:52:50 Victor NOEL wrote:

> On Wed, Apr 23, 2008 at 05:13:46PM +0200, Jan Wielemaker wrote:
> > > String[] initArgs = new String[] {"pl",
> > > "--home=\"/users/stages/noel/Stage/Code/stage/repo/scalogtalk/swipl/\""
> > >};
> >
> > You don't need the \" in there.  In your commandline argument they
> > are removed by the shell, but there is no shell in between anymore to
> > do that.  This will look for a path holding " in it.
>
> I already tried without it (and I verified again before answering :)
> and it doesn't work.

"doesn't work" isn't very informative.  As you use the source anyway,
put some print statements in findHome() in pl-main.c to see what goes
wrong.

        Cheers --- Jan


------------
For further info, please visit http://www.swi-prolog.org/

To unsubscribe, send a plaintext mail with "unsubscribe prolog <e-mail>"
in its body to majordomo@...

Re: Setting swi homedir without setting the env variable

by Victor NOEL :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, Apr 23, 2008 at 08:54:27PM +0200, Jan Wielemaker wrote:

> On Wednesday 23 April 2008 17:52:50 Victor NOEL wrote:
> > On Wed, Apr 23, 2008 at 05:13:46PM +0200, Jan Wielemaker wrote:
> > > > String[] initArgs = new String[] {"pl",
> > > > "--home=\"/users/stages/noel/Stage/Code/stage/repo/scalogtalk/swipl/\""
> > > >};
> > >
> > > You don't need the \" in there.  In your commandline argument they
> > > are removed by the shell, but there is no shell in between anymore to
> > > do that.  This will look for a path holding " in it.
> >
> > I already tried without it (and I verified again before answering :)
> > and it doesn't work.
>
> "doesn't work" isn't very informative.  As you use the source anyway,
You are right, but there is not very much information when using
jpl

> put some print statements in findHome() in pl-main.c to see what goes
> wrong.

This is exactly what I was planning to do tomorrow.
I will get back to you when I found where is the problem :)

>
> Cheers --- Jan
>
>
> ------------
> For further info, please visit http://www.swi-prolog.org/
>
> To unsubscribe, send a plaintext mail with "unsubscribe prolog <e-mail>"
> in its body to majordomo@...


signature.asc (196 bytes) Download Attachment

Re: Setting swi homedir without setting the env variable

by Victor NOEL :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, Apr 23, 2008 at 08:54:27PM +0200, Jan Wielemaker wrote:
> "doesn't work" isn't very informative.  As you use the source anyway,
> put some print statements in findHome() in pl-main.c to see what goes
> wrong.

I was finally able to make it works.
I don't know why but it looks like that when recompiling swipl,
the libjpl.so wasn't.

But when I was trying to enable debug in jpl.c, I guess because it
was modified, libjpl.so was recompiled and it worked.

While doing all of this, I noticed these two things :
1) You changed the documentation for the option "-nosignals" to
"--nosignals" but it looks like pl-main.c is looking for
"-nosignals" (I just took a look at the isoption function)
Maybe other options are impacted by this ? (Or maybe I misread and
there is nothing strange about this :)
2) If I move the source tree after doing a configure, and if I do
a configure again, the source tree doesn't compile for some
packages that did not update the source tree directory in their makefile...

Anyway, thanks you, all is working great now, I hope I will be
finished soon to get some comment on my work :)

>
> Cheers --- Jan

Victor


signature.asc (196 bytes) Download Attachment

Re: Setting swi homedir without setting the env variable

by Jan Wielemaker :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thursday 24 April 2008 12:05, Victor NOEL wrote:

> On Wed, Apr 23, 2008 at 08:54:27PM +0200, Jan Wielemaker wrote:
> > "doesn't work" isn't very informative.  As you use the source anyway,
> > put some print statements in findHome() in pl-main.c to see what goes
> > wrong.
>
> I was finally able to make it works.
> I don't know why but it looks like that when recompiling swipl,
> the libjpl.so wasn't.
>
> But when I was trying to enable debug in jpl.c, I guess because it
> was modified, libjpl.so was recompiled and it worked.

The default on linux on IA32 (32-bit intel) is to put the SWI-Prolog
kernel in a static library (libpl.a), which is linked into libjpl.so, so
you need to relink libjpl.so if you modify Prolog. This is because a
shared object is about 10% slower and using a static library you can
still link it into another shared object on Linux. On most other
platforms Prolog is put in a shared object or DLL because either there
is no significant speed difference or it is not possible to embed using
a static library.

> While doing all of this, I noticed these two things :
> 1) You changed the documentation for the option "-nosignals" to
> "--nosignals" but it looks like pl-main.c is looking for
> "-nosignals" (I just took a look at the isoption function)

If you read more carefully you'll see it accepts both.  --nosignals
is the preferred way; -nosignals is kept for compatibility.

> Maybe other options are impacted by this ? (Or maybe I misread and
> there is nothing strange about this :)
> 2) If I move the source tree after doing a configure, and if I do
> a configure again, the source tree doesn't compile for some
> packages that did not update the source tree directory in their makefile...

Did you do a "make distclean" before?

        Cheers --- Jan


------------
For further info, please visit http://www.swi-prolog.org/

To unsubscribe, send a plaintext mail with "unsubscribe prolog <e-mail>"
in its body to majordomo@...