Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(use-modules (opencog)) doesn't seem to load scheme files #128

Closed
ngeiswei opened this issue Jul 6, 2015 · 11 comments
Closed

(use-modules (opencog)) doesn't seem to load scheme files #128

ngeiswei opened this issue Jul 6, 2015 · 11 comments

Comments

@ngeiswei
Copy link
Member

ngeiswei commented Jul 6, 2015

According to opencog/scm/opencog.scm scheme files like utilities.scm should be automatically loaded but aren't.

I've added a bunch of (display "~~~ N ~~~:") in opencog/scm/opencog.scm to see whether those loading lines are executed, they seem to be. I'm really puzzled, see below:

nilg@laptop:~/OpenCog/opencog/opencog/reasoning/pln$ guile --no-auto-compile
;;; note: source file /usr/local/share/opencog/scm/opencog.scm
;;;       newer than compiled /home/nilg/.cache/guile/ccache/2.0-LE-8-2.0/usr/local/share/opencog/scm/opencog.scm.go
~~~ 1 ~~~:~~~ 2 ~~~:~~~ 3 ~~~:~~~ 4 ~~~:~~~ 5 ~~~:GNU Guile 2.0.9
Copyright (C) 1995-2013 Free Software Foundation, Inc.

Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.

Enter `,help' for help.
scheme@(guile-user)> (use-modules (opencog))
scheme@(guile-user)> (stv 1 1)
;;; <stdin>:2:0: warning: possibly unbound variable `stv'
<unnamed port>:2:0: In procedure #<procedure 1ba5020 at <current input>:2:0 ()>:
<unnamed port>:2:0: In procedure module-lookup: Unbound variable: stv

Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
scheme@(guile-user) [1]> (load-from-path "utilities.scm")
scheme@(guile-user) [1]> (stv 1 1)
$1 = (stv 1 0.99999982)

As you can see (stv 1 1) only runs after re-loading utilities.scm. Obviously (using-modules (opencog)) is present in my .guile config file. Running out of idea, any advice is welcome, thanks!

@ngeiswei
Copy link
Member Author

ngeiswei commented Jul 6, 2015

BTW, I've re-added

(load-from-path "utilities.scm")

at the end of opencog.scm. Same thing.

@jswiergo
Copy link
Member

jswiergo commented Jul 6, 2015

Hi. If you use "use-modules" then all variables not exported by the module stay local inside the scope of module. Like a local function variables not visible from outside of the function or private methods in C++.

There are several alternatives:

  1. You can export module public variables, for example explicitly add (export stv) inside the utilities.scm or other place within opencog module scope.

  2. You can switch into opencog module scope

scheme@(guile-user)> (use-modules (opencog))
scheme@(guile-user)> (define-module (opencog))
$1 = #<directory (opencog) 2409870>
scheme@(opencog)> (stv 1 1)
$2 = (stv 1 0,99999982)
scheme@(opencog)> 
  1. Or you can simply use "load-from-path" instead of "use-modules"
scheme@(guile-user)> (load-from-path "opencog.scm")
scheme@(opencog)> (stv 1 1)
$1 = (stv 1 0,99999982)
scheme@(opencog)> 

Maybe this semantics changed between guile versions. Don't know. I checked GNU Guile 2.0.5-deb+1-1.

@linas
Copy link
Member

linas commented Jul 7, 2015

Yes, What Jacek says is right; the current contents of opencog.scm makes an incorrect assumption about exports. The fix would need to be something like (export-everything-in-this-file "utilities.scm") and there must surely be something that already does this, but I don't know where.

@williampma
Copy link
Member

An alternative would be to change all "define" in those scm file to "define-public". That should export the functions (mentioned at https://github.com/opencog/atomspace/blob/master/opencog/scm/opencog.scm#L36 )

Might interfere with the cogserver's way to loading however...

@ngeiswei
Copy link
Member Author

ngeiswei commented Jul 9, 2015

As a non scheme expert it seems the right fix is 1. suggested by @jswiergo . I'll proceed unless you have more suggestions.

@ngeiswei
Copy link
Member Author

ngeiswei commented Jul 9, 2015

hmm, core_types.scm uses define-public.

@williampma why do you think using define-public might interfere with the cogserver's way of loading?

Anyway, I still like @jswiergo first suggestion better, it's good to have control over what is public and what is not, and it's better to have that information around the same place in a file.

@ngeiswei
Copy link
Member Author

ngeiswei commented Jul 9, 2015

According to guile's manual define-public is equivalent to export. So if definie-public interferes with cogserver's way of loading so will export (if it's inside the file).

Somehow I can't do

(for-each export <FUN_LIST>)

or

(for-each (lambda (fun) (export fun) <FUN_LIST>)

maybe I'll use define-public instead...

@ngeiswei
Copy link
Member Author

ngeiswei commented Jul 9, 2015

I've come down to the following compromise, in each scheme file that can be used inside a module I define a function that exports all useful symbols and call it in the module definition, for instance I add

(define (export-utilities) (export av stv itv ...))

in utilities.scm. Then add the following in opencog.scm

(export-utilities)

in opencog.scm.

That way I don't create any interference and don't bloat the module definition.

@linas
Copy link
Member

linas commented Jul 9, 2015

Any of these seem reasonable to me. I don't really know what the "best practices" is supposed to be.

@williampma
Copy link
Member

Ah, ignore my comment about interference. I just wasn't sure whether define-public will work if the function is not in an module.

@linas
Copy link
Member

linas commented Dec 27, 2015

Closing. The problem as originally described appears to be fixed. I don't quite recall the problem, but using export in a loop seemed to be broken on guile,

@linas linas closed this as completed Dec 27, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants