unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Using guile-scmutils with REPL and compilation
@ 2020-06-19 23:43 Viacheslav Dushin
  2020-06-20  7:33 ` Vladimir Zhbanov
  2020-07-04 14:57 ` Vladimir Zhbanov
  0 siblings, 2 replies; 8+ messages in thread
From: Viacheslav Dushin @ 2020-06-19 23:43 UTC (permalink / raw)
  To: guile-user

Hello all

I have a couple of questions about guile-scmutils.

First one:
I run into a similar problem that is described here:
https://lists.gnu.org/archive/html/guile-user/2008-04/msg00007.html
Turns out the solution is to modify top-repl as said here:
https://lists.gnu.org/archive/html/guile-user/2008-04/msg00021.html

Since I'm new to Lisp I decided to work on the ice-9 source code
directly. I'm going to create my own scmutils-top-repl after I resolve
all problems.

Here is how my top-repl from top-repl.scm looks like:

(define (top-repl)
  (let ((guile-user-module (resolve-module '(guile-user))))

    (add-to-load-path "/Users/slava/.guile.d/")
    (load  (%search-load-path  "guile-scmutils/src/load.scm"))
    (set-current-module generic-environment)
    ;; Use some convenient modules (in reverse order)

    (set-current-module guile-user-module)
    (process-use-modules
     (append
      '(((ice-9 r5rs))
        ((ice-9 session)))
      (if (provided? 'regex)
          '(((ice-9 regex)))
          '())
      (if (provided? 'threads)
          '(((ice-9 threads)))
          '())))

    (call-with-sigint
     (lambda ()
       (and (defined? 'setlocale)
            (catch 'system-error
              (lambda ()
                (setlocale LC_ALL ""))
              (lambda (key subr fmt args errno)
                (format (current-error-port)
                        "warning: failed to install locale: ~a~%"
                        (strerror (car errno))))))

       (let ((status (start-repl (current-language))))
         (run-hook exit-hook)
         status)))
    )
  )

I simply added these three lines:
    (add-to-load-path "/Users/slava/.guile.d/")
    (load  (%search-load-path  "guile-scmutils/src/load.scm"))
    (set-current-module generic-environment)

When I run it I get the following error:

;;; note: source file
/usr/local/Cellar/guile/2.2.7_2/share/guile/2.2/ice-9/boot-9.scm
;;;       newer than compiled
/usr/local/Cellar/guile/2.2.7_2/lib/guile/2.2/ccache/ice-9/boot-9.go
;;; note: source file
/usr/local/Cellar/guile/2.2.7_2/share/guile/2.2/ice-9/top-repl.scm
;;;       newer than compiled
/usr/local/Cellar/guile/2.2.7_2/lib/guile/2.2/ccache/ice-9/top-repl.go
;;; note: source file
/usr/local/Cellar/guile/2.2.7_2/share/guile/2.2/ice-9/top-repl.scm
;;;       newer than compiled
/Users/slava/.cache/guile/ccache/2.2-LE-8-3.A/usr/local/Cellar/guile/2.2.7_2/share/guile/2.2/ice-9/top-repl.scm.go
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;;       or pass the --no-auto-compile argument to disable.
;;; compiling /usr/local/Cellar/guile/2.2.7_2/share/guile/2.2/ice-9/top-repl.scm
;;; ice-9/top-repl.scm:53:4: warning: possibly unbound variable
`generic-environment'
;;; compiled /Users/slava/.cache/guile/ccache/2.2-LE-8-3.A/usr/local/Cellar/guile/2.2.7_2/share/guile/2.2/ice-9/top-repl.scm.go
Backtrace:
           3 (apply-smob/1 #<catch-closure 10eabcee0>)
In ice-9/eval.scm:
   657:36  2 (_ _)
In ice-9/top-repl.scm:
     52:4  1 (top-repl)
In unknown file:
           0 (_ #<procedure 10e617440 at ice-9/eval.scm:330:13 ()> # #)

ERROR: In procedure module-lookup: Unbound variable: generic-environment

If I remove (set-current-module guile-user-module), then it runs OK
and I even have access to the scmutils functions, e.g.:

(define h (compose cube sin))
(h 2)

outputs:

.7518269446689928

What am I missing?

Second one:
There is also a problem with code compilation:

(load  (%search-load-path  "guile-scmutils/src/load.scm"))
(set-current-module generic-environment)

(define ((Gamma w) t)
  (up t (w t) ((D w) t)))

works fine in the REPL, but fails to compile (guile code.scm) with the
following error:

;;; note: source file
/usr/local/Cellar/guile/2.2.7_2/share/guile/2.2/ice-9/boot-9.scm
;;;       newer than compiled
/usr/local/Cellar/guile/2.2.7_2/lib/guile/2.2/ccache/ice-9/boot-9.go
;;; note: source file
/Users/slava/Documents/work/func-diff-geometry/prologue/code.scm
;;;       newer than compiled
/Users/slava/.cache/guile/ccache/2.2-LE-8-3.A/Users/slava/Documents/work/func-diff-geometry/prologue/code.scm.go
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;;       or pass the --no-auto-compile argument to disable.
;;; compiling /Users/slava/Documents/work/func-diff-geometry/prologue/code.scm
;;; WARNING: compilation of
/Users/slava/Documents/work/func-diff-geometry/prologue/code.scm
failed:
;;; Syntax error:
;;; /Users/slava/Documents/work/func-diff-geometry/prologue/code.scm:4:0:
source expression failed to match any pattern in form (define ((Gamma
w) t) (up t (w t) ((D w) t)))
Backtrace:
           6 (primitive-load "/Users/slava/Documents/work/func-diff-…")
           5 (_ #<procedure 102790fe0 at ice-9/eval.scm:330:13 ()> # #)
           4 (_ #<procedure 102790ec0 at ice-9/eval.scm:330:13 ()> # #)
           3 (_ #<procedure 102790de0 at ice-9/eval.scm:330:13 ()> # #)
In ice-9/eval.scm:
   245:16  2 (_ #(#(#<module (guile) 102695dc0> #f #<variable 10…> …)))
In unknown file:
           1 (string-prefix? "/" #f #<undefined> #<undefined> #<und…> …)
           0 (_ #<procedure 102790b20 at ice-9/eval.scm:330:13 ()> # #)

ERROR: In procedure string-prefix?: Wrong type argument in position 2
(expecting string): #f

Thanks, Slava



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Using guile-scmutils with REPL and compilation
  2020-06-19 23:43 Using guile-scmutils with REPL and compilation Viacheslav Dushin
@ 2020-06-20  7:33 ` Vladimir Zhbanov
  2020-07-04 14:57 ` Vladimir Zhbanov
  1 sibling, 0 replies; 8+ messages in thread
From: Vladimir Zhbanov @ 2020-06-20  7:33 UTC (permalink / raw)
  To: guile-user

Hi Slava,

On Sat, Jun 20, 2020 at 02:43:00AM +0300, Viacheslav Dushin wrote:

...

> Second one:
> There is also a problem with code compilation:
> 
> (load  (%search-load-path  "guile-scmutils/src/load.scm"))
> (set-current-module generic-environment)
> 
> (define ((Gamma w) t)
>   (up t (w t) ((D w) t)))
> 
> works fine in the REPL, but fails to compile (guile code.scm) with the
> following error:
> 
> ;;; note: source file
> /usr/local/Cellar/guile/2.2.7_2/share/guile/2.2/ice-9/boot-9.scm
> ;;;       newer than compiled
> /usr/local/Cellar/guile/2.2.7_2/lib/guile/2.2/ccache/ice-9/boot-9.go
> ;;; note: source file
> /Users/slava/Documents/work/func-diff-geometry/prologue/code.scm
> ;;;       newer than compiled
> /Users/slava/.cache/guile/ccache/2.2-LE-8-3.A/Users/slava/Documents/work/func-diff-geometry/prologue/code.scm.go
> ;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
> ;;;       or pass the --no-auto-compile argument to disable.
> ;;; compiling /Users/slava/Documents/work/func-diff-geometry/prologue/code.scm
> ;;; WARNING: compilation of
> /Users/slava/Documents/work/func-diff-geometry/prologue/code.scm
> failed:
> ;;; Syntax error:
> ;;; /Users/slava/Documents/work/func-diff-geometry/prologue/code.scm:4:0:
> source expression failed to match any pattern in form (define ((Gamma
> w) t) (up t (w t) ((D w) t)))
> Backtrace:
>            6 (primitive-load "/Users/slava/Documents/work/func-diff-…")
>            5 (_ #<procedure 102790fe0 at ice-9/eval.scm:330:13 ()> # #)
>            4 (_ #<procedure 102790ec0 at ice-9/eval.scm:330:13 ()> # #)
>            3 (_ #<procedure 102790de0 at ice-9/eval.scm:330:13 ()> # #)
> In ice-9/eval.scm:
>    245:16  2 (_ #(#(#<module (guile) 102695dc0> #f #<variable 10…> …)))
> In unknown file:
>            1 (string-prefix? "/" #f #<undefined> #<undefined> #<und…> …)
>            0 (_ #<procedure 102790b20 at ice-9/eval.scm:330:13 ()> # #)
> 
> ERROR: In procedure string-prefix?: Wrong type argument in position 2
> (expecting string): #f

Try

  (load #f)

and you'll get the same error.

`load' requires string as an argument.  AFAICS in the Guile
reference manual, probably the function is supposed to work in
REPL only (while it works without it).

If `%search-load-path' is not able to find the file you want to
load, it returns #f.  You can check your `%load-path' if the
directory with that file is listed in that variable.  If not, use
`add-to-load-path "the-dir-your-file-resides-in"' to make it work,
or use the absolute path of the file.

HTH

-- 
  Vladimir

(λ)επτόν EDA — https://github.com/lepton-eda



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Using guile-scmutils with REPL and compilation
@ 2020-06-20 14:39 Viacheslav Dushin
  0 siblings, 0 replies; 8+ messages in thread
From: Viacheslav Dushin @ 2020-06-20 14:39 UTC (permalink / raw)
  To: guile-user

Hi, Vladimir

>Try

 > (load #f)

> and you'll get the same error.



If I add (load #f)
Then I get the following error in both cases:

ERROR: In procedure string-prefix?: Wrong type argument in position 2
(expecting string): #f

>If not, use
>`add-to-load-path "the-dir-your-file-resides-in"' to make it work,
> or use the absolute path of the file.
Yes, I tried with the absolute path and got the same errors as
described in the initial message.

Thanks, Slava



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Using guile-scmutils with REPL and compilation
@ 2020-07-04  1:06 Viacheslav Dushin
  2020-07-04  4:15 ` Catonano
  0 siblings, 1 reply; 8+ messages in thread
From: Viacheslav Dushin @ 2020-07-04  1:06 UTC (permalink / raw)
  To: guile-user

Anyone?


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Using guile-scmutils with REPL and compilation
  2020-07-04  1:06 Viacheslav Dushin
@ 2020-07-04  4:15 ` Catonano
  0 siblings, 0 replies; 8+ messages in thread
From: Catonano @ 2020-07-04  4:15 UTC (permalink / raw)
  To: Viacheslav Dushin; +Cc: Guile User

Il giorno sab 4 lug 2020 alle ore 03:06 Viacheslav Dushin <
slava333@gmail.com> ha scritto:

> Anyone?
>

In the past I tried to start reading the SICM

When I came to the part where I had to make MIT-scheme work with the
scmutils, I got discouraged and gave up

I won't go into why it was unusable, but it was

The fact that the scmutils have been ported to Guile is good news but it's
a small step

If there's a unit tests suite, I'd be willing to run it and report results

If there's no such suite, I'd be willing to contribute to write it, given
that someone explains me what the API is supposed to do

Should this thing get momentum it could lead me to try to read the SICM
again

Thanks


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Using guile-scmutils with REPL and compilation
  2020-06-19 23:43 Using guile-scmutils with REPL and compilation Viacheslav Dushin
  2020-06-20  7:33 ` Vladimir Zhbanov
@ 2020-07-04 14:57 ` Vladimir Zhbanov
  2020-07-08 21:04   ` Viacheslav Dushin
  1 sibling, 1 reply; 8+ messages in thread
From: Vladimir Zhbanov @ 2020-07-04 14:57 UTC (permalink / raw)
  To: guile-user

On Sat, Jun 20, 2020 at 02:43:00AM +0300, Viacheslav Dushin wrote:
> Hello all
> 
> I have a couple of questions about guile-scmutils.
> 
> First one:
> I run into a similar problem that is described here:
> https://lists.gnu.org/archive/html/guile-user/2008-04/msg00007.html
> Turns out the solution is to modify top-repl as said here:
> https://lists.gnu.org/archive/html/guile-user/2008-04/msg00021.html
> 
> Since I'm new to Lisp I decided to work on the ice-9 source code
> directly. I'm going to create my own scmutils-top-repl after I resolve
> all problems.
> 
> Here is how my top-repl from top-repl.scm looks like:
> 
> (define (top-repl)
>   (let ((guile-user-module (resolve-module '(guile-user))))
> 
>     (add-to-load-path "/Users/slava/.guile.d/")
>     (load  (%search-load-path  "guile-scmutils/src/load.scm"))
>     (set-current-module generic-environment)
>     ;; Use some convenient modules (in reverse order)
> 
>     (set-current-module guile-user-module)
>     (process-use-modules
>      (append
>       '(((ice-9 r5rs))
>         ((ice-9 session)))
>       (if (provided? 'regex)
>           '(((ice-9 regex)))
>           '())
>       (if (provided? 'threads)
>           '(((ice-9 threads)))
>           '())))
> 
>     (call-with-sigint
>      (lambda ()
>        (and (defined? 'setlocale)
>             (catch 'system-error
>               (lambda ()
>                 (setlocale LC_ALL ""))
>               (lambda (key subr fmt args errno)
>                 (format (current-error-port)
>                         "warning: failed to install locale: ~a~%"
>                         (strerror (car errno))))))
> 
>        (let ((status (start-repl (current-language))))
>          (run-hook exit-hook)
>          status)))
>     )
>   )
> 
> I simply added these three lines:
>     (add-to-load-path "/Users/slava/.guile.d/")
>     (load  (%search-load-path  "guile-scmutils/src/load.scm"))
>     (set-current-module generic-environment)

The question is not about scmutils :-)

You can run Guile interactively, just type 'guile' in your
terminal, and check what every command returns. For example, the
following commands will give you your load path before and after
launching 'add-to-load-path':

scheme@(guile-user)> %load-path
scheme@(guile-user)> (add-to-load-path "/Users/slava/.guile.d/")
scheme@(guile-user)> %load-path

Check, if the directory *really* contains your file
"guile-scmutils/src/load.scm", and try the following after that:

scheme@(guile-user)> (%search-load-path  "guile-scmutils/src/load.scm")

Make sure the file is found and is a string, not #f.  As I said
before (not sure you got it, sorry), 'load' will barf if its
argument is not a string.  It *will* barf if the argument is #f.
So, only if the command above returns the file name you're
searching for, try loading it:

scheme@(guile-user)> (load  (%search-load-path  "guile-scmutils/src/load.scm"))

Another way is to just use:

scheme@(guile-user)> (primitive-load "/My/absolute/file/name.scm")

If you're defining a module in your file, use the 'use-modules'
procedure to load it.

Now about your second question.

I don't know, what 'generic-environment' is.  Is it defined at
all?  Try on the prompt:

scheme@(guile-user)> generic-environment

and read what it reports.

BTW, the command '(set-current-module generic-environment)' won't
work anyway in your code, since you use '(set-current-module
guile-user-module)' just *after* it.

HTH

-- 
  Vladimir

(λ)επτόν EDA — https://github.com/lepton-eda



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Using guile-scmutils with REPL and compilation
  2020-07-04 14:57 ` Vladimir Zhbanov
@ 2020-07-08 21:04   ` Viacheslav Dushin
  2020-07-09  6:32     ` Vladimir Zhbanov
  0 siblings, 1 reply; 8+ messages in thread
From: Viacheslav Dushin @ 2020-07-08 21:04 UTC (permalink / raw)
  To: guile-user

Hello, sorry for the late reply.

zhbanov@gmail.com


I already have "/Users/slava/.guile.d/" in the load path
>scheme@(guile-user)> %load-path
Here is the output:
$1 = ("/Users/slava/.guile.d/"
"/usr/local/Cellar/guile/2.2.7_2/share/guile/2.2"
"/usr/local/Cellar/guile/2.2.7_2/share/guile/site/2.2"
"/usr/local/Cellar/guile/2.2.7_2/share/guile/site"
"/usr/local/Cellar/guile/2.2.7_2/share/guile")

>Check, if the directory *really* contains your file
>"guile-scmutils/src/load.scm", and try the following after that:

>scheme@(guile-user)> (%search-load-path  "guile-scmutils/src/load.scm")
yes, I checked, the file is there:
 (%search-load-path  "guile-scmutils/src/load.scm")
$1 = "/Users/slava/.guile.d/guile-scmutils/src/load.scm"


>So, only if the command above returns the file name you're
>searching for, try loading it:

>scheme@(guile-user)> (load  (%search-load-path
 "guile-scmutils/src/load.scm"))
yes, it works, the output:
(load  (%search-load-path  "guile-scmutils/src/load.scm"))
$2 = done

>Another way is to just use:

>scheme@(guile-user)> (primitive-load "/My/absolute/file/name.scm")

What's the key difference between load and primitive-load? The docs are
unclear.

There is a strange thing: compilator was able to find
"guile-scmutils/src/load.scm"
only when I added "/Users/slava/.guile.d/" at the beginning of my code.
In interactive mode this line is not needed: `.guile` file is loaded.

>If you're defining a module in your file, use the 'use-modules'
>procedure to load it.
Ok, I'll post the updated code later

Now about your second question.

>I don't know, what 'generic-environment' is.  Is it defined at
>all?
Yes, in guile-scmutils/src/kernel/genenv-module.scm

>Try on the prompt:

>scheme@(guile-user)> generic-environment

>and read what it reports.
yes, the output is:
$2 = #<module (#{ g3541}#) 110a1a8c0>

>BTW, the command '(set-current-module generic-environment)' won't
>work anyway in your code, since you use '(set-current-module
>guile-user-module)' just *after* it.
my bad.


Anyway thanks for your answer. I moved a bit forward with this code

(add-to-load-path "/Users/slava/.guile.d/")
(load  (%search-load-path  "guile-scmutils/src/load.scm"))
(use-modules (generic-environment))

Now it fails with the following error:

;;; note: source file
/Users/slava/Documents/work/func-diff-geometry/prologue/code.scm
;;;       newer than compiled
/Users/slava/.cache/guile/ccache/3.0-LE-8-4.3/Users/slava/Documents/work/func-diff-geometry/prologue/code.scm.go
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;;       or pass the --no-auto-compile argument to disable.
;;; compiling
/Users/slava/Documents/work/func-diff-geometry/prologue/code.scm
;;; WARNING: compilation of
/Users/slava/Documents/work/func-diff-geometry/prologue/code.scm failed:
;;; no code for module (generic-environment)


I think the main question is why REPL and compiler act differently.
This code works ok inside the REPL but fails to compile:
(add-to-load-path "/Users/slava/.guile.d/")
(load  (%search-load-path  "guile-scmutils/src/load.scm"))

(set-current-module generic-environment)

(define ((Gamma w) t)
  (up t (w t) ((D w) t)))

I'll keep looking into the scmutils code right now.

Thanks, Slava


>
>
>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Using guile-scmutils with REPL and compilation
  2020-07-08 21:04   ` Viacheslav Dushin
@ 2020-07-09  6:32     ` Vladimir Zhbanov
  0 siblings, 0 replies; 8+ messages in thread
From: Vladimir Zhbanov @ 2020-07-09  6:32 UTC (permalink / raw)
  To: guile-user

On Thu, Jul 09, 2020 at 12:04:29AM +0300, Viacheslav Dushin wrote:

...

> >Another way is to just use:
> 
> >scheme@(guile-user)> (primitive-load "/My/absolute/file/name.scm")
> 
> What's the key difference between load and primitive-load? The docs are
> unclear.

AFAICS in the docs, under the hood, 'load' calls for
'primitive-load', it's a wrapper for it and may take an additional
argument, the "reader" procedure.  It's a subject to play with :-)

...

> Anyway thanks for your answer. I moved a bit forward with this code
> 
> (add-to-load-path "/Users/slava/.guile.d/")
> (load  (%search-load-path  "guile-scmutils/src/load.scm"))
> (use-modules (generic-environment))
> 
> Now it fails with the following error:
> 
> ;;; note: source file
> /Users/slava/Documents/work/func-diff-geometry/prologue/code.scm
> ;;;       newer than compiled
> /Users/slava/.cache/guile/ccache/3.0-LE-8-4.3/Users/slava/Documents/work/func-diff-geometry/prologue/code.scm.go
> ;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
> ;;;       or pass the --no-auto-compile argument to disable.
> ;;; compiling
> /Users/slava/Documents/work/func-diff-geometry/prologue/code.scm
> ;;; WARNING: compilation of
> /Users/slava/Documents/work/func-diff-geometry/prologue/code.scm failed:
> ;;; no code for module (generic-environment)

Is there the file "generic-environment.scm" with the module
definition "(define-module (generic-environment) ...)" in the
'%load-path' visible within 'code.scm'?

...

> I think the main question is why REPL and compiler act differently.
> This code works ok inside the REPL but fails to compile:
> (add-to-load-path "/Users/slava/.guile.d/")
> (load  (%search-load-path  "guile-scmutils/src/load.scm"))
> 
> (set-current-module generic-environment)
> 
> (define ((Gamma w) t)
>   (up t (w t) ((D w) t)))

Maybe, different settings wrt '%load-path' and such in some config
files?  Or maybe some additional modules are loaded when the REPL
starts?  Check what '%load-path' and '(module-uses
(current-module))' return in both cases. (Dunno, if
'%load-compiled-path' can affect something in such a case.)

HTH

-- 
  Vladimir

(λ)επτόν EDA — https://github.com/lepton-eda



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-07-09  6:32 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-19 23:43 Using guile-scmutils with REPL and compilation Viacheslav Dushin
2020-06-20  7:33 ` Vladimir Zhbanov
2020-07-04 14:57 ` Vladimir Zhbanov
2020-07-08 21:04   ` Viacheslav Dushin
2020-07-09  6:32     ` Vladimir Zhbanov
  -- strict thread matches above, loose matches on Subject: below --
2020-06-20 14:39 Viacheslav Dushin
2020-07-04  1:06 Viacheslav Dushin
2020-07-04  4:15 ` Catonano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).