Re: Weird import behaviour of digital modules

2024-06-08 Thread lloda



> On 8 Jun 2024, at 19:30, Tomas Volf <~@wolfsden.cz> wrote:
> 
> On 2024-06-08 15:59:12 +0200, lloda wrote:
>> Modules can't have numbers as names in general
> 
> Modules most definitely *can* have numbers as names, my Advent of Code 
> solutions
> are stored in files matching $YEAR/$DAY pattern (e.g. 2023/01.scm) and it 
> works
> just fine, both define-module and use-modules.

i stand corrected. But then why isn't srfi/n a symlink to srfi/srfi-n instead 
of the way it's done that only works with import?

regards

  daniel


Re: Weird import behaviour of digital modules

2024-06-08 Thread Tomas Volf
On 2024-06-08 15:59:12 +0200, lloda wrote:
> Modules can't have numbers as names in general

Modules most definitely *can* have numbers as names, my Advent of Code solutions
are stored in files matching $YEAR/$DAY pattern (e.g. 2023/01.scm) and it works
just fine, both define-module and use-modules.

Have a nice day,
Tomas Volf

--
There are only two hard things in Computer Science:
cache invalidation, naming things and off-by-one errors.


signature.asc
Description: PGP signature


Re: Weird import behaviour of digital modules

2024-06-08 Thread lloda



> On 7 Jun 2024, at 21:51, Yuval Langer  wrote:
> 
> In this commit I have the WEIRDEST behaviour:
> 
> https://codeberg.org/kakafarm/guile-srfi-189/commit/6e72cc50cc6b068de726f6e97b249a5af26d883c
> 
> When I run the following command at the repository worktree root:
> 
> ```
> guix shell -C guile -- guile -L . test-guile.scm
> ```
> 
> all tests pass, but at line 24 of test-body.scm we have:
> 
> ```
> (import (srfi 189))
> ```
> 
> and that should not work on Guile, right?  That's why we have SRFIs
> located at `(srfi srfi-189)`, no?
> 
> Thank you,
> Yuval Langer.

hi Yuval, 

guile has supported the format (srfi n) in import clauses for a while. Modules 
can't have numbers as names in general, this only works for srfis and 
specifically for this format. For example (srfi 4 gnu) won't work. Also only 
import works, not use-modules. Iirc the support was added for r6rs or r7rs 
compatibility.

regards




Weird import behaviour of digital modules

2024-06-07 Thread Yuval Langer
In this commit I have the WEIRDEST behaviour:

https://codeberg.org/kakafarm/guile-srfi-189/commit/6e72cc50cc6b068de726f6e97b249a5af26d883c

When I run the following command at the repository worktree root:

```
guix shell -C guile -- guile -L . test-guile.scm
```

all tests pass, but at line 24 of test-body.scm we have:

```
(import (srfi 189))
```

and that should not work on Guile, right?  That's why we have SRFIs
located at `(srfi srfi-189)`, no?

Thank you,
Yuval Langer.



Re: Help with modules and unit tests

2023-12-08 Thread Luis Felipe


El 8/12/23 a las 14:26, Luis Felipe escribió:

Hi Nikolaos,

El 8/12/23 a las 6:59, Nikolaos Chatzikonstantinou escribió:

Hello guile-user list,

I am trying to figure out modules and unit tests on Guile.

I would like to have a main.scm that prints a variable defined in
lib.scm and has unit tests in test.scm.

What I thought I had to do was to use

 (add-to-load-path (dirname (current-filename)))

This seemed to be the suggestion in 6.16.8 Load Paths of the Guile
manual. My entire main.scm looks like this:

 (define-module (applejack main))
 (add-to-load-path (dirname (current-filename)))
 (use-modules (applejack lib))
 (define-public (main)
   (format #t "Hello from ~a!~%" name))

My lib.scm is:

 (define-module (applejack))
 (define-public name "Applejack")

but I get an error, which I believe originates from current-filename
returning #f. Separately, the test suite in test.scm is just the
example in SRFI-64, but I don't know how to run it. I am using Emacs
and geiser-mode. If I run geiser-eval-buffer, I get test output, and
it promises that there is some more in vec-test.log, but the logfile
stands empty.

I would appreciate it if some pointers for the workflow of a small
Guile project along the lines above were given.


Personally, I'm using these

For running tests: https://luis-felipe.gitlab.io/guile-proba/


For documentation extraction: https://luis-felipe.gitlab.io/guile-documenta/

(I sent the message incomplete by accident)



OpenPGP_0x0AB0D067012F08C3.asc
Description: OpenPGP public key


OpenPGP_signature
Description: OpenPGP digital signature


Re: Help with modules and unit tests

2023-12-08 Thread Luis Felipe

Hi Nikolaos,

El 8/12/23 a las 6:59, Nikolaos Chatzikonstantinou escribió:

Hello guile-user list,

I am trying to figure out modules and unit tests on Guile.

I would like to have a main.scm that prints a variable defined in
lib.scm and has unit tests in test.scm.

What I thought I had to do was to use

 (add-to-load-path (dirname (current-filename)))

This seemed to be the suggestion in 6.16.8 Load Paths of the Guile
manual. My entire main.scm looks like this:

 (define-module (applejack main))
 (add-to-load-path (dirname (current-filename)))
 (use-modules (applejack lib))
 (define-public (main)
   (format #t "Hello from ~a!~%" name))

My lib.scm is:

 (define-module (applejack))
 (define-public name "Applejack")

but I get an error, which I believe originates from current-filename
returning #f. Separately, the test suite in test.scm is just the
example in SRFI-64, but I don't know how to run it. I am using Emacs
and geiser-mode. If I run geiser-eval-buffer, I get test output, and
it promises that there is some more in vec-test.log, but the logfile
stands empty.

I would appreciate it if some pointers for the workflow of a small
Guile project along the lines above were given.


Personally, I'm using these

For running tests: https://luis-felipe.gitlab.io/guile-proba/




OpenPGP_0x0AB0D067012F08C3.asc
Description: OpenPGP public key


OpenPGP_signature
Description: OpenPGP digital signature


Help with modules and unit tests

2023-12-08 Thread Nikolaos Chatzikonstantinou
Hello guile-user list,

I am trying to figure out modules and unit tests on Guile.

I would like to have a main.scm that prints a variable defined in
lib.scm and has unit tests in test.scm.

What I thought I had to do was to use

(add-to-load-path (dirname (current-filename)))

This seemed to be the suggestion in 6.16.8 Load Paths of the Guile
manual. My entire main.scm looks like this:

(define-module (applejack main))
(add-to-load-path (dirname (current-filename)))
(use-modules (applejack lib))
(define-public (main)
  (format #t "Hello from ~a!~%" name))

My lib.scm is:

(define-module (applejack))
(define-public name "Applejack")

but I get an error, which I believe originates from current-filename
returning #f. Separately, the test suite in test.scm is just the
example in SRFI-64, but I don't know how to run it. I am using Emacs
and geiser-mode. If I run geiser-eval-buffer, I get test output, and
it promises that there is some more in vec-test.log, but the logfile
stands empty.

I would appreciate it if some pointers for the workflow of a small
Guile project along the lines above were given.

Regards,
Nikolaos Chatzikonstantinou



Re: Help with modules and unit tests

2023-12-08 Thread Nikolaos Chatzikonstantinou
On Fri, Dec 8, 2023 at 1:59 AM Nikolaos Chatzikonstantinou
 wrote:
>
> Hello guile-user list,
>
> I am trying to figure out modules and unit tests on Guile.

Although I still appreciate the responses I may get, to save you all
some keystrokes, I found guile-dns to be a decent (and small) project
that shows off all the relevant bits I was curious about.
<https://git.lysator.liu.se/hugo/guile-dns>. However, I am still
wondering, how is documentation extracted from the source code with
guild doc-snarf?

Regards,
Nikolaos Chatzikonstantinou



Re: Using Guile 2.2 modules with Guile 3

2022-08-06 Thread Maxime Devos


On 06-08-2022 17:31, Olivier Dion wrote:

old


Going by the package definition, guile-dbd-postgresql seems to make a
Guile extension (C). There have been incompatible changes (both on the
Guile code level, and presumably on the C level). As such, sounds risky
to me.

Also, for whatever reason, guile-dbi propagates an old guile, so you'll
get a propagation conflict without guarantees on which Guile version ‘wins’.


So I guess it would be better for me to use something like guile-sqlite3.


Myself I think it would be better to update guile-dbi to the new Guile.

There were a few incompatible changes between the two Guile major 
versions, but very little and easy to resolve in my experience.


Greetings,
Maxime.



OpenPGP_0x49E3EE22191725EE.asc
Description: OpenPGP public key


OpenPGP_signature
Description: OpenPGP digital signature


Re: Using Guile 2.2 modules with Guile 3

2022-08-06 Thread Olivier Dion via General Guile related discussions
On Sat, 06 Aug 2022, Maxime Devos  wrote:
> On 06-08-2022 17:11, Olivier Dion via General Guile related discussions 
> wrote:
>> Hi,
>>
>> Say I want to use guile-dbi wich use Guile 2.2.  Is there any danger for
>> me to use it with Guile 3.0?  I see that Guile will recompile the module
>> because the already compiled one does not match, I guess.  Other than
>> that, any side effects?
>>
>> Regards,
>> old
>>
> Going by the package definition, guile-dbd-postgresql seems to make a 
> Guile extension (C). There have been incompatible changes (both on the 
> Guile code level, and presumably on the C level). As such, sounds risky 
> to me.
>
> Also, for whatever reason, guile-dbi propagates an old guile, so you'll 
> get a propagation conflict without guarantees on which Guile version ‘wins’.
>
So I guess it would be better for me to use something like guile-sqlite3.

-- 
Olivier Dion
oldiob.dev



Re: Using Guile 2.2 modules with Guile 3

2022-08-06 Thread Maxime Devos


On 06-08-2022 17:11, Olivier Dion via General Guile related discussions 
wrote:

Hi,

Say I want to use guile-dbi wich use Guile 2.2.  Is there any danger for
me to use it with Guile 3.0?  I see that Guile will recompile the module
because the already compiled one does not match, I guess.  Other than
that, any side effects?

Regards,
old

Going by the package definition, guile-dbd-postgresql seems to make a 
Guile extension (C). There have been incompatible changes (both on the 
Guile code level, and presumably on the C level). As such, sounds risky 
to me.


Also, for whatever reason, guile-dbi propagates an old guile, so you'll 
get a propagation conflict without guarantees on which Guile version ‘wins’.


Greetings,
Maxime.



OpenPGP_0x49E3EE22191725EE.asc
Description: OpenPGP public key


OpenPGP_signature
Description: OpenPGP digital signature


Using Guile 2.2 modules with Guile 3

2022-08-06 Thread Olivier Dion via General Guile related discussions
Hi,

Say I want to use guile-dbi wich use Guile 2.2.  Is there any danger for
me to use it with Guile 3.0?  I see that Guile will recompile the module
because the already compiled one does not match, I guess.  Other than
that, any side effects?

Regards,
old

-- 
Olivier Dion
oldiob.dev




Guile Sandbox and importing modules

2020-04-07 Thread Kovacsics Róbert
Hi,

I have been playing around with libfive-{guile,studio}, which seems
nice so far, but one of the problems is it doesn't support importing
other modules due to the sandboxing, AFAICS
(https://github.com/libfive/libfive/issues/285). I wonder if I could
have some opinions on it, e.g. if I were to put use-modules into a
sandbox would it break the sandbox completely? Presumably if I am
importing/compiling code (such as read/eval) within the sandbox just
as if it were written inline, it won't break the sandbox -- just fail
to load. Do I have to write my own load function that does this? Will
this strategy break with compiled .go files, which might I presume
call out to arbitrary C or somesuch, and would first need to be
analysed.

Thanks,
Robert



Re: How to correctly load modules from runtime defineable locations?

2020-03-08 Thread Ludovic Courtès
Hello,

Михаил Бахтерев  skribis:

> (let* ((fn (current-filename))   
>(dir (if (string? fn) (dirname fn) "."))  
>(lib (if (string? fn) (string-append (dirname dir) "/lib") "../lib")))
>   (add-to-load-path lib)
>   (add-to-load-path dir))

I think the crux is that you’d like this code to run both at
macro-expansion time and at run time.  To do that, you need to enclose
it in ‘eval-when’ (info "(guile) Eval When"):

  (eval-when (expand load eval)
(let …
  (add-to-load-path …)
  …))

(Note that ‘add-to-load-path’ actually does this, but only if the
argument is a literal string.)

HTH!

Ludo’.




Re: How to correctly load modules from runtime defineable locations?

2020-03-06 Thread Zelphir Kaltstahl
Hi!

I don't know about other ways, but using the -L argument, you can run
Guile programs from anywhere, because it will have the effect of making
it look to Guile as if it was started from that -L specified path.

Using `add-to-load-path` would be in your code, but usually I think one
should prefer to keep such things out of the code. I guess a shell
script would be better even, than using `add-to-load-path`.

However, this is only my opinion and I am myself not sure, whether that
is the best way.

I always use the -L argument when running tests, which are in a parallel
directory hierarchy to the source code. I specify a path that points to
a directory, which is (grand* …)parent of both, the tests directory and
the source code directory. Only then my tests have access to the modules
defined in the source code and can use `use-modules` as I described.

Regards,
Zelphir

On 3/6/20 5:29 PM, Михаил Бахтерев wrote:
> Thanks for the detailed answer.
>
> When i run
>
>   guile -L lib bin/check.scm
>
> everything works fine. No warnings.
>
> But my problem is that client wants just to unpack code archive to the
> random location and run it from there. Unfortunately, no GUIX, no custom
> builds. I don't understand what is the difference between -L option and
> add-to-load-path. It seems, that -L just adds lib directory to the
> %load-path, and that is it.
>
> May be it would be better to provide shell script, but i would like
> to solve this in pure Guile, if possible. May be, instead of
> adding-to-load-path, the better solution would be to reexecute Guile
> with appropriate -L options from simple trampoline .scm script?
>
> If i opt to this solution of reexecuting Guile, are there better and
> more robust choices than passing options through command line? Could the
> passing paths through environment variables be more reliable option?
>
> On Fri, Mar 06, 2020 at 12:53:37PM +0100, Zelphir Kaltstahl wrote:
>> Hi!
>>
>> I am not sure this will help you, but here is what I observed and what
>> works best for me:
>>
>>   * For running Guile programs use: `guile -L 
>> `.
>>   * For using libraries:
>>   o If Guile is installed via GUIX, try to install the library
>> through GUIX as well, then it should be available for Guile.
>>   o If Guile is installed via GUIX, but the library is not on GUIX
>> or not in the version you would like, create a directory
>> somewhere and set the Guile load path for that directory.
>>   o If Guile is built and installed by yourself also use Guile load
>> path.
>>   * Modules need to be named the same as the directories they are in to
>> be found:
>>   o To use (use-modules (some mymodule)) the module should be in a
>> directory `some` and a file `mymodule.scm`.
>>   o To use (use-modules (some)), the module should be in a file
>> named `some.scm`.
>>
>> Perhaps the Guile load path varies on different systems?
>>
>> Regards,
>> Zelphir
>>
>



Re: How to correctly load modules from runtime defineable locations?

2020-03-06 Thread Михаил Бахтерев
Thanks for the detailed answer.

When i run

  guile -L lib bin/check.scm

everything works fine. No warnings.

But my problem is that client wants just to unpack code archive to the
random location and run it from there. Unfortunately, no GUIX, no custom
builds. I don't understand what is the difference between -L option and
add-to-load-path. It seems, that -L just adds lib directory to the
%load-path, and that is it.

May be it would be better to provide shell script, but i would like
to solve this in pure Guile, if possible. May be, instead of
adding-to-load-path, the better solution would be to reexecute Guile
with appropriate -L options from simple trampoline .scm script?

If i opt to this solution of reexecuting Guile, are there better and
more robust choices than passing options through command line? Could the
passing paths through environment variables be more reliable option?

On Fri, Mar 06, 2020 at 12:53:37PM +0100, Zelphir Kaltstahl wrote:
> Hi!
> 
> I am not sure this will help you, but here is what I observed and what
> works best for me:
> 
>   * For running Guile programs use: `guile -L 
> `.
>   * For using libraries:
>   o If Guile is installed via GUIX, try to install the library
> through GUIX as well, then it should be available for Guile.
>   o If Guile is installed via GUIX, but the library is not on GUIX
> or not in the version you would like, create a directory
> somewhere and set the Guile load path for that directory.
>   o If Guile is built and installed by yourself also use Guile load
> path.
>   * Modules need to be named the same as the directories they are in to
> be found:
>   o To use (use-modules (some mymodule)) the module should be in a
> directory `some` and a file `mymodule.scm`.
>   o To use (use-modules (some)), the module should be in a file
> named `some.scm`.
> 
> Perhaps the Guile load path varies on different systems?
> 
> Regards,
> Zelphir
> 





Re: How to correctly load modules from runtime defineable locations?

2020-03-06 Thread Zelphir Kaltstahl
Hi!

I am not sure this will help you, but here is what I observed and what
works best for me:

  * For running Guile programs use: `guile -L 
`.
  * For using libraries:
  o If Guile is installed via GUIX, try to install the library
through GUIX as well, then it should be available for Guile.
  o If Guile is installed via GUIX, but the library is not on GUIX
or not in the version you would like, create a directory
somewhere and set the Guile load path for that directory.
  o If Guile is built and installed by yourself also use Guile load
path.
  * Modules need to be named the same as the directories they are in to
be found:
  o To use (use-modules (some mymodule)) the module should be in a
directory `some` and a file `mymodule.scm`.
  o To use (use-modules (some)), the module should be in a file
named `some.scm`.

Perhaps the Guile load path varies on different systems?

Regards,
Zelphir

On 06.03.20 06:22, Михаил Бахтерев wrote:
> Hello, Guile world.
>
> I have got the following issue, when trying to understand, how the
> Guiles modules system works.
>
> 1. I've wrote simple code
>
> ; check.scm
> (setlocale LC_ALL "")
>
> (let* ((fn (current-filename))   
>(dir (if (string? fn) (dirname fn) "."))  
>(lib (if (string? fn) (string-append (dirname dir) "/lib") "../lib")))
>   (add-to-load-path lib)    
>   (add-to-load-path dir))
>
> (display %load-path)
> (newline)
>
> (use-modules (json))
>
> (scm->json #("hello" "world"))
> (newline)
>
> 2. I have the following tree structure
>
> $ find
> .
> ./bin
> ./bin/check.scm
> ./lib
> ./lib/json
> ./lib/json/parser.scm
> ./lib/json/builder.scm
> ./lib/json.scm
>
> These json files are taken from https://github.com/aconchillo/guile-json
> intact.
>
> 3. I have Guile 2.2.6
>
> 4. In that environment i run
>
> $ guile bin/check.scm 
> ;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
> ;;;   or pass the --no-auto-compile argument to disable.
> ;;; compiling /tmp/news/bin/check.scm
> ;;; WARNING: compilation of /tmp/news/bin/check.scm failed:
> ;;; no code for module (json)
> ;;; compiling /tmp/news/lib/json.scm
> ;;; compiling /tmp/news/lib/json/builder.scm
> ;;; compiled 
> /home/mob/.cache/guile/ccache/2.2-LE-8-3.A/tmp/news/lib/json/builder.scm.go
> ;;; compiling /tmp/news/lib/json/parser.scm
> ;;; compiled 
> /home/mob/.cache/guile/ccache/2.2-LE-8-3.A/tmp/news/lib/json/parser.scm.go
> ;;; compiled 
> /home/mob/.cache/guile/ccache/2.2-LE-8-3.A/tmp/news/lib/json.scm.go
> (/tmp/news/bin /tmp/news/lib /usr/share/guile/2.2 /usr/share/guile/site/2.2 
> /usr/share/guile/site /usr/share/guile)
> ["hello","world"]
>
> My questions:
>
> 1. What does the message "no code for module" mean? It seems, that Guile
> can find the code and compile it.
>
> 2. Why does the program work in some distributives (Arch, Debian) and
> does not work in others (Ubuntu)? What is the difference, given the
> Guile versions are the same?
>
> 3. What am i doing wrong? My intent is to have some freedom in library
> placement, i do not want to use autoconf and automake for fixed paths.
> Is it possible to solve this task with `add-to-load-path` or should i
> use another technique?
>
> -- MB, respectfully, with many thanks in advance.
>


How to correctly load modules from runtime defineable locations?

2020-03-05 Thread Михаил Бахтерев
Hello, Guile world.

I have got the following issue, when trying to understand, how the
Guiles modules system works.

1. I've wrote simple code

; check.scm
(setlocale LC_ALL "")

(let* ((fn (current-filename))   
   (dir (if (string? fn) (dirname fn) "."))  
   (lib (if (string? fn) (string-append (dirname dir) "/lib") "../lib")))
  (add-to-load-path lib)
  (add-to-load-path dir))

(display %load-path)
(newline)

(use-modules (json))

(scm->json #("hello" "world"))
(newline)

2. I have the following tree structure

$ find
.
./bin
./bin/check.scm
./lib
./lib/json
./lib/json/parser.scm
./lib/json/builder.scm
./lib/json.scm

These json files are taken from https://github.com/aconchillo/guile-json
intact.

3. I have Guile 2.2.6

4. In that environment i run

$ guile bin/check.scm 
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;;   or pass the --no-auto-compile argument to disable.
;;; compiling /tmp/news/bin/check.scm
;;; WARNING: compilation of /tmp/news/bin/check.scm failed:
;;; no code for module (json)
;;; compiling /tmp/news/lib/json.scm
;;; compiling /tmp/news/lib/json/builder.scm
;;; compiled 
/home/mob/.cache/guile/ccache/2.2-LE-8-3.A/tmp/news/lib/json/builder.scm.go
;;; compiling /tmp/news/lib/json/parser.scm
;;; compiled 
/home/mob/.cache/guile/ccache/2.2-LE-8-3.A/tmp/news/lib/json/parser.scm.go
;;; compiled /home/mob/.cache/guile/ccache/2.2-LE-8-3.A/tmp/news/lib/json.scm.go
(/tmp/news/bin /tmp/news/lib /usr/share/guile/2.2 /usr/share/guile/site/2.2 
/usr/share/guile/site /usr/share/guile)
["hello","world"]

My questions:

1. What does the message "no code for module" mean? It seems, that Guile
can find the code and compile it.

2. Why does the program work in some distributives (Arch, Debian) and
does not work in others (Ubuntu)? What is the difference, given the
Guile versions are the same?

3. What am i doing wrong? My intent is to have some freedom in library
placement, i do not want to use autoconf and automake for fixed paths.
Is it possible to solve this task with `add-to-load-path` or should i
use another technique?

-- MB, respectfully, with many thanks in advance.



Re: How to use-modules within macro?

2019-09-04 Thread pelzflorian (Florian Pelz)
Thank you for giving my approach a kind of “trial by fire”.
Considering what you wrote, I still believe in my datum->syntax
approach in my special case.  After all, datum->syntax exists for a
reason, I suppose.  I am interested in your further comments.  They
have been very helpful.

On Wed, Sep 04, 2019 at 03:54:13PM -0400, Mark H Weaver wrote:
> If you could give me a birds-eye view of what you're trying to do here,
> I might be able to suggest other approaches.
> 

I am trying to i18n the Guix website by writing a gettext that accepts
s-expresions.

For example, the about page of Guix <https://guix.gnu.org/about/>
would use this SHTML:

  ;; TRANSLATORS: Features and Defining Packages are section names
  ;; in the English (en) manual.
  ,(G_
`(p
  "GNU Guix provides "
  ,(G_ (manual-href "state-of-the-art package management features"
(G_ "en")
(G_ "Features.html")))
  " such as transactional upgrades and roll-backs, reproducible
build environments, unprivileged package management, and
per-user profiles.  It uses low-level mechanisms from the "
  ,(G_ `(a (@ (href "https://nixos.org/nix/;)) "Nix"))
  " package manager, but packages are "
  ,(G_ (manual-href "defined" (G_ "en") (G_ "Defining-Packages.html")))
  " as native "
  ,(G_ `(a (@ (href ,(gnu-url "software/guile"))) "Guile"))
  " modules, using extensions to the "
  ,(G_ `(a (@ (href "http://schemers.org;)) "Scheme"))
  " language—which makes it nicely hackable."))


Another program I wrote converts it to a POT file from which I make
this German translation PO file:


#. TRANSLATORS: Features and Defining Packages are section names
#. in the English (en) manual.
#: apps/base/templates/about.scm:64
msgid ""
"GNU Guix provides <1>state-of-the-art package management "
"features<1.1>en<1.2>Features.html such as transactional "
"upgrades and roll-backs, reproducible\n"
"        build environments, unprivileged package management, and\n"
"per-user profiles.  It uses low-level mechanisms from the "
"<2>Nix package manager, but packages are "
"<3>defined<3.1>en<3.2>Defining-Packages.html as native "
"<4>Guile modules, using extensions to the <5>Scheme language—which "
"makes it nicely hackable."
msgstr ""
"GNU Guix bietet <1>Paketverwaltungsfunktionalitäten auf dem Stand der "
"Technik<1.1>de<1.2>Funktionalitaten.html, wie etwa "
"transaktionelle Aktualisierungen und Rücksetzungen, reproduzierbare "
"Erstellungsumgebungen, eine „unprivilegierte“ Paketverwaltung für Nutzer "
"ohne besondere Berechtigungen sowie ein eigenes Paketprofil für jeden "
"Nutzer. Dazu verwendet es dieselben Mechanismen, die dem "
"Paketverwaltungsprogramm <2>Nix zu Grunde liegen, jedoch werden Pakete "
"als reine <4>Guile-Module <3>definiert<3.1>de<3.2>Pakete-"
"definieren.html. Dazu erweitert Guix die <5>Scheme-"
"Programmiersprache, wodurch es leicht ist, selbst an diesen zu hacken."


Then the G_ macro takes apart the original SHTML and, using the
translation, reorders and recombines it automatically to this (I
manually added the indentation now):

(quasiquote
 (p "GNU Guix bietet "
(unquote
 (manual-href "Paketverwaltungsfunktionalitäten auf dem Stand der Technik"
  "de"
  ""
  "Funktionalitaten.html"
  ""))
", wie etwa transaktionelle Aktualisierungen und Rücksetzungen, 
reproduzierbare Erstellungsumgebungen, eine „unprivilegierte“ Paketverwaltung 
für Nutzer ohne besondere Berechtigungen sowie ein eigenes Paketprofil für 
jeden Nutzer. Dazu verwendet es dieselben Mechanismen, die dem 
Paketverwaltungsprogramm "
(unquote (quasiquote (a (@ (href "https://nixos.org/nix/;))
"Nix")))
" zu Grunde liegen, jedoch werden Pakete als reine "
(unquote (quasiquote (a (@ (href (unquote (gnu-url "software/guile"
"Guile")))
"-Module "
(unquote
 (manual-href "definiert"
  "de"
  ""
  "Pakete-definieren.html"
  ""))
". Dazu erweitert Guix die "
(unquote (quasiquote (a (@ (href "

Re: How to use-modules within macro?

2019-09-04 Thread Mark H Weaver
Hello again,

I wrote earlier:
> So, instead of using 'match' on the result of 'syntax->datum', you
> should instead use 'syntax-case' on the syntax object itself, like this
> (untested):
>
>   (let loop ((e #'exp))
> (syntax-case e ()
>   (num
>(number? (syntax->datum #'num))
>#'(1+ num))
>   ((x ...)
>(map loop #'(x ...)))
>   (y
>#'y)))

I should mention that the use of 'map' directly on a syntax object is
only allowable in certain cases.  Here, we assume that the syntax object
produced by #'(x ...) is a normal Scheme list.  That is _not_ the case
for arbitrary syntax objects that correspond to a list.  For example, it
would _not_ be safe to pass 'e' as the list argument to 'map', although
'e' is in some sense equivalent to #(x ...) in the second clause above.

The reason is that syntax objects contain information about the
associated lexical environment which starts at the top of the expression
tree, and is *lazily* pushed down into the subexpressions as the tree is
taken apart using 'syntax-case' and put back together using 'syntax'
(a.k.a. "#'").

As a result, there are only a few cases when you can safely assume that
the top structure of a syntax object is a normal list or pair, and they
are spelled out in the documentation for 'syntax' in the R6RS Standard
Libraries specification:

  http://www.r6rs.org/final/html/r6rs-lib/r6rs-lib-Z-H-13.html#node_sec_12.4

Here's the relevant excerpt:

  The output produced by syntax is wrapped or unwrapped according to the
  following rules.

  * the copy of ( . ) is a pair if  or  contain any
pattern variables,

  * the copy of ( ) is a list if  contains any pattern
variables,

  * the copy of #( ... ) is a vector if any of , ..., 
contain any pattern variables, and

  * the copy of any portion of  not containing any pattern variables
is a wrapped syntax object.

A "wrapped syntax object" is one where the lexical environment
information has not yet been pushed down into the subexpressions.  It is
a special kind of object that you can only take apart using
'syntax-case'.

So, in the clause above where 'map' is used, 'e' might be a "wrapped
syntax object", but when the elements are extracted from it using the
'syntax-case' pattern (x ...) and then put back together using
#'(x ...), you can then assume that the resulting syntax object is
a normal Scheme list of syntax objects, and therefore it is safe to
use 'map' on it.

   Mark



Re: How to use-modules within macro?

2019-09-04 Thread Mark H Weaver
Hi Florian,

"pelzflorian (Florian Pelz)"  writes:

> To retain unhygienic references, I am now using datum->syntax instead
> of local-eval.  It is much better.  For example, to make a macro that
> increments all numbers in a given program by one:
>
> (use-modules (ice-9 match))
> (define-syntax one-more
>   (lambda (x)
> (syntax-case x ()
>   ((_ exp)
>(datum->syntax
> #'exp
> (let loop ((y (syntax->datum #'exp)))
>   (match y
> ((? number?) (1+ y))
> ((? list?) (map loop y))
> (else y
>
> (let ((four 4))
>   (one-more (* 2 3 four)))
>
> Yields 48.  I hope this is the right approach for rewriting programs.

There are some problems above:

(1) The first argument to 'datum->syntax' must be an identifier, which
is the syntax object corresponding to a symbol.  Here, you are
passing an entire expression, and in the example usage above, #'exp
will be the syntax object corresponding to (* 2 3 hour).  Guile
should ideally raise an error in this case.

(2) The way you are doing things here destroys hygiene within the
expression that you are rewriting.  You convert the entire
expression with 'syntax->datum', process the datum, and then convert
the rewritten expression using 'datum->syntax'.  The problem here is
that 'syntax->datum' discards all of the extra information about
lexical environments of identifiers that were kept in the syntax
object.  This will cause severe problems when 'one-more' is used in
combination with other macros, including unintended variable
capture.

To do this properly, you must do the rewriting on the syntax objects
themselves.  It's okay to convert a syntax object to a datum to test
whether it's a literal number, but the important thing is that all
*identifiers* in the rewritten code should be preserved.

So, instead of using 'match' on the result of 'syntax->datum', you
should instead use 'syntax-case' on the syntax object itself, like this
(untested):

  (let loop ((e #'exp))
(syntax-case e ()
  (num
   (number? (syntax->datum #'num))
   #'(1+ num))
  ((x ...)
   (map loop #'(x ...)))
  (y
   #'y)))

Finally, I should mention that macro expansion is always done from the
outside in, meaning that when 'one-more' is expanded, its operand will
not yet have been expanded.  In general, this means that it's impossible
to comprehend the code within a macro's operands unless the parsing code
knows about every macro that might be used within the operands.  It's
not even possible to know which subparts are expressions and which are
other things like variable binding lists.

For this reason, I think it's generally a mistake to try to parse code
within a macro's operands.  It normally only makes sense for macros to
inspect the parts of operands that are considered part of the macro's
syntax.  For example, it makes sense for a 'let' macro to parse its
binding list, or for a 'match' macro to parse its patterns and
templates, but it does *not* make sense for a macro to try to parse
general subexpressions passed to the macro.

If you could give me a birds-eye view of what you're trying to do here,
I might be able to suggest other approaches.

   Best,
Mark



Re: How to use-modules within macro?

2019-09-04 Thread pelzflorian (Florian Pelz)
On Thu, Aug 29, 2019 at 07:04:07PM -0400, Mark H Weaver wrote:
> Hi Florian,
> 
> "pelzflorian (Florian Pelz)"  writes:
> 
> > I am writing a Guile macro to manipulate Scheme code and am stuck on
> > what I hope is a simple problem and it would be nice if you could
> > explain.  I try:
> >
> > (define-syntax O
> >   (lambda (x)
> > (syntax-case x ()
> >   ((_)
> >#`(begin (use-modules (ice-9 local-eval))
> > (local-eval 42 (the-environment)))
> > (pk (O))
> 
> This approach is misguided and unnecessary.  You don't need to include
> 'use-modules' in your macro expansion, and it's best avoided.
> 
> […]

Your explanation helped a lot.

To retain unhygienic references, I am now using datum->syntax instead
of local-eval.  It is much better.  For example, to make a macro that
increments all numbers in a given program by one:

(use-modules (ice-9 match))
(define-syntax one-more
  (lambda (x)
(syntax-case x ()
  ((_ exp)
   (datum->syntax
#'exp
(let loop ((y (syntax->datum #'exp)))
  (match y
((? number?) (1+ y))
((? list?) (map loop y))
(else y

(let ((four 4))
  (one-more (* 2 3 four)))

Yields 48.  I hope this is the right approach for rewriting programs.

Regards,
Florian



Re: How to use-modules within macro?

2019-08-30 Thread pelzflorian (Florian Pelz)
On Thu, Aug 29, 2019 at 07:04:07PM -0400, Mark H Weaver wrote:
> This approach is misguided and unnecessary.  You don't need to include
> 'use-modules' in your macro expansion, and it's best avoided.
> 

:) I suspected I was doing something very wrong.



> FYI, the way this works internally is that the macro expander operates
> on "syntax objects" instead of plain S-expressions.  The main difference
> is that "syntax objects" keep additional information about the lexical
> environments where the embedded identifiers were originally found.  So
> when a use of (O) expands into (local-eval 42 (the-environment)), the
> identifiers 'local-eval' and 'the-environment' are looked up in the
> proper environment.
>

I had read but not understood that syntax carries references, but of
course it does because of hygiene.  Thank you!



> By the way, another consequence of hygiene, which you probably don't
> want here, is that the (the-environment) above will capture the lexical
> environment where 'O' was *defined*, instead of the environment where
> (O) is used.  In other words, in (let ((x 5)) (O)), the captured lexical
> environment will not include 'x'.
> 
> I should also mention that using (the-environment) will pretty much
> disable most compiler optimizations that would otherwise occur with that
> top-level form.  That entire mechanism is best avoided if at all
> possible.
> 
> Can you tell me more broadly what you are trying to accomplish here?
> I may be able to suggest an alternate approach.
> 
>  Best,
>   Mark


What I am actually trying to do is rewriting S-expressions based on a
translated gettext MO file for localization.  I have a gettext POT
file which contains:

#: apps/packages/templates/components.scm:104$
msgid " issue"
msgid_plural " issues"
msgstr[0] ""
msgstr[1] ""



(define (sngettext x)
  "After choosing an identifier for behavior similar to ngettext:1,2,
make it usable like (define-syntax N_ sngettext).  sngettext takes
into account that not all languages have only singular and plural
forms."
  (syntax-case x ()
((_ msgid1 msgid2 n) ;three sexps
 ;; sexp->msgid computes a gettext msgid for lookup with gettext
 (let* ((msgstr1 (sexp->msgid (syntax->datum #'msgid1)))
(msgstr2 (sexp->msgid (syntax->datum #'msgid2
   #`(begin
   (use-modules (ice-9 local-eval))
   (local-eval (let ((applicable (if (= #'n 1) #'msgid1 #'msgid2)))
 ;; deconstruct builds a new sexp from either
 ;; msgid1 or msgid2 and the translation from
 ;; the gettext MO file, i.e. it deconstructs
 ;; the translation to an sexp.
 (deconstruct (syntax->datum applicable)
  (ngettext #,msgstr1 #,msgstr2 n)))
   (the-environment)))


The first argument of sexp->msgid and deconstruct must be the msgid,
which can be a complicated nested sexp.  Macros must not have been
expanded there.  For ngettext, it is important that the n s-expression
be evaluated by ngettext in the evaluation phase and not at expansion
time.

The corresponding sgettext works fine with deconstruct moved to macro
expansion time, therefore there is no need for local-eval.  Moving
deconstruct to macro expansion time would mean I would need to
deconstruct all singular, plural etc. forms, because I do not yet know
the value of n.  I could do this by evaluating the Plural-Forms line
from the MO file, I just wanted to avoid this and let ngettext do the
work.


Thank you!!  I now understand macros better.

Regards,
Florian



Re: How to use-modules within macro?

2019-08-29 Thread Mark H Weaver
Hi Florian,

"pelzflorian (Florian Pelz)"  writes:

> I am writing a Guile macro to manipulate Scheme code and am stuck on
> what I hope is a simple problem and it would be nice if you could
> explain.  I try:
>
> (define-syntax O
>   (lambda (x)
> (syntax-case x ()
>   ((_)
>#`(begin (use-modules (ice-9 local-eval))
> (local-eval 42 (the-environment)))
> (pk (O))

This approach is misguided and unnecessary.  You don't need to include
'use-modules' in your macro expansion, and it's best avoided.

The references to 'local-eval' and 'the-environment' in the macro
template above will refer to bindings present in the module where 'O' is
defined, *not* the module where 'O' is used.  This is part of what it
means to say that 'O' is a "hygienic" macro.

Therefore, all you need to do is make sure (ice-9 local-eval) is
imported in the module where 'O' is defined, like this:

--8<---cut here---start->8---
(define-module (my-module-that-exports-O)
  #:use-module (ice-9 local-eval)
  #:export (O))

(define-syntax O
  (lambda (x)
(syntax-case x ()
  ((_)
   #`(local-eval 42 (the-environment))
--8<---cut here---end--->8---

Does that work for you?

FYI, the way this works internally is that the macro expander operates
on "syntax objects" instead of plain S-expressions.  The main difference
is that "syntax objects" keep additional information about the lexical
environments where the embedded identifiers were originally found.  So
when a use of (O) expands into (local-eval 42 (the-environment)), the
identifiers 'local-eval' and 'the-environment' are looked up in the
proper environment.

By the way, another consequence of hygiene, which you probably don't
want here, is that the (the-environment) above will capture the lexical
environment where 'O' was *defined*, instead of the environment where
(O) is used.  In other words, in (let ((x 5)) (O)), the captured lexical
environment will not include 'x'.

I should also mention that using (the-environment) will pretty much
disable most compiler optimizations that would otherwise occur with that
top-level form.  That entire mechanism is best avoided if at all
possible.

Can you tell me more broadly what you are trying to accomplish here?
I may be able to suggest an alternate approach.

 Best,
  Mark



How to use-modules within macro?

2019-08-29 Thread pelzflorian (Florian Pelz)
Hello,

I am writing a Guile macro to manipulate Scheme code and am stuck on
what I hope is a simple problem and it would be nice if you could
explain.  I try:

(define-syntax O
  (lambda (x)
(syntax-case x ()
  ((_)
   #`(begin (use-modules (ice-9 local-eval))
(local-eval 42 (the-environment)))
(pk (O))

But it does not work; it cannot resolve local-eval and
the-environment.  Why?  When I write it in the interpreter, a second
call to (pk (O)) works and prints 42.

Using (@ (ice-9 local-eval) …) does not work for looking up
the-environment.

Regards,
Florian



Re: Streaming responses with Guile's web modules

2018-09-23 Thread Ludovic Courtès
Hi Roel,

Roel Janssen  skribis:

> I'd like to implement a web server using the (web server) module, but
> allow for “streaming” results.  The way I image this would look like,
> is something like this:
>
> (define (request-handler request body)
>   (values '((content-type . (text/plain)))
>   ;; This function can build its response by writing to
>   ;; ‘port’, rather than to return the whole body as a
>   ;; string.
>   (lambda (port)
> (format port "Hello world!"
>
> (run-server request-handler)
>
> Is this possible with the (web server) module?  If so, how?
> If not, what would be a good starting point to implement this?

As discussed on IRC a few days ago, this is not really possible.  ‘guix
publish’ works around it by providing a custom implementation of the
‘write’ method of the HTTP server and having handlers provide a “fake”
body to be interpreted by this ‘write’ implementation:

  https://git.savannah.gnu.org/cgit/guix.git/tree/guix/scripts/publish.scm#n690
  https://git.savannah.gnu.org/cgit/guix.git/tree/guix/scripts/publish.scm#n522

I reported this limitation of (web server) at
.

Thanks,
Ludo’.




Re: Streaming responses with Guile's web modules

2018-09-22 Thread Roel Janssen


Roel Janssen  writes:

> Amirouche Boubekki  writes:
>
>> On 2018-09-18 21:42, Roel Janssen wrote:
>>> Dear Guilers,
>>>
>>> I'd like to implement a web server using the (web server) module, but
>>> allow for “streaming” results.  The way I imagine this would look like,
>>> is something like this:
>>>
>>> (define (request-handler request body)
>>>   (values '((content-type . (text/plain)))
>>>   ;; This function can build its response by writing to
>>>   ;; ‘port’, rather than to return the whole body as a
>>>   ;; string.
>>>   (lambda (port)
>>> (format port "Hello world!"
>>>
>>> (run-server request-handler)
>>>
>>> Is this possible with the (web server) module?  If so, how?
>>
>> What you describe is exactly how it works. The second value can
>> be a bytevector, #f or a procedure that takes a port as argument.
>>
>> Here is an example use [0] and here is the code [1]
>>
>> [0]
>> https://framagit.org/a-guile-mind/culturia.next/blob/master/culturia/web/helpers.scm#L34
>> [1]
>> https://git.savannah.gnu.org/cgit/guile.git/tree/module/web/server.scm#n198
>>
>> Regards
>
> Thanks for your quick and elaborate reply!  I didn't realize that in
> writing the example I had written a working example.
>
> Looking at memory usage, it looks as if it puts all bytes produced by
> that function into memory at once before sending the HTTP response over
> the network.  Is that observation correct?  If so, can it be avoided?

I implemented a proof-of-concept "chunked" transfer that does not
consume too much memory.  It's hacky because it (mis)uses a bytevector to
pass the input-port for a file to the new 'http-write' function.  It
also ignores any header field set when serving the large response.

The next (and hopefully final) question: Can I combine this with
'run-server' from Fibers?

Here's the code:

--8<---cut here---start->8---
(use-modules (web server)
 (web request)
 (web response)
 (web http)
 (web uri)
 (ice-9 format)
 (ice-9 match)
 (ice-9 receive)
 (ice-9 rdelim)
 (ice-9 iconv)
 (ice-9 binary-ports)
 (rnrs bytevectors))

(define original-http-write
  (@@ (web server http) http-write))

(define (write-buffer-to-client client input-port buffer-size)
  (let* ((buffer (get-bytevector-n input-port buffer-size))
 (buffer-length (if (eof-object? buffer) 0 (bytevector-length buffer)))
 (end (string->utf8 "\r\n")))
(when (> buffer-length 0)
  (put-bytevector client (string->utf8 (format #f "~x\r\n" buffer-length)))
  (put-bytevector client buffer)
  (put-bytevector client end)
  (force-output client))
(when (= buffer-length buffer-size)
  (write-buffer-to-client client input-port buffer-size

(define (new-http-write server client response body)
  "Allow sending raw HTTP so we can serve large responses with little memory."
  (match (response-transfer-encoding response)
[('(chunked) . _)
 (let ((input-port (fdes->inport (string->number (utf8->string body
   (buffer-size (expt 2 13)))
   (setvbuf input-port 'block buffer-size)
   (setvbuf client 'block (+ buffer-size 6))

   ;; Write the HTTP header.
   (for-each (lambda (line) (put-bytevector client (string->utf8 line)))
 '("HTTP/1.1 200 OK\r\n"
   "Content-Type: text/html;charset=utf-8\r\n"
   "Transfer-Encoding: chunked\r\n"
   "Connection: close\r\n\r\n"))

   ;; Write the file contents.
   (write-buffer-to-client client input-port buffer-size)

   ;; End the stream.
   (put-bytevector client (string->utf8 "0\r\n\r\n"))
   (close-port client))]
   [_ (original-http-write server client response body)]))

(define-server-impl concurrent-http-server
  (@@ (web server http) http-open)
  (@@ (web server http) http-read)
  new-http-write
  (@@ (web server http) http-close))

(define (process-input input-port output-port)
  (unless (or (port-closed? input-port)
  (port-closed? output-port))
(let ((line (read-line input-port)))
  (if (eof-object? line)
  (begin
(close-port input-port)
#t)
  (begin
(put-bytevector output-port (string->bytevector line "UTF-8"))
(force-output output-port)
(process-input input-port output-port))

(define (request-handler request body)
  (if (string-prefix? &q

Re: Streaming responses with Guile's web modules

2018-09-19 Thread Roel Janssen


Roel Janssen  writes:

> Amirouche Boubekki  writes:
>
>> On 2018-09-18 21:42, Roel Janssen wrote:
>>> Dear Guilers,
>>>
>>> I'd like to implement a web server using the (web server) module, but
>>> allow for “streaming” results.  The way I imagine this would look like,
>>> is something like this:
>>>
>>> (define (request-handler request body)
>>>   (values '((content-type . (text/plain)))
>>>   ;; This function can build its response by writing to
>>>   ;; ‘port’, rather than to return the whole body as a
>>>   ;; string.
>>>   (lambda (port)
>>> (format port "Hello world!"
>>>
>>> (run-server request-handler)
>>>
>>> Is this possible with the (web server) module?  If so, how?
>>
>> What you describe is exactly how it works. The second value can
>> be a bytevector, #f or a procedure that takes a port as argument.
>>
>> Here is an example use [0] and here is the code [1]
>>
>> [0]
>> https://framagit.org/a-guile-mind/culturia.next/blob/master/culturia/web/helpers.scm#L34
>> [1]
>> https://git.savannah.gnu.org/cgit/guile.git/tree/module/web/server.scm#n198
>>
>> Regards
>
> Thanks for your quick and elaborate reply!  I didn't realize that in
> writing the example I had written a working example.
>
> Looking at memory usage, it looks as if it puts all bytes produced by
> that function into memory at once before sending the HTTP response over
> the network.  Is that observation correct?  If so, can it be avoided?

As an addition to the above, here's an example implementation:

(use-modules (web server)
 (web request)
 (web response)
 (web http)
 (ice-9 receive)
 (ice-9 rdelim))

(define (process-input input-port output-port)
  (unless (or (port-closed? input-port)
  (port-closed? output-port))
(let ((line (read-line input-port)))
  (if (eof-object? line)
  (begin
(close-port input-port)
#t)
  (begin
(format output-port "~a~%" line)
(process-input input-port output-port))

(define (request-handler request body)
  (values '((content-type  . (text/plain))
(transfer-encoding . ((chunked
  (lambda (port)
(call-with-input-file "large-file.txt"
  (lambda (input-port) (process-input input-port port))

(run-server request-handler)


In the example, “large-file.txt” is a file of a few gigabytes, and the
Guile process grows to a few gigabytes as well.

Kind regards,
Roel Janssen



Re: Streaming responses with Guile's web modules

2018-09-19 Thread Roel Janssen


Amirouche Boubekki  writes:

> On 2018-09-18 21:42, Roel Janssen wrote:
>> Dear Guilers,
>>
>> I'd like to implement a web server using the (web server) module, but
>> allow for “streaming” results.  The way I imagine this would look like,
>> is something like this:
>>
>> (define (request-handler request body)
>>   (values '((content-type . (text/plain)))
>>   ;; This function can build its response by writing to
>>   ;; ‘port’, rather than to return the whole body as a
>>   ;; string.
>>   (lambda (port)
>> (format port "Hello world!"
>>
>> (run-server request-handler)
>>
>> Is this possible with the (web server) module?  If so, how?
>
> What you describe is exactly how it works. The second value can
> be a bytevector, #f or a procedure that takes a port as argument.
>
> Here is an example use [0] and here is the code [1]
>
> [0]
> https://framagit.org/a-guile-mind/culturia.next/blob/master/culturia/web/helpers.scm#L34
> [1]
> https://git.savannah.gnu.org/cgit/guile.git/tree/module/web/server.scm#n198
>
> Regards

Thanks for your quick and elaborate reply!  I didn't realize that in
writing the example I had written a working example.

Looking at memory usage, it looks as if it puts all bytes produced by
that function into memory at once before sending the HTTP response over
the network.  Is that observation correct?  If so, can it be avoided?

Kind regards,
Roel Janssen



Re: Streaming responses with Guile's web modules

2018-09-18 Thread Amirouche Boubekki

On 2018-09-18 21:42, Roel Janssen wrote:

Dear Guilers,

I'd like to implement a web server using the (web server) module, but
allow for “streaming” results.  The way I imagine this would look like,
is something like this:

(define (request-handler request body)
  (values '((content-type . (text/plain)))
  ;; This function can build its response by writing to
  ;; ‘port’, rather than to return the whole body as a
  ;; string.
  (lambda (port)
(format port "Hello world!"

(run-server request-handler)

Is this possible with the (web server) module?  If so, how?


What you describe is exactly how it works. The second value can
be a bytevector, #f or a procedure that takes a port as argument.

Here is an example use [0] and here is the code [1]

[0] 
https://framagit.org/a-guile-mind/culturia.next/blob/master/culturia/web/helpers.scm#L34
[1] 
https://git.savannah.gnu.org/cgit/guile.git/tree/module/web/server.scm#n198


Regards

--
Amirouche ~ amz3 ~ http://www.hyperdev.fr



Streaming responses with Guile's web modules

2018-09-18 Thread Roel Janssen
Dear Guilers,

I'd like to implement a web server using the (web server) module, but
allow for “streaming” results.  The way I image this would look like,
is something like this:

(define (request-handler request body)
  (values '((content-type . (text/plain)))
  ;; This function can build its response by writing to
  ;; ‘port’, rather than to return the whole body as a
  ;; string.
  (lambda (port)
(format port "Hello world!"

(run-server request-handler)

Is this possible with the (web server) module?  If so, how?
If not, what would be a good starting point to implement this?

Kind regards,
Roel Janssen



Re: Lightweight web modules for Guile?

2018-07-14 Thread Tonton
Hey!

Sorry about the long response time, lost myself for a while. :-)

Thanks a lot for the thorough walkthrough Amirouche!

I've not had time to continue the web project recently, but look very much
forward to continue exploring both artanis and the web-projects/helpers
mentioned in these threads. Especially the web-app project of tantalum.

Again, thanks.
:-)

On Sun, 01 Jul 2018 13:15:13 +0200
Amirouche Boubekki  wrote:

> On 2018-06-29 03:29, Tonton wrote:
> > Hey, I'm wanting to write a web page using guile, I'll need a module 
> > that can
> > help me with the web part. I like haunt, but I'll need a few dynamic
> > elements[1]. So I've been looking at and trying artanis. It is 
> > potentially
> > awesome and does a lot of things I'm not familiar with - and I have yet 
> > to
> > make it work. (I just sent a request for aid to the artanis list)
> > 
> > Are there other libraries or modules that eases web development? 
> > Anything
> > between artanis and "plain" guile?  
> 
> The sad story is that there is no such thing as "plain" guile for doing
> webdev. I think I have done a fair amount of work around webdev without
> resorting to Artanis. The last of them is called 'presence'. It's wip 
> stalled
> dynamic blog engine. It stalled because I have a bug in the frontend for 
> which
> I use biwascheme. So, it's a REST API with, so called, Single Page 
> Application
> written fully in Scheme [0]
> 
> I forked that project and got rid of the parts that are still (!) 
> controversial,
> that is my database with, so called, minikanren querying and the 
> biwascheme part.
> And made a git repository called guile-web [1]. If you want, it's 
> backend framework
> for webdev, let's call it that. In reality it's no more that thin 
> helpers on top
> of 'plain' guile, an opinionated choice.
> 
> So here is what it bundles:
> 
> - sha2 + hmac for cryptographically signing cookies, copied from scheme 
> industria
> 
> - argon2 bindings a new breed of memory & cpu strong [2] for hashing 
> passwords [3]
>I translated how Python Django use that very same library. AFAIK there 
> is no
>argon2 package in guix, yet...
> 
> - The entry point of the server is web:main but the interesting stuff is 
> in
>the handler [4]. Which is basically the equivalent of the router. It's 
> simply
>takes guile REQUEST and a BODY. Yes it's plain Guile. And dispatch 
> based
>on request method and request path like any good backend router
>using ice-9 match. It doesn't support regex, but who cares?! It 
> doesn't
>support reversing url through a string indirection because it's an 
> antipattern.
>Let's argue about that last point: The arguments about named routes 
> are:
> 
>  a) It allows to rework the url path later _without changing the name 
> route_.
> If the path change is very likely that the logic of the path 
> changed, otherwise
> why would you change the path in the first place? A slim chance 
> you made a
> mistake and the original design. That's why you should give a 
> fair amount
> of thought when design the request path routes but not too much! 
> What I mean
> by that is that path are at the end of the day a detail. Not much 
> endusers
> take advantage of it. Let's now, imagine I made a mistake 
> (unlikely!) but
> I want to rework my routes and will leave the name of the route 
> unchanged
> EVEN IF the logic behind changed? That would mean leaving some 
> debt behind
> in the code, but it's ok because it's just a string (or a 
> symbol). Very poor
> pratice, when you rework/refactor a codebase you should leave it 
> better the
> best you can, especially if it's easy to do! In this case, you 
> have to retype
> all (yes all the path!) that changed in the codebase. Nobody said 
> it is not
> boring dull code. That's coding is, some fun, some boring stuff.
> 
>  b) It makes possible to reverse urls with a simple
> 
>   (router-reverse 'name-of-the-route path-parameter-one 
> path-parameter-two)
> 
> This. is. boilerplate. code. Very useless abstraction. Because 
> the alternative
> is much simpler and lower the call stack depth and "complexity", 
> which will
> ease reading the code. Behold the alternative to the above 
> snipped:
> 
>   (string-append "/name/of/the/route/" path-paramater-one "/" 
> path-paramater-two)
> 
> Simple clean and newbie friendly. No need to abstract that path 
> are made of
> str

Re: Lightweight web modules for Guile?

2018-07-01 Thread Arne Babenhauserheide

Amirouche Boubekki  writes:
> What is missing is handling multipart mime type form encoded
> stuff. That means
> you can not handle form submission and uploads, yet. Patch very
> welcome.

I cannot help you with that code directly, but I did write a small
multifile form upload script for Guile. Maybe you can adapt the code for
your needs:

https://bitbucket.org/ArneBab/wisp/src/7501dc0db3f8cebf49b48634719ab82b4a509a79/examples/upload-server.w

parsed to plain Scheme:

https://bitbucket.org/ArneBab/wisp/src/db4210a0af51c654cd196b9d500234b2a33eaec3/examples/upload-server.scm

This simply grabs every file that was uploaded into the form and saves
it in a local folder. It is not secured against malicious users, because
I built it for "internal" use (means: as 3h hack for use at home to
transfer files from really "dumb" devices that only provide a webbrowser
to another computer).

> Happy hacking!

Happy Hacking to you, too!

- Arne

--
Unpolitisch sein
heißt politisch sein
ohne es zu merken


signature.asc
Description: PGP signature


Re: Lightweight web modules for Guile?

2018-07-01 Thread Amirouche Boubekki

On 2018-06-29 03:29, Tonton wrote:
Hey, I'm wanting to write a web page using guile, I'll need a module 
that can

help me with the web part. I like haunt, but I'll need a few dynamic
elements[1]. So I've been looking at and trying artanis. It is 
potentially
awesome and does a lot of things I'm not familiar with - and I have yet 
to

make it work. (I just sent a request for aid to the artanis list)

Are there other libraries or modules that eases web development? 
Anything

between artanis and "plain" guile?


The sad story is that there is no such thing as "plain" guile for doing
webdev. I think I have done a fair amount of work around webdev without
resorting to Artanis. The last of them is called 'presence'. It's wip 
stalled
dynamic blog engine. It stalled because I have a bug in the frontend for 
which
I use biwascheme. So, it's a REST API with, so called, Single Page 
Application

written fully in Scheme [0]

I forked that project and got rid of the parts that are still (!) 
controversial,
that is my database with, so called, minikanren querying and the 
biwascheme part.
And made a git repository called guile-web [1]. If you want, it's 
backend framework
for webdev, let's call it that. In reality it's no more that thin 
helpers on top

of 'plain' guile, an opinionated choice.

So here is what it bundles:

- sha2 + hmac for cryptographically signing cookies, copied from scheme 
industria


- argon2 bindings a new breed of memory & cpu strong [2] for hashing 
passwords [3]
  I translated how Python Django use that very same library. AFAIK there 
is no

  argon2 package in guix, yet...

- The entry point of the server is web:main but the interesting stuff is 
in
  the handler [4]. Which is basically the equivalent of the router. It's 
simply
  takes guile REQUEST and a BODY. Yes it's plain Guile. And dispatch 
based

  on request method and request path like any good backend router
  using ice-9 match. It doesn't support regex, but who cares?! It 
doesn't
  support reversing url through a string indirection because it's an 
antipattern.
  Let's argue about that last point: The arguments about named routes 
are:


a) It allows to rework the url path later _without changing the name 
route_.
   If the path change is very likely that the logic of the path 
changed, otherwise
   why would you change the path in the first place? A slim chance 
you made a
   mistake and the original design. That's why you should give a 
fair amount
   of thought when design the request path routes but not too much! 
What I mean
   by that is that path are at the end of the day a detail. Not much 
endusers
   take advantage of it. Let's now, imagine I made a mistake 
(unlikely!) but
   I want to rework my routes and will leave the name of the route 
unchanged
   EVEN IF the logic behind changed? That would mean leaving some 
debt behind
   in the code, but it's ok because it's just a string (or a 
symbol). Very poor
   pratice, when you rework/refactor a codebase you should leave it 
better the
   best you can, especially if it's easy to do! In this case, you 
have to retype
   all (yes all the path!) that changed in the codebase. Nobody said 
it is not

   boring dull code. That's coding is, some fun, some boring stuff.

b) It makes possible to reverse urls with a simple

 (router-reverse 'name-of-the-route path-parameter-one 
path-parameter-two)


   This. is. boilerplate. code. Very useless abstraction. Because 
the alternative
   is much simpler and lower the call stack depth and "complexity", 
which will
   ease reading the code. Behold the alternative to the above 
snipped:


 (string-append "/name/of/the/route/" path-paramater-one "/" 
path-paramater-two)


   Simple clean and newbie friendly. No need to abstract that path 
are made of

   strings with more strings!

   A Python dev, might tell you:

 "I know better, I know object hierarchy <-> request path router. 
It's magiq!"


  I am a Python. Gone there, Seen that. It's a pain. It's the of coding 
that some
  part of the code are dull and not 'funky' not algorithm heavy and dull 
easy.

  Rejoice about that, that's more time to think about interesting stuff!

- The router calls controllers with whatever they need as argument 
REQUEST
  or BODY depending on the case. In guile-web, I inlined that code in 
the

  handler aka. router:

(render-html (template "index" "Héllo Guilers"))

  Template is the base template procedure, that will return the sxml 
shell, and in
  this case will return the "index" as body class and "Héllo Guilers" as 

  content. render-html will translate that sxml to a plain guile 
response. SXML
  is awesome. Look at it closely. How much more complicated it can 
become than
  that! Look at Python mixt or JavaScript JSX or wors

Re: Lightweight web modules for Guile?

2018-06-30 Thread Amirouche Boubekki

On 2018-06-29 23:21, Tonton wrote:

Hey.pp project looks more like what I'd like. I'll probably packa

Thank you both tantalum and Zelphir!

I'm not entirely sure what I need myself to be honest, this is very 
much a

learning exercise; even though I have a goal to use it. That said, the
web-app project looks more like what I'd like. I'll probably package it 
for

guix also, if I use it.


Let me know how it works




On Fri, 29 Jun 2018 18:42:15 +
tantalum  wrote:


hi, not sure if it is exactly what your looking for but it might be
useful for examples and matches the general question.
i maintain a project named "web-app" at http://sph.mn/c/view/mu or
https://github.com/sph-mn/sph-web-app
the core is small and working well for me so far, ive been maintaining
it for a long time. it starts a server and for each request gives a
request object to a user defined procedure, which then returns a
response object that is send back to the client.
it comes with an optional module for file processing (templates,
preprocessed files, bundling, etc) and has some more cool features 
like
protocol independence (socket -> app -> socket), an exchangeable 
server

(fibers included) and derived projects (using modules and symlinks).

the project hasnt gone through testing and feedback loops with other
users, and the documentation, while technically probably up to date,
needs revision i think. here is a minimal usage example, in a file 
named

"example.scm":

 (import (sph web app) (sph web app http))
 (define (app-respond request) (respond "test"))
 (define app (swa-create (quote project-name) app-respond))
 (swa-start app #f swa-server-guile)

then running "guile example.scm" displays

 listening on 127.0.0.1:6500
 exit with ctrl+c

the app is then accessible with the browser at http://127.0.0.1:6500


--
Amirouche ~ amz3 ~ http://www.hyperdev.fr



Re: Lightweight web modules for Guile?

2018-06-29 Thread Tonton
Hey.

Thank you both tantalum and Zelphir!

I'm not entirely sure what I need myself to be honest, this is very much a
learning exercise; even though I have a goal to use it. That said, the
web-app project looks more like what I'd like. I'll probably package it for
guix also, if I use it.

On Fri, 29 Jun 2018 18:42:15 +
tantalum  wrote:

> hi, not sure if it is exactly what your looking for but it might be 
> useful for examples and matches the general question.
> i maintain a project named "web-app" at http://sph.mn/c/view/mu or 
> https://github.com/sph-mn/sph-web-app
> the core is small and working well for me so far, ive been maintaining 
> it for a long time. it starts a server and for each request gives a 
> request object to a user defined procedure, which then returns a 
> response object that is send back to the client.
> it comes with an optional module for file processing (templates, 
> preprocessed files, bundling, etc) and has some more cool features like 
> protocol independence (socket -> app -> socket), an exchangeable server 
> (fibers included) and derived projects (using modules and symlinks).
> 
> the project hasnt gone through testing and feedback loops with other 
> users, and the documentation, while technically probably up to date, 
> needs revision i think. here is a minimal usage example, in a file named 
> "example.scm":
> 
>  (import (sph web app) (sph web app http))
>  (define (app-respond request) (respond "test"))
>  (define app (swa-create (quote project-name) app-respond))
>  (swa-start app #f swa-server-guile)
> 
> then running "guile example.scm" displays
> 
>  listening on 127.0.0.1:6500
>  exit with ctrl+c
> 
> the app is then accessible with the browser at http://127.0.0.1:6500


pgpz5epRIMCFT.pgp
Description: OpenPGP digital signature


Re: Lightweight web modules for Guile?

2018-06-29 Thread tantalum
hi, not sure if it is exactly what your looking for but it might be 
useful for examples and matches the general question.
i maintain a project named "web-app" at http://sph.mn/c/view/mu or 
https://github.com/sph-mn/sph-web-app
the core is small and working well for me so far, ive been maintaining 
it for a long time. it starts a server and for each request gives a 
request object to a user defined procedure, which then returns a 
response object that is send back to the client.
it comes with an optional module for file processing (templates, 
preprocessed files, bundling, etc) and has some more cool features like 
protocol independence (socket -> app -> socket), an exchangeable server 
(fibers included) and derived projects (using modules and symlinks).


the project hasnt gone through testing and feedback loops with other 
users, and the documentation, while technically probably up to date, 
needs revision i think. here is a minimal usage example, in a file named 
"example.scm":


(import (sph web app) (sph web app http))
(define (app-respond request) (respond "test"))
(define app (swa-create (quote project-name) app-respond))
(swa-start app #f swa-server-guile)

then running "guile example.scm" displays

listening on 127.0.0.1:6500
exit with ctrl+c

the app is then accessible with the browser at http://127.0.0.1:6500



Lightweight web modules for Guile?

2018-06-29 Thread Tonton
Hey, I'm wanting to write a web page using guile, I'll need a module that can
help me with the web part. I like haunt, but I'll need a few dynamic
elements[1]. So I've been looking at and trying artanis. It is potentially
awesome and does a lot of things I'm not familiar with - and I have yet to
make it work. (I just sent a request for aid to the artanis list)

Are there other libraries or modules that eases web development? Anything
between artanis and "plain" guile?


(Another possibility I entertained is to use haunt and have the dynamic
elements be a separate html page populated by a separate process on the
server. The page would then only be linked to from the rest of the pages and
would hardcode paths for css and the rest. Not a very good solution, but
maybe the simplest right now.)


[1]: I need to embed messages from a pump.io account on the index page.
I would also like to try integrating with one or two other web
applications.

Tonton
:-)

-- 
I use gpg to sign my emails. All the symbols you may see at the bottom
of this mail is my cryptographic signature. It can be ignored, or used
to check that it really is me sending this email. Learn more by asking
me or see: https://u.fsf.org/zb or https://ssd.eff.org/


pgpZJyWXRIPBK.pgp
Description: OpenPGP digital signature


Re: Trouble trying to use some modules from the docs

2018-06-16 Thread Zelphir Kaltstahl
On 16.06.2018 18:00, guile-user-requ...@gnu.org wrote:
> Message: 3
> Date: Sat, 16 Jun 2018 06:36:46 -0700
> From: Matt Wette 
> To: guile-user@gnu.org
> Subject: Re: Trouble trying to use some modules from the docs (Matt
>   Wette)
> Message-ID: 
> Content-Type: text/plain; charset=utf-8; format=flowed
>
>
> On 06/16/2018 02:35 AM, Zelphir Kaltstahl wrote:
>> Hello,
>>
>> I have managed to get another case of a binding not being available
>> according to the Guile REPL, this time I have the code and way to
>> reproduce the issue.
>> ;; ===== HELPERS MODULE (networking-lib/helpers.scm) =
>> (use-modules (rnrs bytevectors))
>>
>> (define-module (networking-lib helpers)
>>  ? #:export (display-byte-vector))
>>
> With above code, bytevector import is NOT in the context of your 
> module.? Try
>
> (define-module (networking-lib helpers)
>  ? #:export (display-byte-vector))
>
> (use-modules (rnrs bytevectors))
>
>
> OR
>
>
> (define-module (networking-lib helpers)
>  ? #:export (display-byte-vector)
>  ? #:use-module (rnrs bytevectors))
Thank you Matt, that worked.
Somehow I assumed, that it would "magically" make the used modules also
available in the code, which uses the helpers module.
Now I can have less/no code duplication : )

I have now changed the code and I have it here:
https://gitlab.com/zelphir-kaltstahl-projects/guile-scheme-tutorials-and-examples/tree/dev/network-programming



Re: Trouble trying to use some modules from the docs (Matt Wette)

2018-06-16 Thread Matt Wette



On 06/16/2018 02:35 AM, Zelphir Kaltstahl wrote:

Hello,

I have managed to get another case of a binding not being available
according to the Guile REPL, this time I have the code and way to
reproduce the issue.
;; = HELPERS MODULE (networking-lib/helpers.scm) =
(use-modules (rnrs bytevectors))

(define-module (networking-lib helpers)
   #:export (display-byte-vector))

With above code, bytevector import is NOT in the context of your 
module.  Try


(define-module (networking-lib helpers)
  #:export (display-byte-vector))

(use-modules (rnrs bytevectors))


OR


(define-module (networking-lib helpers)
  #:export (display-byte-vector)
  #:use-module (rnrs bytevectors))





Re: Trouble trying to use some modules from the docs (Matt Wette)

2018-06-16 Thread Zelphir Kaltstahl
Hello,

I have managed to get another case of a binding not being available
according to the Guile REPL, this time I have the code and way to
reproduce the issue.

After some struggling, trying and reading the docs of networking
procedures multiple times, I managed to write a little TCP server and
client example program.
(More examples in this area would be cool and if my code is worth
anything, feel free to take it, improve it, and make an example for TCP
server/client in the docs. Or maybe I can put examples in the docs?)

The directory structure looks as follows (tree):


.
├── main.scm
├── networking-lib
│   └── helpers.scm
├── tcp-client.scm
└── tcp-server.scm


The contents of the files are:


;; = HELPERS MODULE (networking-lib/helpers.scm) =
(use-modules (rnrs bytevectors))

(define-module (networking-lib helpers)
  #:export (display-byte-vector))

(define (display-byte-vector vec len)
  (let ([minimal-vec (make-bytevector len)])
    (bytevector-copy! vec 0 minimal-vec 0 len)
    (display (simple-format #f
    "I got the following message: ~s\n"
    (utf8->string minimal-vec)
;; = HELPERS MODULE END =



;; = CLIENT (tcp-client.scm) =
(add-to-load-path
 (string-append "/home/xiaolong"
    "/development/Guile"
    "/examples-and-convenience-procedures/network-programming"))
(use-modules (rnrs bytevectors)
 (networking-lib helpers))

(define receive-buffer (make-bytevector 1024))

(define (connect-to-server)
  (let ([sock
 (socket PF_INET SOCK_STREAM
 (protoent:proto (getprotobyname "TCP")))])
    (connect sock
 (make-socket-address AF_INET
  INADDR_LOOPBACK
  12345))
    sock))

(define (send-message-to-server sock message)
  (display (simple-format #f "sending message to server: ~s" message))
  (send sock (string->utf8 message)))

(define (receive-message-from-server! sock receive-buffer)
  (recv! sock receive-buffer))

(define in-out-sock (connect-to-server))

(let ([bytes-count (receive-message-from-server! in-out-sock
receive-buffer)])
  (display-byte-vector receive-buffer bytes-count)
  (send-message-to-server in-out-sock "Hello from client!\n"))
;; = CLIENT END =



;; = SERVER (tcp-server.scm) =
(add-to-load-path
 (string-append "/home/user"
    "/development/Guile"
    "/examples-and-convenience-procedures/network-programming"))
(use-modules (rnrs bytevectors)
 (networking-lib helpers)
 (ice-9 threads))

(define receive-buffer (make-bytevector 1024))

(define (create-server-socket)
  (let ([sock
 (socket PF_INET SOCK_STREAM (protoent:proto (getprotobyname
"TCP")))]
    [backlog-of-connection-requests 10])
    (bind sock (make-socket-address AF_INET INADDR_ANY 12345))
    (listen sock backlog-of-connection-requests)
    sock))

(define (send-message-to-client sock message)
  (display (simple-format #f "sending message to client: ~s\n" message))
  (send sock (string->utf8 message)))

(define (handle-messages sock)
  (call-with-new-thread
   (λ ()
 (while #t
   (let* ([client-connection
   (accept sock)]
  [client-details (cdr client-connection)]
  [in-out-sock (car client-connection)])
 (display
  (simple-format #f
 "Got new client connection: ~S\n"
 client-details))
 (display
  (simple-format #f
 "Client address: ~S\n"
 (gethostbyaddr (sockaddr:addr client-details

 (send-message-to-client in-out-sock "Hello from server!\n")
 (display-byte-vector receive-buffer (recv! in-out-sock
receive-buffer))
 (display "closing input-output-socket with client ...\n"))

(define sock (create-server-socket))

(handle-messages sock)
;; = SERVER END =



With that code, I do the following:

1. Start two Guile REPLs inside the
.../examples-and-convenience-procedures/network-programming directory.
(in XFCE4 terminal)
2. In the first REPL I paste all code of the server. It starts a new
thread and runs fine without showing any error.
3. In the second REPL I paste all code of the client. It seems to run
fine until I hit the last let form.

The error I get is:


;; = ERROR =
scheme@(guile-user)> (let ([bytes-count (receive-message-from-server!
in-out-sock receive-buffer)])
...   (display-byte-vector receive-buffer bytes-count)
...   (send-message-to-server in-out-sock "Hello from client!\n"))
networking-lib/helpers.scm:7:0: In procedure display-byte-vector:
In procedure module-lookup: Unbound variable: make-byteve

Re: Trouble trying to use some modules from the docs (Matt Wette)

2018-06-05 Thread Mark H Weaver
Hi,

Zelphir Kaltstahl  writes:

> Something must be up with either the Guile REPL or the Guile REPL inside
> Emacs' M-x shell. I tried to run socket in it and it could not find
> that. I also ran other code before that, so maybe the issue was, that
> that somehow prevented the REPL from finding the bindings. However, now
> that I tried what you wrote in a completely new REPL in a XFCE terminal,
> it works flawlessly. And such a thing has happened to me before with
> another module inside Emacs M-x shell mode.

Can you please post a transcript demonstrating the problem that you're
seeing while trying to run 'socket' in Emacs shell mode, starting from
the beginning of the REPL session?

In general, it's much more useful to show us the precise commands you
typed, and the precise error message, than to write "I tried to run
socket in it and it could not find that".  I'd like to understand what's
going on here.  I use the Guile REPL from within Emacs all the time, and
it's far more convenient to use from within Emacs than within a bare
terminal.  It would be good to get to the bottom of this.

 Regards,
   Mark



Re: Trouble trying to use some modules from the docs (Matt Wette)

2018-06-04 Thread Zelphir Kaltstahl


On 03.06.2018 18:00, guile-user-requ...@gnu.org wrote:
> On 06/02/2018 10:13 AM, Zelphir Kaltstahl wrote:
>> Hello Guile mailing list members,
>>
>> Guile Scheme beginner here.
>>
>> I want to play with network programming things in Guile a little, but I
>> cannot figure out how to use the modules, which are described in the
>> docs at
>> https://www.gnu.org/software/guile/manual/html_node/Network-Sockets-and-Communication.html
>> .
>>
>> There is no (use-modules ...) example anywhere I looked and I could also
>> not find any examples in search engines. For other modules I somehow
>> always found an example (use-modules ...) somewhere, mostly in the docs.
>>
>> Is there some inherent way of simply knowing how to import a module? I
>> did not read all of the docs from front to back, but that really should
>> not be necessary in order to use some part of it.
>>
>> What I've tried already:
>>
>> (use-modules (ice-9 posix))? ; maybe the same way many other things are
>> imported?
>> (use-modules (posix))? ; maybe it's its own module?
>> (use-modules (std posix))? ; maybe "std" for "standard" works?
>>
>> None of those worked in the REPL.
>>
>> A search on Github:
>>
>> https://github.com/cky/guile/search?utf8=%E2%9C%93=use-modules+posix=
>>
>> Yielded the following interesting result:
>>
>> https://github.com/cky/guile/blob/c1eb929258fc6b9653d31c0d1bc654d9e300d4e5/module/ice-9/boot-9.scm#L1445
>>
>> But why does (use-modules (ice-9 posix)) not work then? I am out of ideas.
>>
>> Can you point me to the part of the docs, which explain how to always
>> know how to import a module, if there is such? Or, if there is no such
>> thing, can you help me out in this case?
>>
>> Regards,
>>
>> Zelphir
>>
> The manual is not crystal clear in all uses of procedures.  The posix 
> procedures are built-in so
> no `(use-module ...)' is necessary.  The test is to just type the procedure 
> name. You will get a
> procedure object in return. see example below. (Note this does not work with 
> syntax.)
>
> mwette$ guile
> GNU Guile 2.2.3
> Copyright (C) 1995-2017 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)> getaddrinfo
> $1 = #
>
> scheme@(guile-user)>

Thank you!

Something must be up with either the Guile REPL or the Guile REPL inside
Emacs' M-x shell. I tried to run socket in it and it could not find
that. I also ran other code before that, so maybe the issue was, that
that somehow prevented the REPL from finding the bindings. However, now
that I tried what you wrote in a completely new REPL in a XFCE terminal,
it works flawlessly. And such a thing has happened to me before with
another module inside Emacs M-x shell mode.
I think what I can take from this is, that if there is no use-modules
part in the docs, it is likely available without running such and if it
is not available I should check outside of Emacs in a standard terminal
emulator.


Re: Trouble trying to use some modules from the docs

2018-06-02 Thread Matt Wette

On 06/02/2018 10:13 AM, Zelphir Kaltstahl wrote:

Hello Guile mailing list members,

Guile Scheme beginner here.

I want to play with network programming things in Guile a little, but I
cannot figure out how to use the modules, which are described in the
docs at
https://www.gnu.org/software/guile/manual/html_node/Network-Sockets-and-Communication.html
.

There is no (use-modules ...) example anywhere I looked and I could also
not find any examples in search engines. For other modules I somehow
always found an example (use-modules ...) somewhere, mostly in the docs.

Is there some inherent way of simply knowing how to import a module? I
did not read all of the docs from front to back, but that really should
not be necessary in order to use some part of it.

What I've tried already:

(use-modules (ice-9 posix))  ; maybe the same way many other things are
imported?
(use-modules (posix))  ; maybe it's its own module?
(use-modules (std posix))  ; maybe "std" for "standard" works?

None of those worked in the REPL.

A search on Github:

https://github.com/cky/guile/search?utf8=%E2%9C%93=use-modules+posix=

Yielded the following interesting result:

https://github.com/cky/guile/blob/c1eb929258fc6b9653d31c0d1bc654d9e300d4e5/module/ice-9/boot-9.scm#L1445

But why does (use-modules (ice-9 posix)) not work then? I am out of ideas.

Can you point me to the part of the docs, which explain how to always
know how to import a module, if there is such? Or, if there is no such
thing, can you help me out in this case?

Regards,

Zelphir


The manual is not crystal clear in all uses of procedures.  The posix 
procedures are built-in so
no `(use-module ...)' is necessary.  The test is to just type the procedure 
name. You will get a
procedure object in return. see example below. (Note this does not work with 
syntax.)

mwette$ guile
GNU Guile 2.2.3
Copyright (C) 1995-2017 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)> getaddrinfo
$1 = #

scheme@(guile-user)>






Trouble trying to use some modules from the docs

2018-06-02 Thread Zelphir Kaltstahl
Hello Guile mailing list members,

Guile Scheme beginner here.

I want to play with network programming things in Guile a little, but I
cannot figure out how to use the modules, which are described in the
docs at
https://www.gnu.org/software/guile/manual/html_node/Network-Sockets-and-Communication.html
.

There is no (use-modules ...) example anywhere I looked and I could also
not find any examples in search engines. For other modules I somehow
always found an example (use-modules ...) somewhere, mostly in the docs.

Is there some inherent way of simply knowing how to import a module? I
did not read all of the docs from front to back, but that really should
not be necessary in order to use some part of it.

What I've tried already:

(use-modules (ice-9 posix))  ; maybe the same way many other things are
imported?
(use-modules (posix))  ; maybe it's its own module?
(use-modules (std posix))  ; maybe "std" for "standard" works?

None of those worked in the REPL.

A search on Github:

https://github.com/cky/guile/search?utf8=%E2%9C%93=use-modules+posix=

Yielded the following interesting result:

https://github.com/cky/guile/blob/c1eb929258fc6b9653d31c0d1bc654d9e300d4e5/module/ice-9/boot-9.scm#L1445

But why does (use-modules (ice-9 posix)) not work then? I am out of ideas.

Can you point me to the part of the docs, which explain how to always
know how to import a module, if there is such? Or, if there is no such
thing, can you help me out in this case?

Regards,

Zelphir




Re: Problem merging generics across modules

2017-10-17 Thread David Pirotte
Hi Andrew,

Lets try to keep our conversation about this o the list, others may 
benefit
from it, and/or help us ...

> Thanks for your feedback on this. It certainly resolved my issue.

Welcome.

> Can you point me to documentation on this? I read through the Guile info
> pages when trying to figure this out, but I couldn't figure it out.
> ...

No, there is no 'good' documentation neither recommendation(s) about 'generic
functions and the module system' in guile's manual - I mean 'no good' in my 
opinion,
but this is 'relative', and besides, some guilers are opposed to these
recommendations I always 'offer', but here they are:

1]  better preventing then curing:  when you define a module that use goops,
always use

  #:duplicates (merge-generics
replace
warn-override-core
warn
last)

2]  unless you really know what you are doing, never call define-generic
yourself

3]  always use #:export for class names, and make sure class names are
unique (guile will warn you if not, at import time, so rename if you
have conflict, never use twice the same class name in diff modules 
(unless
you really know what you're doing))

4]  always use g-export for (and only for) getters, setters, accessors and
methods


https://git.savannah.gnu.org/cgit/guile-cv.git/tree/cv/support/g-export.scm

5]  remember, while you are developing and testing your code, you have to 
add
'merge-generics to the default-duplicate-binding-handler in the repl as 
well,
_after_ you imported goops (in the repl):

,use (oop goops)
(default-duplicate-binding-handler
   '(merge-generics replace warn-override-core warn last))
    (use-modules (yourmod1) (yourmod2))

With these recommendations, you actually 'mimic' [1] the CLOS specification, 
which
states that anything related to CLOS lands in a specific package, visible to all
others.

David

[1] mimic because unlike CLOS, a generic function in a guile module will
only contain methods that comes from that module and the one it
imports, but not (necessarily) all methods for that name (unless the 
module
imports all the others that define a method for that name of course)


pgpVqlMqWFBtj.pgp
Description: OpenPGP digital signature


Re: Problem merging generics across modules

2017-10-13 Thread David Pirotte
Hi again,

> ... You should use #:re-export instead

Note that #:re-export fails if the name is not already defined ... which is ok 
for
small and individual projects, but less then optimal and subject to introduce 
bugs
for long term projects, involving multiple developers, with hundreds of 
modules, and
where module reorganization is (sometimes) part of the game ...  So I defined a 
macro
which checks if a name exists (as in imported) or not, and appropriately calls
export or re-export, that you should onlu use for getters, setters, accessors
and methods):


https://git.savannah.gnu.org/cgit/guile-cv.git/tree/cv/support/g-export.scm

Just as an example, your module definition would be (see below)... Then if this
module later imports another module, that defines !r, !g and/or !b, you still 
would
be fine...

Cheers,
David

;;;
;;; Extending equal?
;;;

(define-module (extending-equal)
  #:use-module (oop goops)
  ;; just changed the module 'path' to what ever ...
  #:use-module (g-export)

  #:export ()

(g-export !r
!g
!b)

(define-class  ()
  (r #:accessor !r #:init-keyword #:r #:init-value 0)
  (g #:accessor !g #:init-keyword #:g #:init-value 0)
  (b #:accessor !b #:init-keyword #:b #:init-value 0))

(define-method (equal? (c1 ) (c2 ))
  (pk "in extended equal? ...")
  (and (= (!r c1) (!r c2))
   (= (!g c1) (!g c2))
   (= (!b c1) (!b c2


pgpX10JuRN8c7.pgp
Description: OpenPGP digital signature


Re: Problem merging generics across modules

2017-10-13 Thread David Pirotte
Hi again,

> (define-module (project a)
>   #:use-module (oop goops)  
>   #:use-module (ice-9 r5rs)
>   #:duplicates (merge-generics)
>   #:export (equal?)

> but this doesn't seem to do anything.

Because that was not the source of your problem, see my previous email.

Although in theory merge-generics is only needed when you import more then one 
module
that define the 'same' generic function, I personally recommend you to add the 
option
in any modules that use goops, unless you really know what you are doing:

this is because as time goes, you may rearrange your modules, import
others ... and forget that more then one defined a generic function, 
and ...
bang! (and these bugs are among the most diffcult to track down and 
debug

Note that you probably want more then just 'merge-generics, and prefer to 
extend the
default set:

scheme@(guile-user)> (default-duplicate-binding-handler)
$10 = (replace warn-override-core warn last)

So this gives you:

  #:duplicates (merge-generics
replace
warn-override-core
warn
last)

Also note that you have to set this in the repl as well, if you import more 
then one
module defining the 'same' generics ...:

(default-duplicate-binding-handler
   '(merge-generics replace warn-override-core warn last))
$11 = (#< merge-generics (3)> # …)
scheme@(guile-user)> (default-duplicate-binding-handler)
$12 = (merge-generics replace warn-override-core warn last)

David


pgp7sHMBKdAiV.pgp
Description: OpenPGP digital signature


Re: Problem merging generics across modules

2017-10-13 Thread David Pirotte
Hello Andrew,

> I am trying to extend the definition of a few primitives,
> including equal?, in a project of mine. Let's say that a.scm contains:

> (define-module (project a)
>   #:use-module (oop goops)  
>   #:export (equal?)

When you extend a guile primitive, don't #:export it in your module definition,
because that creates a new binding, hiding guile's core primitive. You should 
use
#:re-export instead, though in this very specific case of extending a guile core
primitive it is not even necessary, because when guile 'encounter' your
define-method, it does this:

it creates a generic function for the method name, if it does not 
already
exists, by calling define-generic [1]:

define-generic checks that the name was (or not) previously 
bound to
a scheme procedure, in which case it incorporates it into the 
new
generic function as its default procedure

it adds your methods to the generic function...

David

[1] unless you really know what you are doing, you don't want to call
define-generic yourself, because if it existed already, then that 
previous
generic function would discarded and replaced by a new, empty generic
function. goops calls define-generic for you, as part ofthe 
define-method
protocol, iff there is no generic function for that name, so you are 
always
on the safe side to rely on goops here.

;;;
;;; Extending equal?
;;;

(define-module (extending-equal)
  #:use-module (oop goops)

  #:export (
!r
!g
!b))

(define-class  ()
  (r #:accessor !r #:init-keyword #:r #:init-value 0)
  (g #:accessor !g #:init-keyword #:g #:init-value 0)
  (b #:accessor !b #:init-keyword #:b #:init-value 0))

(define-method (equal? (c1 ) (c2 ))
  (pk "in extended equal? ...")
  (and (= (!r c1) (!r c2))
   (= (!g c1) (!g c2))
   (= (!b c1) (!b c2

;;;
;;; Let's try it
;;;

GNU Guile 2.2.2.3-0c102

scheme@(guile-user)> (add-to-load-path (getcwd))
scheme@(guile-user)> ,use (oop goops)
scheme@(guile-user)> ,use (extending-equal)
;;; note: source file /usr/alto/projects/guile/goops/extending-equal.scm
;;; ...
scheme@(guile-user)> (make )
$2 = #< 5610ca6b2ba0>
scheme@(guile-user)> (make )
$3 = #< 5610ca7480f0>
scheme@(guile-user)> (equal? $2 $3)

;;; ("in extended equal? ...")
$4 = #t


pgpeS5qjRHKtZ.pgp
Description: OpenPGP digital signature


Re: Problem merging generics across modules

2017-10-12 Thread Andrew Erlanger
Andrew Erlanger <andrew.erlan...@gmail.com> writes:

> Now I go to the REPL, and this is what I see:
>
> scheme@(guile-user)> equal?
> WARNING: (guile-user): `equal?' imported from both (ice-9 r5rs) and (capital 
> base)
> $2 = #< equal? (2)>
> scheme@(guile-user)> (equal? 2 3)
> ERROR: In procedure scm-error:
> ERROR: No applicable method for #< equal? (2)> in call (equal? 2 3)
>

I should have mentioned that these are called after invoking:

> scheme@(guile-user)> (use-modules (project a))

- Andrew



Problem merging generics across modules

2017-10-12 Thread Andrew Erlanger
Hello, Schemers,

I am trying to extend the definition of a few primitives,
including equal?, in a project of mine. Let's say that a.scm contains:

(define-module (project a)
  #:use-module (oop goops)  
  #:export (equal?)

...

(define-method (equal? (c1 ) (c2 ))
   (same-rgb? c1 c2))

Now I go to the REPL, and this is what I see:

scheme@(guile-user)> equal?
WARNING: (guile-user): `equal?' imported from both (ice-9 r5rs) and (capital 
base)
$2 = #< equal? (2)>
scheme@(guile-user)> (equal? 2 3)
ERROR: In procedure scm-error:
ERROR: No applicable method for #< equal? (2)> in call (equal? 2 3)

Now I'm aware of "#:duplicates (merge-generics)", but I don't understand
how to apply it in this case. I've tried replacing the module definition with:

(define-module (project a)
  #:use-module (oop goops)  
  #:use-module (ice-9 r5rs)
  #:duplicates (merge-generics)
  #:export (equal?)

but this doesn't seem to do anything.

Any advice? Thank you.

- Andrew



Error compiling guile modules with guile extended program

2017-03-28 Thread Vijay Pratap Chaurasia
Hi,
   I have a bunch of C/C++ libraries and functions which I link with guile
to build an extension of guile. I have compiled guile-2.2 on RHEL5 system
and compiled and link my program with guile successfully but when I execute
my program, it fails to compile guile modules.
Environment variables GUILE_LOAD_PATH and GUILE_LOAD_COMPILED_PATH are set
properly. Any help appreciated.

;;; compiling /ilx/fish_tools/share/guile/2.2/system/vm/vm.scm
;;; compiling /ilx/fish_tools/share/guile/2.2/system/base/compile.scm
;;; it seems /ilx/fish_tools/share/guile/2.2/system/base/compile.scm
;;; is part of the compiler; skipping auto-compilation
;;; compiling /ilx/fish_tools/share/guile/2.2/system/base/syntax.scm
;;; WARNING: compilation of
/ilx/fish_tools/share/guile/2.2/system/base/syntax.scm failed:
;;; ERROR: In procedure variable-ref: variable is unbound: #>
;;; compiling /ilx/fish_tools/share/guile/2.2/system/base/message.scm
;;; WARNING: compilation of
/ilx/fish_tools/share/guile/2.2/system/base/message.scm failed:
;;; ERROR: In procedure variable-ref: variable is unbound: #>

.
;;; compiling /ilx/fish_tools/share/guile/2.2/language/bytecode/spec.scm
;;; WARNING: compilation of
/ilx/fish_tools/share/guile/2.2/language/bytecode/spec.scm failed:
;;; ERROR: no such language bytecode
..
;;; compiling
/ilx/fish_tools/share/guile/2.2/language/scheme/decompile-tree-il.scm
;;; WARNING: compilation of
/ilx/fish_tools/share/guile/2.2/language/scheme/decompile-tree-il.scm
failed:
;;; ERROR: no such language scheme
..
;;; compiling /ilx/fish_tools/share/guile/2.2/language/tree-il/debug.scm
;;; WARNING: compilation of
/ilx/fish_tools/share/guile/2.2/language/tree-il/debug.scm failed:
;;; ERROR: no such language tree-il


Thanks
- Vijay


Concentrate procedures from various modules in one module

2017-02-21 Thread Diogo F. S. Ramos
Can I concentrate procedures from various modules in one module and use
this module in the other modules?

For example, suppose I have these modules:

(define-module (foo)
  #:export (foo-proc))

(define-module (bar)
  #:export (bar-proc))

`foo' is a module that exports procedure `foo-proc' and `bar' is another
module that exports `bar-proc'.

I want to concentrate `foo-proc' and `bar-proc' in a single `quux'
module, and then use this `quux' module in `foo' and `bar'.

(define-module (quux)
  #:use-module (foo)
  #:re-export (foo-proc)
  #:use-module (bar)
  #:re-export (bar-proc))

(define-module (foo)
  #:use-module (quux)
  #:export (foo-proc))

(define-module (bar)
  #:use-module (quux)
  #:export (bar-proc))

Unfortunately on the REPL, when I try to change to module (say) `foo',
there is an `ERROR: Undefined variable: foo-proc'.



Re: Modules and GOOPS

2016-07-31 Thread Chris Vine
On Fri, 29 Jul 2016 21:00:42 +0300
Marko Rauhamaa  wrote:
[snip]
> More generally, take a look at  http://www.delorie.com/gnu/docs/guile/guile-tut_10.html> and how
> MAKE-CELL has been defined. That's true OOP without classes or slots.

For that simple kind of use you might as well use records.  R6RS
records are also inheritable, so you can construct type heirarchies;
SRFI-9 records are not.  Guile provides both.

Chris



Re: Modules and GOOPS

2016-07-29 Thread Kovacsics Róbert
First, thank you for your detailed answer!

On 28 July 2016 at 22:14, David Pirotte <da...@altosw.be> wrote:
> First, generic functions are 'containers', that are not associated, and do not
> pertain to any class.  does not have a generic function x:

Thank you, I am still thinking in Java terms at the moment.

> Then unlike you've been told by others, I do not recommend to define generic
> function, they are just 'containers', the system creates them for you and it 
> is an
> error [not implemented by Guile] to redefine a generic function. With the 
> last in
> mind, manually defining GF will work if you play with a couple of your own 
> modules,
> but it will almost certainly fail for large system.

 So what is the right approach when I'm implementing textbook data
structures (rather than want to use the given ones, for learning
reasons) and want to implement a set. On this set, I want to write a
method "closure" that computes all the elements of the set given a
function on the set elements, such that for any call to the function
with an element of the set, the result will also be in the set. This
is the same code for all implementation, but depends on implementation
specific code such as "contains?" and "add". Then I want to implement
different sets, e.g. red-black trees, AVL trees, etc.

The plan was something like this, but I think I may be trying to
achieve it wrong, or at least the unidiomatic way:

; =
(define-module (sets set)
  #:use-module (oop goops)
  #:export ( add ... closure))

(define-class  ())

(define-generic add)
...

(define-method (closure (set ) (function ))
  ... contains? ... add ... )

; =
(define-module (sets red-black-tree)
  #:use-module (oop goops)
  #:use-module (sets set)
  #:export ())

(define-class  ())

(define-method (add (tree ))
  ...)

; =
... Code to exercise methods ...


> But if you do so, define generic functions manually, then I recommend do it in
> another module.

So I could move the add, etc, methods out into another module, if that
is the way to do it, but I need them, because without having them,
Guile will complain with "unbound variable: add". But this is a very
classes-contain-methods approach and given what you said, makes me
think that I'm doing this wrong thing.



Re: Modules and GOOPS

2016-07-29 Thread Marko Rauhamaa
Kovacsics Róbert :

> Thank you, I am still thinking in Java terms at the moment.
>
> [...]
>
> But this is a very classes-contain-methods approach and given what you
> said, makes me think that I'm doing this wrong thing.

I'm thinking GOOPS is the wrong thing here.

A better, more Schemey way is hiding in plain sight. Look at how ports
are created and manipulated. You have a rich set of methods that take
the best from Scheme and the classic object/method paradigm, eg:

   (with-output-to-string thunk)

   (with-input-from-file filename thunk)

   (port-filename port)

   (close-port port)


More generally, take a look at http://www.delorie.com/gnu/docs/guile/guile-tut_10.html> and how
MAKE-CELL has been defined. That's true OOP without classes or slots.


Marko



Re: Modules and GOOPS

2016-07-27 Thread Jan Wedekind

On Wed, 27 Jul 2016, Kovacsics Róbert wrote:


Hello!

I have trouble with getting GOOPS and modules to co-operate. What I am
trying to do is to have 'A subclass B' where A is something akin to an
abstract class, that is it has generic "x" for which it provides no
implementation. This is my minimum broken example:


; =
(define-module (mbe a)
 #:use-module (oop goops)
 #:export ( x y))

(define-class  ())

(define-generic x)
(define-generic y)

(define-method (y (a ))
 (display (x a)))

; =
(define-module (mbe b)
 #:use-module (oop goops)
 #:use-module (mbe a)
 #:export ( x))

(define-class  ())

(define-method (x (b ))
 'b)

; =
(define-module (mbe test)
 #:use-module (oop goops)
 #:use-module (mbe a)
 #:use-module (mbe b)
 #:duplicates (merge-generics))

(y (make ))


and when I type "(use-modules (mbe test))" in guile, I get


While compiling expression:
ERROR: No applicable method for #< x (0)> in call (x #< 23ccdd0>)

(which shows that the generic function "x" has no implementation as
far as I can work it out, due to accessibility. When I don't use
separate modules, it works.)

Am I using the right sort of approach? I was thinking modules, for
extensibility.




Having mbe/b.scm *not* export "x" works but I am not sure whether that is 
the solution you are looking for:



; =
(define-module (mbe a)
  #:use-module (oop goops)
  #:export ( x y))

(define-class  ())

(define-generic x)
(define-generic y)

(define-method (y (a ))
  (display (x a)))

; =
(define-module (mbe b)
  #:use-module (oop goops)
  #:use-module (mbe a)
  #:export ())

(define-class  ())

(define-method (x (b ))
  'b)

; =
(define-module (mbe test)
  #:use-module (oop goops)
  #:use-module (mbe a)
  #:use-module (mbe b)
  #:duplicates (merge-generics))

(y (make ))


Has anybody managed to get the "merge-generics" handler to work? I used to 
have this in my $HOME/.guile configuration but it didn't seem to have any 
effect:


(default-duplicate-binding-handler '(merge-generics replace warn-override-core 
warn last))


Modules and GOOPS

2016-07-27 Thread Kovacsics Róbert
Hello!

I have trouble with getting GOOPS and modules to co-operate. What I am
trying to do is to have 'A subclass B' where A is something akin to an
abstract class, that is it has generic "x" for which it provides no
implementation. This is my minimum broken example:


; =
(define-module (mbe a)
  #:use-module (oop goops)
  #:export ( x y))

(define-class  ())

(define-generic x)
(define-generic y)

(define-method (y (a ))
  (display (x a)))

; =
(define-module (mbe b)
  #:use-module (oop goops)
  #:use-module (mbe a)
  #:export ( x))

(define-class  ())

(define-method (x (b ))
  'b)

; =
(define-module (mbe test)
  #:use-module (oop goops)
  #:use-module (mbe a)
  #:use-module (mbe b)
  #:duplicates (merge-generics))

(y (make ))


and when I type "(use-modules (mbe test))" in guile, I get


While compiling expression:
ERROR: No applicable method for #< x (0)> in call (x #< 23ccdd0>)

(which shows that the generic function "x" has no implementation as
far as I can work it out, due to accessibility. When I don't use
separate modules, it works.)

Am I using the right sort of approach? I was thinking modules, for
extensibility.



Re: Deficiencies in documentation for modules

2013-12-02 Thread Ludovic Courtès
Panicz Maciej Godek godek.mac...@gmail.com skribis:

 While looking at (ice-9 r5rs), (ice-9 safe-r5rs)
 and (ice-9 null), I've noticed, that there are a few
 undocumented procedures used there, like
 make-module or set-module-kind!. In the thread
 http://lists.gnu.org/archive/html/guile-user/2009-02/msg0.html
 there is another one mentioned, named beautify-user-module!.
 Using the readline's completion feature, I also noticed
 that there are procedures module-obarray,
 module-observe, make-modules-in and some
 others that are lacking an entry in the manual.

 Are there any deeper reasons behind their absence,
 or is it just an oversight?

Initially it’s just an oversight.

For now, you can figure it out by browsing boot-9.scm (which is
admittedly suboptimal; patches welcome!)

Nowadays, as Guile moves toward ahead-of-time compilation, there may be
an incentive to keep some of the module API internal, I think.

Thanks,
Ludo’.




Deficiencies in documentation for modules

2013-12-01 Thread Panicz Maciej Godek
While looking at (ice-9 r5rs), (ice-9 safe-r5rs)
and (ice-9 null), I've noticed, that there are a few
undocumented procedures used there, like
make-module or set-module-kind!. In the thread
http://lists.gnu.org/archive/html/guile-user/2009-02/msg0.html
there is another one mentioned, named beautify-user-module!.
Using the readline's completion feature, I also noticed
that there are procedures module-obarray,
module-observe, make-modules-in and some
others that are lacking an entry in the manual.

Are there any deeper reasons behind their absence,
or is it just an oversight?


Re: statically linking in srfi modules

2013-02-12 Thread Richard Shann
On Mon, 2013-02-11 at 12:03 -0500, Mark H Weaver wrote:
 Richard Shann richard.sh...@virgin.net writes:
  configure:31783: checking for main in -lregex
  configure:31812: i686-pc-mingw32-gcc -o conftest.exe
  -Wno-unused-but-set-variable
  -I/home/rshann/mxe/usr/i686-pc-mingw32/include  conftest.c -lregex
  -lgmp -lws2_32 -lm -lltdl -lunistring -lintl -liconv 5
  /home/rshann/mxe/usr/lib/gcc/i686-pc-mingw32/4.7.0/../../../../i686-pc-mingw32/bin/ld:
   cannot find -lregex
 
  probably in all cases.
 
 Can you find out where the 'regcomp' function is? 
Well, I tracked back from the GNU/LilyPond build system - it seems to
originate in glibc, but in the GNU/LilyPond build system it has been
extracted out as a separate library. 
http://lilypond.org/download/gub-sources/regex-2.3.90-1.tar.bz2

By building this with --disable-shared I have obtained a library which
links to guile and ice-9/regex is now working inside Denemo.

Thank you very much for your help. I don't know if there is anything
that it would be good to do upstream as a result of this epic little
voyage ...

Richard

  If you can find it,
 you could pass LDFLAGS=-lfoobar to ./configure.  My suspicion is that
 it's missing from your MXE build.  Another possibility is that 'regcomp'
 is a preprocessor macro in one of the include files, which the current
 tests would fail to detect.
 
  I am a bit out of my depth here ... these seem to be the libraries that
  could plausibly provide regcomp(), )
  (by running find . -name '*regex*' -print)
  
  ./usr/i686-pc-mingw32/lib/libboost_regex-mt.a
  ./usr/i686-pc-mingw32/lib/libwxregexu-2.8-i686-pc-mingw32.a
  ./usr/i686-pc-mingw32/lib/libwxregex-2.8-i686-pc-mingw32.a
  ./usr/i686-pc-mingw32/lib/libboost_regex-mt-d.a
 
 These aren't the droids you're looking for.  Guile 1.8's ./configure
 seems to be looking for either libregex or librx, though I confess that
 my autoconf skills are weak.
 
   Mark





Re: statically linking in srfi modules

2013-02-12 Thread Mark H Weaver
Richard Shann richard.sh...@virgin.net writes:

 On Mon, 2013-02-11 at 12:03 -0500, Mark H Weaver wrote:
 
 Can you find out where the 'regcomp' function is? 

 Well, I tracked back from the GNU/LilyPond build system - it seems to
 originate in glibc, but in the GNU/LilyPond build system it has been
 extracted out as a separate library. 
 http://lilypond.org/download/gub-sources/regex-2.3.90-1.tar.bz2

 By building this with --disable-shared I have obtained a library which
 links to guile and ice-9/regex is now working inside Denemo.

Excellent!

 Thank you very much for your help. I don't know if there is anything
 that it would be good to do upstream as a result of this epic little
 voyage ...

Glad to help, and thanks for letting us know how it went.

I guess the main thing for us to do upstream is to ensure that
--disable-shared works properly without such workarounds.  Fortunately
this is mostly not an issue in Guile 2, because the SRFI-1 and SRFI-60
libraries have been moved into the core.  The only remaining
dynamically-loaded extension bundled with Guile 2 is for readline.
It would be good to fix that at some point.

Regards,
  Mark



Re: statically linking in srfi modules

2013-02-11 Thread Richard Shann
On Mon, 2013-02-11 at 10:05 +, Richard Shann wrote:
 I noticed that the invocation of the guile build was accepting the
 default for regex, so I tried setting it explicitly
 with --enable-regex=yes in the configure. With this I see in
 config.log
 
 configure:31783: checking for main in -lregex
 configure:31812: i686-pc-mingw32-gcc -o conftest.exe
 -Wno-unused-but-set-variable
 -I/home/rshann/mxe/usr/i686-pc-mingw32/include  conftest.c -lregex
 -lgmp -lws2_32 -lm -lltdl -lunistring -lintl -liconv 5
 /home/rshann/mxe/usr/lib/gcc/i686-pc-mingw32/4.7.0/../../../../i686-pc-mingw32/bin/ld:
  cannot find -lregex
 collect2: error: ld returned 1 exit status
 
 That must surely be a clue, and perhaps a bug, I presume the default
 is
 to have regex built? 
Sorry - 
I think I was getting fooled here by repeated sections of stuff,
checking for regcomp occurs three times and there is this:

configure:31783: checking for main in -lregex
configure:31812: i686-pc-mingw32-gcc -o conftest.exe
-Wno-unused-but-set-variable
-I/home/rshann/mxe/usr/i686-pc-mingw32/include  conftest.c -lregex
-lgmp -lws2_32 -lm -lltdl -lunistring -lintl -liconv 5
/home/rshann/mxe/usr/lib/gcc/i686-pc-mingw32/4.7.0/../../../../i686-pc-mingw32/bin/ld:
 cannot find -lregex

probably in all cases.

Richard




Re: statically linking in srfi modules

2013-02-11 Thread Mark H Weaver
Richard Shann richard.sh...@virgin.net writes:
 configure:31783: checking for main in -lregex
 configure:31812: i686-pc-mingw32-gcc -o conftest.exe
 -Wno-unused-but-set-variable
 -I/home/rshann/mxe/usr/i686-pc-mingw32/include  conftest.c -lregex
 -lgmp -lws2_32 -lm -lltdl -lunistring -lintl -liconv 5
 /home/rshann/mxe/usr/lib/gcc/i686-pc-mingw32/4.7.0/../../../../i686-pc-mingw32/bin/ld:
  cannot find -lregex

 probably in all cases.

Can you find out where the 'regcomp' function is?  If you can find it,
you could pass LDFLAGS=-lfoobar to ./configure.  My suspicion is that
it's missing from your MXE build.  Another possibility is that 'regcomp'
is a preprocessor macro in one of the include files, which the current
tests would fail to detect.

 I am a bit out of my depth here ... these seem to be the libraries that
 could plausibly provide regcomp(), )
 (by running find . -name '*regex*' -print)
 
 ./usr/i686-pc-mingw32/lib/libboost_regex-mt.a
 ./usr/i686-pc-mingw32/lib/libwxregexu-2.8-i686-pc-mingw32.a
 ./usr/i686-pc-mingw32/lib/libwxregex-2.8-i686-pc-mingw32.a
 ./usr/i686-pc-mingw32/lib/libboost_regex-mt-d.a

These aren't the droids you're looking for.  Guile 1.8's ./configure
seems to be looking for either libregex or librx, though I confess that
my autoconf skills are weak.

  Mark



Re: statically linking in srfi modules

2013-02-10 Thread Richard Shann
On Sat, 2013-02-09 at 21:00 -0500, Mark H Weaver wrote:
 Hi Richard,
 
 Don't worry, we'll get it working.  Here's another attempt.
 Replace the calls to 'scm_c_register_extension' with the following:
 
   scm_c_call_with_current_module (scm_c_resolve_module (guile),
   bind_srfi_initializers, NULL);
 
 With the following additional definitions:
 
   static SCM
   init_srfi_1 (void)
   {
 scm_init_srfi_1 ();
 return SCM_UNSPECIFIED;
   }
 
   static SCM
   init_srfi_60 (void)
   {
 scm_init_srfi_60 ();
 return SCM_UNSPECIFIED;
   }
 
   static SCM
   bind_srfi_initializers (void *dummy)
   {
 scm_c_define_gsubr (%init-srfi-1,  0, 0, 0, init_srfi_1);
 scm_c_define_gsubr (%init-srfi-60, 0, 0, 0, init_srfi_60);
 return SCM_UNSPECIFIED;
   }
 
 Then, starting with the original versions of srfi-1.scm and srfi-60.scm
 from Guile 1.8, replace the (load-extension ...) calls in those two
 files with (%init-srfi-1) and (%init-srfi-60), respectively.
With this Denemo starts up looking very good - no error messages from
any of the scheme executed on startup. However the symbol make-regexp is
undefined. Denemo executes 

(use-modules (srfi srfi-1)) ; List library
(use-modules (srfi srfi-8)) ; Returning and Accepting Multiple Values
(use-modules (srfi srfi-13)) ; String library
(use-modules (ice-9 regex)) ; regular expressions
(use-modules (ice-9 optargs)) ; optional (define* ) arguments
(use-modules (ice-9 q)) ; queue module

at startup.
I have displayed (defined? 'make-regexp) and it is #f from before the
first of those module loads and remains #f throughout.
 
I am not sure if it is defined or merely re-defined by (ice-9 regex).

Could this be a side effect of those initialization calls made in the C
code? Or is this a separate problem? ... I realize that I don't know for
sure that srfi-1 has successfully loaded - is there a simple test for
that?

Thanks for your patience,

Richard







Re: statically linking in srfi modules

2013-02-10 Thread Mark H Weaver
Richard Shann richard.sh...@virgin.net writes:
 With this Denemo starts up looking very good - no error messages from
 any of the scheme executed on startup.

Good.  I think the SRFI problem is finally solved.

 However the symbol make-regexp is undefined.

This is an unrelated problem, namely that './configure' is apparently
unable to find a suitable POSIX regexp library.  I think you'll find
that HAVE_REGCOMP is not defined in 'config.h', in which case
'make-regexp' will not be available.  Search for 'regex' and 'rxposix'
in 'config.log' for details on what went wrong.

Regards,
  Mark



Re: statically linking in srfi modules

2013-02-09 Thread Mark H Weaver
Richard Shann richard.sh...@virgin.net writes:
 Well it seems I may have been premature in saying that srfi-1 was
 successfully loaded. Although the error message is gone, there is no
 symbol 'map which srfi-1 should have re-defined. 
 Can someone suggest what this might be a symptom of? 

I know what's wrong.  Please try replacing the calls to
'scm_c_register_extension' with the following:

  scm_c_define_module (srfi srfi-1,  init_srfi_1,  NULL);
  scm_c_define_module (srfi srfi-60, init_srfi_60, NULL);

Where 'init_srfi_1' and 'init_srfi_60' are defined as follows:

  static void init_srfi_1  (void *dummy) { scm_init_srfi_1  (); }
  static void init_srfi_60 (void *dummy) { scm_init_srfi_60 (); }

 Mark



Re: statically linking in srfi modules

2013-02-09 Thread Mark H Weaver
Richard Shann richard.sh...@virgin.net writes:
 Well it seems I may have been premature in saying that srfi-1 was
 successfully loaded. Although the error message is gone, there is no
 symbol 'map which srfi-1 should have re-defined. 
 Can someone suggest what this might be a symptom of? 

I wrote:
 I know what's wrong.  Please try replacing the calls to
 'scm_c_register_extension' with the following:

   scm_c_define_module (srfi srfi-1,  init_srfi_1,  NULL);
   scm_c_define_module (srfi srfi-60, init_srfi_60, NULL);
[...]

Sorry, this isn't quite right either.  Instead of the above, please try
replacing the calls to 'scm_c_register_extension' with the following:

  scm_c_call_with_current_module (scm_c_resolve_module (srfi srfi-1),
  init_srfi_1, NULL);
  scm_c_call_with_current_module (scm_c_resolve_module (srfi srfi-60),
  init_srfi_60, NULL);

Where 'init_srfi_1' and 'init_srfi_60' are defined as follows:

  static SCM
  init_srfi_1 (void *dummy)
  {
scm_init_srfi_1 ();
return SCM_UNSPECIFIED;
  }

  static SCM
  init_srfi_60 (void *dummy)
  {
scm_init_srfi_60 ();
return SCM_UNSPECIFIED;
  }

Hopefully this will work.  I'm too lazy to try it myself.

  Mark



Re: statically linking in srfi modules

2013-02-09 Thread Richard Shann
On Sat, 2013-02-09 at 10:32 -0500, Mark H Weaver wrote:
 Richard Shann richard.sh...@virgin.net writes:
  Well it seems I may have been premature in saying that srfi-1 was
  successfully loaded. Although the error message is gone, there is no
  symbol 'map which srfi-1 should have re-defined. 
  Can someone suggest what this might be a symptom of? 
 
 I wrote:
  I know what's wrong.  Please try replacing the calls to
  'scm_c_register_extension' with the following:
 
scm_c_define_module (srfi srfi-1,  init_srfi_1,  NULL);
scm_c_define_module (srfi srfi-60, init_srfi_60, NULL);
 [...]

This worked in that map was defined, but then make-regexp was undefined
- we (use-modules (ice-9 regex)) in our opening preamble, which I guess
may re-define that, but grepping through the ice-9 directory I didn't
see any sign of the load-extension call that happens in srfi-1 and 60.
 
 Sorry, this isn't quite right either.  Instead of the above, please try
 replacing the calls to 'scm_c_register_extension' with the following:
 
   scm_c_call_with_current_module (scm_c_resolve_module (srfi srfi-1),
   init_srfi_1, NULL);
   scm_c_call_with_current_module (scm_c_resolve_module (srfi srfi-60),
   init_srfi_60, NULL);
 
 Where 'init_srfi_1' and 'init_srfi_60' are defined as follows:
 
   static SCM
   init_srfi_1 (void *dummy)
   {
 scm_init_srfi_1 ();
 return SCM_UNSPECIFIED;
   }
 
   static SCM
   init_srfi_60 (void *dummy)
   {
 scm_init_srfi_60 ();
 return SCM_UNSPECIFIED;
   }
 
This seemed to have a dramatic effect! The program exits at startup with
the message
ERROR: Unbound variable: map

and return status 1

Until now I felt we were converging on something :) One thing that
puzzles me is that other srfi numbers have static libraries generated
for them, but on 1 and 60 would seem to be needed?
Thanks for the support...

Richard








Re: statically linking in srfi modules

2013-02-09 Thread Mark H Weaver
Hi Richard,

Don't worry, we'll get it working.  Here's another attempt.
Replace the calls to 'scm_c_register_extension' with the following:

  scm_c_call_with_current_module (scm_c_resolve_module (guile),
  bind_srfi_initializers, NULL);

With the following additional definitions:

  static SCM
  init_srfi_1 (void)
  {
scm_init_srfi_1 ();
return SCM_UNSPECIFIED;
  }

  static SCM
  init_srfi_60 (void)
  {
scm_init_srfi_60 ();
return SCM_UNSPECIFIED;
  }

  static SCM
  bind_srfi_initializers (void *dummy)
  {
scm_c_define_gsubr (%init-srfi-1,  0, 0, 0, init_srfi_1);
scm_c_define_gsubr (%init-srfi-60, 0, 0, 0, init_srfi_60);
return SCM_UNSPECIFIED;
  }

Then, starting with the original versions of srfi-1.scm and srfi-60.scm
from Guile 1.8, replace the (load-extension ...) calls in those two
files with (%init-srfi-1) and (%init-srfi-60), respectively.

   *crosses fingers*
 Mark



statically linking in srfi modules

2013-02-08 Thread Richard Shann
Is it possible to statically link in the srfi modules? For GNU/Denemo we
are currently trying http://mxe.cc to build for ms windows. Guile is
being built with --disable-shared and in consequence when denemo loads
srfi-1 the dynamic loading it does:
(load-extension libguile-srfi-srfi-1-v-3 scm_init_srfi_1)
fails.
If OTOH I put --enable-shared then the link fails lacking further shared
libraries libgmp libltdl libunistring libintl libiconv.

Can someone suggest how to proceed - there is no critical objection to
using shared libraries, but all those libraries are already built in mxe
as static libraries; is there a way to build guile with the srfi stuff
ready linked in?

Richard Shann





Re: statically linking in srfi modules

2013-02-08 Thread Richard Shann
Oh - sorry, I should have mentioned, we are still on guile 1.8 (perhaps
for no good reason?), if that affects the answer.

Richard

On Fri, 2013-02-08 at 09:24 +, Richard Shann wrote:
 Is it possible to statically link in the srfi modules? For GNU/Denemo we
 are currently trying http://mxe.cc to build for ms windows. Guile is
 being built with --disable-shared and in consequence when denemo loads
 srfi-1 the dynamic loading it does:
 (load-extension libguile-srfi-srfi-1-v-3 scm_init_srfi_1)
 fails.
 If OTOH I put --enable-shared then the link fails lacking further shared
 libraries libgmp libltdl libunistring libintl libiconv.
 
 Can someone suggest how to proceed - there is no critical objection to
 using shared libraries, but all those libraries are already built in mxe
 as static libraries; is there a way to build guile with the srfi stuff
 ready linked in?
 
 Richard Shann
 





Re: statically linking in srfi modules

2013-02-08 Thread Richard Shann
I succeeded in linking Denemo with the call 

scm_c_register_extension (libguile-srfi-srfi-1-v-3, scm_init_srfi_1,
 scm_init_srfi_1, NULL);
inserted right at the beginning of inner_main (the  value passed to
scm_boot_guile, that is), but disappointingly I still get the error
message when srfi-1 tries to dynamically load 

libguile-srfi-srfi-1-v-3 The specified module could not be found.

I found some documentation on this call at
http://mulliken.chem.hope.edu/cgi-bin/info2www.cgi?(guile)Extensions

and it indicated the first argument could be NULL, which would reduce
the danger of a typo in that string causing trouble, but alas with NULL
the same error message occurs. I have checked that scm_init_srfi_1 is a
genuinely non-null pointer, so I don't quite know where to go next. I
have gdb running on the windows box (again, thanks to the mxe
cross-compilation project), but perhaps someone can spare me tracking
through the libguile-srfi-srfi-1-v-3.a code?

Richard


On Fri, 2013-02-08 at 12:27 +0100, Andy Wingo wrote:
 On Fri 08 Feb 2013 10:25, Richard Shann richard.sh...@virgin.net
 writes:
 
  On Fri, 2013-02-08 at 09:24 +, Richard Shann wrote:
  Is it possible to statically link in the srfi modules?
  (load-extension libguile-srfi-srfi-1-v-3 scm_init_srfi_1)
  fails.
 
 You can link it in I think, but then you will need to call
 
   scm_c_register_extension (libguile-srfi-srfi-1-v-3,
 scm_init_srfi_1,
  scm_init_srfi_1, NULL)
 
 somewhere in your C code.
 
 




Re: statically linking in srfi modules

2013-02-08 Thread Mark H Weaver
I wrote:

 Richard Shann richard.sh...@virgin.net writes:

 libguile-srfi-srfi-1-v-3 The specified module could not be found.

 The problem is the call to 'load-extension' near the top of
 'srfi-1.scm', which again tries to load that shared library.
 You'll have to remove that call from 'srfi-1.scm'.

 You should probably do the same thing for libguile-srfi-srfi-13-14-v-3,
 so that Denemo users who wish to use the string or character set
 libraries can do so.

Sorry, I was mistaken.  It turns out that srfi-13-14 was moved into the
core a while ago, and that shared library is just an empty dummy
library.  The same is true of srfi-4.

However, there's also a shared library for srfi-60, which should be
statically linked as well.  Just as for srfi-1, the call to
'load-extension' should be removed from srfi-60.scm, and you should add
the following to your C initialization code:

  scm_c_register_extension (libguile-srfi-srfi-60-v-2, scm_init_srfi_60,
 scm_init_srfi_60, NULL);

Regards,
  Mark



Re: statically linking in srfi modules

2013-02-08 Thread Richard Shann
Thank you very much - that does indeed fix the module loading problem.
As always, there is one last glitch. It seems that internationalization
is missing - no _ symbol for translating strings.
But I'll leave that until tomorrow to investigate - I just wanted to
thank you all very much for the rapid response.
Richard

On Fri, 2013-02-08 at 17:11 -0500, Mark H Weaver wrote:
 I wrote:
 
  Richard Shann richard.sh...@virgin.net writes:
 
  libguile-srfi-srfi-1-v-3 The specified module could not be found.
 
  The problem is the call to 'load-extension' near the top of
  'srfi-1.scm', which again tries to load that shared library.
  You'll have to remove that call from 'srfi-1.scm'.
 
  You should probably do the same thing for libguile-srfi-srfi-13-14-v-3,
  so that Denemo users who wish to use the string or character set
  libraries can do so.
 
 Sorry, I was mistaken.  It turns out that srfi-13-14 was moved into the
 core a while ago, and that shared library is just an empty dummy
 library.  The same is true of srfi-4.
 
 However, there's also a shared library for srfi-60, which should be
 statically linked as well.  Just as for srfi-1, the call to
 'load-extension' should be removed from srfi-60.scm, and you should add
 the following to your C initialization code:
 
   scm_c_register_extension (libguile-srfi-srfi-60-v-2, scm_init_srfi_60,
  scm_init_srfi_60, NULL);
 
 Regards,
   Mark





Re: statically linking in srfi modules

2013-02-08 Thread Ludovic Courtès
Mark H Weaver m...@netris.org skribis:

 The problem is the call to 'load-extension' near the top of
 'srfi-1.scm', which again tries to load that shared library.
 You'll have to remove that call from 'srfi-1.scm'.

Actually ltdl supports “preloaded libraries”, but that would mean
reworking 1.8’s build system to use it (see
http://thread.gmane.org/gmane.lisp.guile.devel/7897).

Ludo’.




Re: use-modules: selecting, which symbols not to load

2013-01-06 Thread Ian Price
Panicz Maciej Godek godek.mac...@gmail.com writes:

 What I've been lacking is specifying symbols that are NOT meant
 to be imported from a module.
 So I'd wish to be able to load modules in the following manner:

 (use-modules ((rnrs) #:version (6) #:without (write display)))

While I see this is resolved now[0], but one option you could have
considered was using the R6RS import form directly, which has an except
clause. i.e.

(import (except (rnrs) write display))

The import form is exported as part of the syntax case module, and so
usable in any guile program.

It may, however, be confusing to some people if you mix-and-match module
forms.


0. I've been away from the mailing list, and so am only catching up today.
-- 
Ian Price -- shift-reset.com

Programming is like pinball. The reward for doing it well is
the opportunity to do it again - from The Wizardy Compiled



Re: use-modules: selecting, which symbols not to load

2012-12-31 Thread Mark H Weaver
l...@gnu.org (Ludovic Courtès) writes:
 Mark H Weaver m...@netris.org skribis:

 Although it is not documented, there's a way to do this:

 (use-modules ((rnrs) #:version (6) #:hide (write display)))

 Woow, I didn’t know that one.  Does someone want to document it?

I'll work on it.

Mark



Re: use-modules: selecting, which symbols not to load

2012-12-30 Thread Ludovic Courtès
Hi!

Mark H Weaver m...@netris.org skribis:

 Although it is not documented, there's a way to do this:

 (use-modules ((rnrs) #:version (6) #:hide (write display)))

Woow, I didn’t know that one.  Does someone want to document it?

Thanks,
Ludo’.




Re: use-modules: selecting, which symbols not to load

2012-12-27 Thread Thien-Thi Nguyen
() Panicz Maciej Godek godek.mac...@gmail.com
() Thu, 27 Dec 2012 04:43:16 +0100

   I think it can sometimes be desirable to import the whole public
   interface except certain bindings.

Could you give a non-contrived example?  I can't think of any, myself.
I remember toying w/ the idea when adding ‘#:renamer’, w/ same doubts.

   [...] and require me to change my header as the module changes.

Note that maintaining a blacklist and maintaining a whitelist is still
maintenance.  Better to ‘#:select’ exactly what you need and no more,
i.e., take a purely constructive stance.  That's maintenance, too, but
the eye work is locally concentrated, which builds Quality, rather than
broadly dispersed, which destroys (or, at best, delays) trust.  (IMHO.)

-- 
Thien-Thi Nguyen . GPG key: 4C807502
.  NB: ttn at glug dot org is not me   .
. (and has not been since 2007 or so)  .
.ACCEPT NO SUBSTITUTES .
... please send technical questions to mailing lists ...


pgp7dck6YpTGo.pgp
Description: PGP signature


Re: use-modules: selecting, which symbols not to load

2012-12-27 Thread Panicz Maciej Godek
2012/12/27 Thien-Thi Nguyen t...@gnuvola.org:
 () Panicz Maciej Godek godek.mac...@gmail.com
 () Thu, 27 Dec 2012 04:43:16 +0100

I think it can sometimes be desirable to import the whole public
interface except certain bindings.

 Could you give a non-contrived example?  I can't think of any, myself.
 I remember toying w/ the idea when adding ‘#:renamer’, w/ same doubts.

I recently had two similar cases, related with similar problem --
namely, with goops' generics. I wanted to use some features (I guess
those were bytevector features) from (rnrs) module, but I also
imported `write` and `display` procedures, which overrode the `write`
and `display` generics from goops. I knew that I wasn't using write
nor display from (rnrs) (because I didn't even realize their
existence), but I didn't remember which features exactly did I use.
Yesterday I had a similar case, because I was trying to make generics
from slot-ref and slot-set! so that I could be able to extend their
functionality, because I'm trying to extend the goops system to better
suit my needs -- so I'd wish, for instance, to be able to record
easily, which slots of an object have been modified -- and while I was
trying to manage it using macros (and introducing a `define*-class`
form with extended syntax), it occurred to me that using generics
would be much simpler.

[...] and require me to change my header as the module changes.

 Note that maintaining a blacklist and maintaining a whitelist is still
 maintenance.  Better to ‘#:select’ exactly what you need and no more,
 i.e., take a purely constructive stance.  That's maintenance, too, but
 the eye work is locally concentrated, which builds Quality, rather than
 broadly dispersed, which destroys (or, at best, delays) trust.  (IMHO.)

I have to say that I completely don't understand this point. I'd never
think, that 'precision' is the word that would apply to a module
system. For me, the module system should be convenient, rather than
'concentrated'. It's like if -- in a conversation -- you'd need to
specify which words you are going to use in which meaning beforehand,
before you even say anything meaningful.
Such symbols, as +, -, /, *, are available in scheme, even if you're
not using any arithmetics in your program. Is it this 'broad
dispersion' that you mentioned? I always get frustrated that I have to
(use-modules (ice-9 match) (srfi srfi-2)), because I use the 'match'
and 'and-let*' syntaxes as a part of the common logic of the language.
OK, maybe arithmetics is an exception. But it's really a surprise that
such procedures as inet-aton or select are available in the core
guile, because I'd rather expect to (use-modules (unix socket)) or
something like that, before using them.
But I'm used to thinking of modules as if they were (more or less
consistent) domains, so I would find it extremely irritating if I had
to say explicitly, which notions from that domain I want to use.

Thanks for your reply :)



Re: use-modules: selecting, which symbols not to load

2012-12-27 Thread Mark H Weaver
Panicz Maciej Godek godek.mac...@gmail.com writes:

 What I've been lacking is specifying symbols that are NOT meant
 to be imported from a module.
 So I'd wish to be able to load modules in the following manner:

 (use-modules ((rnrs) #:version (6) #:without (write display)))

Although it is not documented, there's a way to do this:

(use-modules ((rnrs) #:version (6) #:hide (write display)))

   Regards,
 Mark



use-modules: selecting, which symbols not to load

2012-12-26 Thread Panicz Maciej Godek
Hey,
I've been thinking about the ways `use-modules` can be used.
Namely, one can import selected symbols from a module, and
additionally can rename specified symbols.

What I've been lacking is specifying symbols that are NOT meant
to be imported from a module.
So I'd wish to be able to load modules in the following manner:

(use-modules ((rnrs) #:version (6) #:without (write display)))

I think it can sometimes be desirable to import the whole public
interface except certain bindings. Of course, similar effect could
be worked around by writing a smart renamer, such as
(use-modules ((rnrs) #:version (6)
  #:renamer (lambda(name)
 (if (or (equal? name 'write) (equal? name 'display))
(symbol-append 'unused: name)
name)))

but it's much more complicated, and it creates some unnecessary
garbage. If I really wanted to exclude those two symbols, I'd need
to import all the remaining symbols from the module, which would
be bothersome and require me to change my header as the module
changes.
Or maybe there is an easy way to exclude certain symbols from
import-list?

Best regards!



Re: I/O, modules

2012-11-13 Thread Ludovic Courtès
Hi,

thorso...@lavabit.com skribis:

 Could you show me some trivial programs related to I/O (e.g. read from
 file, convert to uppercase, write to another file)?

 This page [0] doesn't list a function that can be used to read the whole
 file at once. Is there a read-string function? What about read-port?

For textual I/O, search the manual for (ice-9 rdelim).  This module
provides a ‘read-line’ function, which reads a line from a port.

For binary I/O, search for (rnrs io ports).  You’ll get a variety of
procedures, including ‘get-bytevector-all’, which reads all of a ports
contents in memory.

 I created two files in the same dir:

 test-scm.scm:

 (define-module (test-scm)
   #:export (test-func))

 (define (test-func x)
   (+ x 1))

 import-test.scm:

 (define-module (import-test)
   #:use-module (test-scm))

 (display (test-func 2))

 Why does guile import-test.scm raise ERROR: no code for module
 (test-scm)?

Because ‘test-scm.scm’ is not in the search path.

The fix is to run:

  guile -L . import-test.scm

Thanks,
Ludo’.



Re: I/O, modules

2012-11-13 Thread Thien-Thi Nguyen
() thorso...@lavabit.com
() Tue, 13 Nov 2012 00:57:11 -0500 (EST)

   [...] to read the whole file at once.

   Should I import some module to get the above functions? Which one?

Personally, i would do:
-*- mode: compilation; default-directory: /tmp/ -*-
Compilation started at Tue Nov 13 10:04:09

cd /tmp ; cat upcase ; guile -s upcase upcase to ; echo =/= ; cat to
;;; upcase

(use-modules (ttn-do mogrify))

(define (upcase-file i o)
  (call-with-output-file o
(lambda (o)
  (display (string-upcase
(editing-buffer (find-file-read-only i)
  (buffer-string)))
   o

(apply upcase-file (cdr (command-line)))

;;; upcase ends here
=/=
;;; UPCASE

(USE-MODULES (TTN-DO MOGRIFY))

(DEFINE (UPCASE-FILE I O)
  (CALL-WITH-OUTPUT-FILE O
(LAMBDA (O)
  (DISPLAY (STRING-UPCASE
(EDITING-BUFFER (FIND-FILE-READ-ONLY I)
  (BUFFER-STRING)))
   O

(APPLY UPCASE-FILE (CDR (COMMAND-LINE)))

;;; UPCASE ENDS HERE

Compilation finished at Tue Nov 13 10:04:09

which (trivially) uses module (ttn-do mogrify) for input:
http://www.glug.org/software/ttn-do/ttn-do.html.gz#mogrify

If you grep ttn-do, you'll see other examples, most of which do more
inside ‘editing-buffer’ than outside.  In various versions of Guile,
there is module ‘(ice-9 gap-buffer)’, which is related technology.

   [...] problem with modules. How to check what can be imported?

You can ‘(set! %load-verbosely #t)’ to check.  On a deeper level, Guile
resolves a module name to a filename using var ‘%load-path’, which is
initialized from env var ‘GUILE_LOAD_PATH’ and command-line arg ‘-L DIR’
(one or more).  By default, cwd is excluded from these, for security.
Try to specify it explicitly, e.g.: guile -L . -s import-test.scm.

At least, this is my understanding of Guile 1.x -- maybe 2.0 differs.

[clickety click]

Hmm, i see you've successfully tempted me into passing a half hour
playing w/ this stuff.  Well done!  Might as well share the fruit.
;;; upcase
;;;
;;; Usage: guile -s upcase INFILE OUTSTEM
;;;
;;; Description: Upcase INFILE to both OUTSTEM-unsafe, OUTSTEM-safe{1,2}.

(use-modules (ttn-do mogrify))

(define (upcase-file i o)

  ;; unsafe: Output fails silently if ‘display’ does short ‘write’.
  ;; This occurs for some Guile versions, sometimes.
  (let ((o (string-append o -unsafe)))
(call-with-output-file o
  (lambda (o)
(display (string-upcase
  (editing-buffer (find-file-read-only i)
(buffer-string)))
 o

  ;; safe1: As long as you have the memory.  :-D
  (let ((o (string-append o -safe1)))
(editing-buffer (find-file i)
  (let ((new (string-upcase (buffer-string
(delete-region (point-min) (point-max))
(insert new))
  (write-to-port (open-output-file o

  ;; safe2: Like safe1, but w/ a more functional style.
  (let ((o (string-append o -safe2)))
(editing-buffer (string-upcase
 (editing-buffer (find-file-read-only i)
   (buffer-string)))
  (write-to-port (open-output-file o

  ;; Add more shouted mumblings here.
  )

(apply upcase-file (cdr (command-line)))

;;; upcase ends here

Poking around in ~/codebits/scheme, i also found this:
#!/usr/local/bin/guile \
-e main -s
!#

;;; ID: $Id: upcase.scm,v 1.3 1999/05/15 10:15:31 ttn Exp $

(define (toupper s)
  (list-string
   (map (lambda (c)
  (if (char-lower-case? c)
  (char-upcase c)
  c))
(string-list s

(define main
  (lambda args
(let r ((form (read-line)))
  (or (eof-object? form)
  (begin
(write-line (toupper form))
(r (read-line)
(quit)))

;;; $RCSfile: upcase.scm,v $$Revision: 1.3 $ ends here

It operates line at a time, which is nice for pipes, etc...  OK, enough!

-- 
Thien-Thi Nguyen . GPG key: 4C807502
.  NB: ttn at glug dot org is not me   .
. (and has not been since 2007 or so)  .
.ACCEPT NO SUBSTITUTES .
... please send technical questions to mailing lists ...


pgpX3j5PM2Wh8.pgp
Description: PGP signature


Re: I/O, modules

2012-11-13 Thread Mark H Weaver
thorso...@lavabit.com writes:
 Could you show me some trivial programs related to I/O (e.g. read from
 file, convert to uppercase, write to another file)?

There are many ways to do this, but here's a simple upcase program that
reads the entire file into memory and does not depend on any external
modules:

--8---cut here---start-8---
#!/usr/bin/guile \
-e main -s
!#

(use-modules (ice-9 match)
 (ice-9 rdelim))

(define (usage)
  (display Usage: upcase in-filename out-filename\n)
  (exit 1))

(define (upcase-file in-filename out-filename)
  (call-with-input-file in-filename
(lambda (in-port)
  (call-with-output-file out-filename
(lambda (out-port)
  (display (string-upcase (read-delimited  in-port))
   out-port))

(define (main args)
  (setlocale LC_ALL )
  (match args
((program in-filename out-filename)
 (upcase-file in-filename out-filename))
(_ (usage
--8---cut here---end---8---

 This page [0] doesn't list a function that can be used to read the whole
 file at once.

As shown in the upcase program above, (read-delimited  port) will read
the whole file as a string.  You need to (use-modules (ice-9 rdelim)) to
import this procedure.

Most of these procedures allow you to omit the 'port' argument, in which
case they will use (current-input-port) or (current-output-port).  Those
can be temporarily set within a block using 'with-input-from-file' and
'with-output-to-file'.  For example, 'upcase-file' above could be
written as follows:

   (define (upcase-file in-filename out-filename)
 (with-input-from-file in-filename
   (lambda ()
 (with-output-to-file out-filename
   (lambda ()
 (display (string-upcase (read-delimited 

To read one line from a file, use (read-line port), which is also from
(ice-9 rdelim).  For example, we can use this to modify the upcase
program to read and write one line at a time, so that it will use less
memory for large files (as long as the lines aren't too long):

   (define (upcase-file in-filename out-filename)
 (call-with-input-file in-filename
   (lambda (in-port)
 (call-with-output-file out-filename
   (lambda (out-port)
 (define (loop)
   (let ((line (read-line in-port 'concat)))
 (unless (eof-object? line)
   (display (string-upcase line) out-port)
   (loop
 (loop))

The 'concat argument to 'read-line' means that it should include the
end-of-line character(s), if any, in the returned string.  By default
they are stripped.

  Happy hacking!
  Mark



Re: I/O, modules

2012-11-13 Thread Mike Gran
 From: Mark H Weaver m...@netris.org

 
 As shown in the upcase program above, (read-delimited  port) will 
 read
 the whole file as a string.  You need to (use-modules (ice-9 rdelim)) to
 import this procedure.

Nice.  For reading entire files, I always ended up doing something like
the following (which does reveal how I think of everything in low-level C
constructs, I suppose.)

(use-modules (ice-9 rw))

(define (read-all port) (let loop ((block (make-string 32000))
(text ))
(let ((count (read-string!/partial block port)))
  (if count
  (loop block 
(string-append text (substring block 0 count)))
  text-Mike




Re: I/O, modules

2012-11-13 Thread tantalum
Hi

The (ice-9 streams) module could be interesting, too.
http://www.gnu.org/software/guile/manual/html_node/Streams.html

Example:
-
(import
  (ice-9 streams)
  (ice-9 rdelim))

(define (port-line-stream port handle-delim)
  (port-stream port (lambda (port) (read-line port handle-delim

(define (file-upcase source-path target-path)
  (call-with-input-file source-path
(lambda (source-file)
  (call-with-output-file target-path
(lambda (target-file)
  (stream-for-each
(lambda (line) (display (string-upcase line) target-file))
(port-line-stream source-file (quote concat


;test
(system echo test /tmp/file-upcase-test)
(file-upcase /tmp/file-upcase-test /tmp/file-upcase-test-out)
--
Where
  - Handle-delim specifies what should happen with the newline character. 
Default is to remove it
  - And display is Schemes standard string write procedure

I don't know of any existing generic file to string procedure.
Something similar to what I have used is:
---
(import
  (ice-9 streams)
  (ice-9 rdelim))

(define (port-line-stream port handle-delim)
  (port-stream port (lambda (port) (read-line port handle-delim

(define (file-string file)
  (apply string-append
(stream-list (port-line-stream file (quote concat)

(define (file-from-path-string path)
  (call-with-input-file path file-string))

(display (file-from-path-string /home/jkalbhenn/temp/temp.scm))
-

Julian



Re: I/O, modules

2012-11-13 Thread Ian Price
Mark H Weaver m...@netris.org writes:

 As shown in the upcase program above, (read-delimited  port) will read
 the whole file as a string.  You need to (use-modules (ice-9 rdelim)) to
 import this procedure.

A perhaps more lucid way is to use get-string-all from (rnrs io ports)

-- 
Ian Price -- shift-reset.com

Programming is like pinball. The reward for doing it well is
the opportunity to do it again - from The Wizardy Compiled



Re: I/O, modules

2012-11-13 Thread Ian Price
tanta...@gmx.net writes:

 The (ice-9 streams) module could be interesting, too.
 http://www.gnu.org/software/guile/manual/html_node/Streams.html

When it gets merged into master/stable-2.0, I'd suggest using (srfi
srfi-41) rather than (ice-9 streams). It cures the off-by-1 problems
that frequently occur with odd streams.

Another approach to stream based IO is called iteratees, as proposed
by Oleg Kiselyov.[0] I had started working on an implementation[1], but
it quite incomplete at the moment. Maybe one day...

0. http://okmij.org/ftp/Streams.html
1. https://github.com/ijp/iteratees/blob/master/iteratees.sls
-- 
Ian Price -- shift-reset.com

Programming is like pinball. The reward for doing it well is
the opportunity to do it again - from The Wizardy Compiled



I/O, modules

2012-11-12 Thread thorsopia
Hello,

Could you show me some trivial programs related to I/O (e.g. read from
file, convert to uppercase, write to another file)?

This page [0] doesn't list a function that can be used to read the whole
file at once. Is there a read-string function? What about read-port?

Should I import some module to get the above functions? Which one?

BTW, I have a problem with modules. How to check what can be imported?

For example:

I created two files in the same dir:

test-scm.scm:

(define-module (test-scm)
  #:export (test-func))

(define (test-func x)
  (+ x 1))

import-test.scm:

(define-module (import-test)
  #:use-module (test-scm))

(display (test-func 2))

Why does guile import-test.scm raise ERROR: no code for module
(test-scm)?

[0] https://gnu.org/software/guile/manual/guile.html#Reading





Re: Higher order modules: a first stab

2012-03-21 Thread Ludovic Courtès
Hello,

Sorry for the delay.

This looks nice.

Ian Price ianpric...@googlemail.com skribis:

 Currently, parameterized modules are functions that return a
 module, and functions are retrieved by module-ref. This is fine for a
 proof of concept, but hopefully I'll have something better integrated
 soon.

Would be cool to see how higher-order module support could be added to
our module system.

Something like:

  (define-module (seq-utils)
#:require (kar kdr)
#:export (take drop))

  ...

and:

  (define-module (srfi srfi-1)
#:use-module ((seq-utils) #:with (car cdr)))

  ...

  (define-module (ice-9 vlist)
#:use-module ((seq-utils) #:with (vlist-head vlist-tail)))

  ...

  (resolve-module '(seq-utils) #:with (list car cdr))
  = fresh module

  (resolve-module '(seq-utils))
  =| error

WDYT?

Thanks,
Ludo’.




Re: Problem with modules in Guile 2.0

2012-03-12 Thread Gubinelli Massimiliano
Hi Mark,

 I've update the svn repository and now the build process should recognize 
Guile 2.0. To build TeXmacs you will need the Qt framework, freetype and of 
course Guile. A standard

./configure --enable-qt
make

should suffice. You car run TeXmacs without installing by telling it where to 
find resources. Assuming you are 
in the source directory, after the make the executable is to be found in 
TeXmacs/bin, so the followng is enough

TEXMACS_PATH=$PWD/TeXmacs TeXmacs/bin/texmacs.bin

Scheme scripts are in TeXmacs/progs. 

The custom module macro is defined in kernel/boot/boot.scm
TeXmacs functions are defined via the tm-define macro defined in 
kernel/texmacs/tm-define.scm 

An example of contextual overloading allowed by tm-define : (from 
kernel/math/math-edit.scm:44)

(tm-define (kbd-enter t shift?)
  (:require (tree-is? t 'equation))
  (go-end-of 'equation)
  (insert-return))

here we redefine the function kdb-enter in the case the :require condition 
results #t. The new definition is simply added by the tm-define macro at the 
top of the previous with a conditional statement. I do not know if this can 
cause interferences with compilation. 

General documentation about TeXmacs is written in the TeXmacs document format 
and you can find it in the TeXmacs help menu (Help-Scheme extensions). The 
documentation on the main web page (www.texmacs.org) does not contain the 
chapters about the scheme interface. 

Maybe we should continue this discussion in private, without polluting the 
mailing list.

Massimiliano

On Mar 11, 2012, at 9:38 PM, Mark H Weaver wrote:

 Gubinelli Massimiliano m.gubine...@gmail.com writes:
 Why not convert your scripts to use the standard Guile module syntax?
 
 TeXmacs is currently composed of 250 scheme files for \sim 6 lines
 of scheme.
 
 Fair enough.  I see no obstacle to adapting the TeXmacs module system to
 work with Guile 2.  It's just a matter of finding the cleanest way to
 implement it.
 
 It has a slightly customized module system and features contextual
 overloading of functions (a function can be redefined to act
 differently is some condition is met without modifying the module
 which implemented the base behaviour). We would like to preserve the
 current system as much as possible.
 
 Can you provide some specific examples of this contextual overloading of
 functions, so that I might understand this feature more clearly?
 Pointers to relevant documentation would also be helpful.
 
 With the current svn you will not be able to build TeXmacs with Guile
 2.0. If you are interested in that I will tell you how to do.
 
 Please do.  I would like to try to build TeXmacs with Guile 2, so that I
 may better help you with the transition to Guile 2.
 
 Thanks,
   Mark



Re: Problem with modules in Guile 2.0

2012-03-11 Thread Mark H Weaver
Gubinelli Massimiliano m.gubine...@gmail.com writes:
 Why not convert your scripts to use the standard Guile module syntax?

 TeXmacs is currently composed of 250 scheme files for \sim 6 lines
 of scheme.

Fair enough.  I see no obstacle to adapting the TeXmacs module system to
work with Guile 2.  It's just a matter of finding the cleanest way to
implement it.

 It has a slightly customized module system and features contextual
 overloading of functions (a function can be redefined to act
 differently is some condition is met without modifying the module
 which implemented the base behaviour). We would like to preserve the
 current system as much as possible.

Can you provide some specific examples of this contextual overloading of
functions, so that I might understand this feature more clearly?
Pointers to relevant documentation would also be helpful.

 With the current svn you will not be able to build TeXmacs with Guile
 2.0. If you are interested in that I will tell you how to do.

Please do.  I would like to try to build TeXmacs with Guile 2, so that I
may better help you with the transition to Guile 2.

 Thanks,
   Mark



Higher order modules: a first stab

2012-03-09 Thread Ian Price

Hi guilers,

I've been musing over the concept of higher order modules (modules
parameterized by other modules) in the back of my mind, and am
occasionally making steps towards implementing it in guile. I think that
with guile's first class modules all the machinery is there, it's just a
question of figuring out the best way to do it. The advantage for users
of guile is that it provides a different, and hopefully useful, form of
code reuse.

Here is the first step towards it that I made.

;;; higher order modules for guile

(define-syntax-parameter provide ; an export for `module' forms
  (lambda (stx)
(syntax-violation 'provide provide used outside a module form stx)))

(define-syntax module
  (lambda (stx)
(syntax-case stx ()
  ((module (params ...) body ...)
   (with-syntax (((tmp ...) (generate-temporaries #'(params ...
 #'(lambda (tmp ...)
 (define fresh (make-fresh-user-module))
 (module-use! fresh (resolve-interface '(guile)))
 (save-module-excursion
  (lambda ()
(set-current-module fresh)
(let ((export-alist '()))
  (syntax-parameterize ((provide (syntax-rules ()
   ((provide foo bar (... ...))
(set! export-alist
  (append (list
   (cons 'foo 
foo)
   (cons 'bar 
bar)
   (... 
...
(define params tmp) ...
body ...
(map (lambda (pair)
   (let ((var (car pair))
 (val (cdr pair)))
 (module-define! fresh var val)))
 export-alist)
 fresh))

;; example module
(define stream-utils
  (module (stream-car stream-cdr)
(define (stream-drop s n)
  (if (zero? n)
  s
  (stream-drop (stream-cdr s) (- n 1
(define (stream-take s n)
  (if (zero? n)
  '()
  (cons (stream-car s)
(stream-take (stream-cdr s) (- n 1)
(provide stream-drop stream-take)))

;; first stream implementation
;; Stream a = Stream b (b - a) (b - Stream a)

(import (rnrs records syntactic))

(define-record-type stream
  (fields val this next))

(define (stream-car stream)
  ((stream-this stream) (stream-val stream)))

(define (stream-cdr stream)
  ((stream-next stream) (stream-val stream)))

(define (constant-stream k)
  (define (next k)
(make-stream k identity next))
  (next k))

(define naturals
  (letrec ((next (lambda (current)
   (make-stream (+ 1 current) identity next
(next -1)))

(define stream-module (stream-utils stream-car stream-cdr))
(define stream-take (module-ref stream-module 'stream-take))

(stream-take naturals 10) ;;(0 1 2 3 4 5 6 7 8 9)


;; second stream implementation
(use-modules ((ice-9 streams)
  #:renamer (symbol-prefix-proc 's:)))

(define naturals2 (s:make-stream (lambda (x)
   (cons x (1+ x)))
 0))

(define stream-module2 (stream-utils s:stream-car s:stream-cdr))
(define stream-take2 (module-ref stream-module2 'stream-take))

(stream-take2 naturals2 10)


Currently, parameterized modules are functions that return a
module, and functions are retrieved by module-ref. This is fine for a
proof of concept, but hopefully I'll have something better integrated
soon.

Thanks to wingo for suggesting the current method of providing exports

-- 
Ian Price

Programming is like pinball. The reward for doing it well is
the opportunity to do it again - from The Wizardy Compiled




Re: Problem with modules in Guile 2.0

2012-03-09 Thread Mark H Weaver
Gubinelli Massimiliano m.gubine...@gmail.com writes:

 Hi Mark,
  thanks again. I start to understand better the Guile 2 compile
 system. I decided to dig into boot-9.scm to have a more precise idea
 of the ecosystem around my scripts. Unfortunately it seems that the
 basic TeXmacs scripting infrastructure need a major change to be run
 into Guile 2.0 and I'm afraid not to be sufficiently proficient in
 scheme to do this in a short time.

Why not convert your scripts to use the standard Guile module syntax?

 Is there anyone on this list which would like to assist me to port GNU
 TeXmacs to Guile 2.0. Currently the code in svn builds fine against
 2.0 so the problem is just to adapt the scheme scripts which rely on a
 customized module system.

I'd be glad to take a look.  Where can I find your scripts?

   Regards,
 Mark



Re: Problem with modules in Guile 2.0

2012-03-09 Thread Gubinelli Massimiliano
Hi Mark,

On Mar 9, 2012, at 5:29 PM, Mark H Weaver wrote:

 Gubinelli Massimiliano m.gubine...@gmail.com writes:
 
 Hi Mark,
 thanks again. I start to understand better the Guile 2 compile
 system. I decided to dig into boot-9.scm to have a more precise idea
 of the ecosystem around my scripts. Unfortunately it seems that the
 basic TeXmacs scripting infrastructure need a major change to be run
 into Guile 2.0 and I'm afraid not to be sufficiently proficient in
 scheme to do this in a short time.
 
 Why not convert your scripts to use the standard Guile module syntax?
 

TeXmacs is currently composed of 250 scheme files for \sim 6 lines of 
scheme. Guile is used for customization and for other operations which do not 
require special performance. All the rest of the program is written in C++, in 
particular the typesetter and the GUI code. It has a slightly customized module 
system and features contextual overloading of functions (a function can be 
redefined to act differently is some condition is met without modifying the 
module which implemented the base behaviour). We would like to preserve the 
current system as much as possible. Moreover we want also to be compatible with 
previous versions of Guile (now we support Guile 1.4 up to Guile 1.8). The code 
does not depend very much on specific Guile features a part form the module 
system.

 Is there anyone on this list which would like to assist me to port GNU
 TeXmacs to Guile 2.0. Currently the code in svn builds fine against
 2.0 so the problem is just to adapt the scheme scripts which rely on a
 customized module system.
 
 I'd be glad to take a look.  Where can I find your scripts?
 

TeXmacs codebase is hosted at savannan 
(https://savannah.gnu.org/projects/texmacs/).  Check out the svn trunk  via

svn co svn://svn.savannah.gnu.org/texmacs/trunk

then you can find the scheme script in trunk/src/TeXmacs/progs

at boot C++ evaluate init-texmacs.scm which in turn bootstrap the custom module 
system defined in kernel/boot.scm and start to load modules. We have a facility 
to lazy load modules since in old machines the bootstrap of the scheme code is 
too slow. 
With the current svn you will not be able to build TeXmacs with Guile 2.0. If 
you are interested in that I will tell you how to do.

I still do not know very well the scheme code (almost all of it has been 
written by the main developer, Joris van der Hoeven). 

Massimiliano

   Regards,
 Mark




Re: Problem with modules in Guile 2.0

2012-03-08 Thread Gubinelli Massimiliano
Hi Mark,
 thanks again. I start to understand better the Guile 2 compile system. I 
decided to dig into boot-9.scm to have a more precise idea of the ecosystem 
around my scripts. Unfortunately it seems that the basic TeXmacs scripting 
infrastructure need a major change to be run into Guile 2.0 and I'm afraid not 
to be sufficiently proficient in scheme to do this in a short time. Is there 
anyone on this list which would like to assist me to port GNU TeXmacs to Guile 
2.0. Currently the code in svn builds fine against 2.0 so the problem is just 
to adapt the scheme scripts which rely on a customized module system. If you 
are interested you can contact me privately. In the meantime I will dig into 
the code hoping to find illumination among parentheses….

best
max


On Mar 8, 2012, at 3:01 AM, Mark H Weaver wrote:

 Gubinelli Massimiliano m.gubine...@gmail.com writes:
 
 Thanks for the prompt reply to both of you. However the proposed
 solution do not work in my case.
 
 I think it _did_ solve your original problem, but now you have moved on
 to other unrelated problems.
 
 After implementing the
 begin-for-syntax alternative I now get
 
 scheme@(guile-user) (load main.scm)
 ;;; compiling /Users/mgubi/t/build-64-guile-2.0/test-modules/main.scm
 ;;; note: source file 
 /Users/mgubi/t/build-64-guile-2.0/test-modules/test-modules.scm
 ;;; newer than compiled
 /Users/mgubi/.cache/guile/ccache/2.0-LE-8-2.0/Users/mgubi/t/build-64-guile-2.0/test-modules/test-modules.scm.go
 ;;; compiling /Users/mgubi/t/build-64-guile-2.0/test-modules/test-modules.scm
 ;;;
 /Users/mgubi/t/build-64-guile-2.0/test-modules/test-modules.scm:15:34:
 warning: possibly unbound variable `compile-interface-spec'
 
 Note that 'compile-interface-spec' was an undocumented internal
 procedure of Guile 1.x, and no longer exists in Guile 2.
 
 ;;; /Users/mgubi/t/build-64-guile-2.0/test-modules/test-modules.scm:32:11: 
 warning: possibly unbound variable `:use'
 ;;; /Users/mgubi/t/build-64-guile-2.0/test-modules/test-modules.scm:33:11: 
 warning: possibly unbound variable `:inherit'
 ;;; /Users/mgubi/t/build-64-guile-2.0/test-modules/test-modules.scm:34:11: 
 warning: possibly unbound variable `:export'
 
 In order to use the shorter keyword syntax ':use' (instead of '#:use'),
 you must set the prefix keywords reader option.  Put the following at
 the beginning of your 'begin-for-syntax' form:
 
  (read-set! keywords 'prefix)
 
 ;;; compiled 
 /Users/mgubi/.cache/guile/ccache/2.0-LE-8-2.0/Users/mgubi/t/build-64-guile-2.0/test-modules/test-modules.scm.go
 ;;; WARNING: compilation of 
 /Users/mgubi/t/build-64-guile-2.0/test-modules/main.scm failed:
 ;;; ERROR: No variable named %module-public-interface in #directory (sub 
 mymodule) 10507ed80
 ERROR: In procedure scm-error:
 ERROR: No variable named %module-public-interface in #directory (sub 
 mymodule) 10507ed80
 
 Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
 scheme@(guile-user) [1] 
 
 if I understand correctly this backtrace it seems that the module is
 not completely loaded at compile time and there is not public
 interface available. How can I force the evaluation of the loaded
 modules in order to get a list of exported symbols?
 
 I cannot reproduce this.  When I try using your example code, Guile
 2.0.5 tries to compile (sub mymodule).  Are you sure that you remembered
 to set GUILE_LOAD_PATH during this test run?
 
 This is what I see:
 
  GNU Guile 2.0.5
  Copyright (C) 1995-2012 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) (load main.scm)
  ;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
  ;;;   or pass the --no-auto-compile argument to disable.
  ;;; compiling /home/mhw/guile-modules/main.scm
  ;;; compiling /home/mhw/guile-modules/./test-modules.scm
  ;;; test-modules.scm:15:34: warning: possibly unbound variable 
 `compile-interface-spec'
  ;;; compiled 
 /home/mhw/.cache/guile/ccache/2.0-LE-4-2.0/home/mhw/guile-modules/test-modules.scm.go
  ;;; compiling /home/mhw/guile-modules/sub/mymodule.scm
  ;;; sub/mymodule.scm:1:0: warning: possibly unbound variable `texmacs-module'
  ;;; sub/mymodule.scm:1:16: warning: possibly unbound variable `sub'
  ;;; sub/mymodule.scm:1:16: warning: possibly unbound variable `mymodule'
  ;;; compiled 
 /home/mhw/.cache/guile/ccache/2.0-LE-4-2.0/home/mhw/guile-modules/sub/mymodule.scm.go
  ;;; WARNING: compilation of /home/mhw/guile-modules/main.scm failed:
  ;;; ERROR: In procedure module-lookup: Unbound variable: texmacs-module
  sub/mymodule.scm:1:0: In procedure #procedure 1058ebb0 ():
  sub/mymodule.scm:1:0: In procedure module-lookup: Unbound variable: 
 texmacs-module
 
  Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
  scheme@(#{ g435

Re: Problem with modules in Guile 2.0

2012-03-07 Thread Andy Wingo
Hi!

Mark gave great answers; I just wanted to give one more option:

On Tue 06 Mar 2012 22:48, Gubinelli Massimiliano m.gubine...@gmail.com writes:

 (load test-modules.scm)

Add a definition first:

  (cond-expand
   (guile-2
(define-syntax-rule (begin-for-syntax form ...)
  (eval-when (load compile eval) (begin form ...
   (else
(define begin-for-syntax begin)))

Then:

  (begin-for-syntax
   (load test-modules.scm))

Regards,

Andy
-- 
http://wingolog.org/



Re: Problem with modules in Guile 2.0

2012-03-07 Thread Gubinelli Massimiliano
Thanks for the prompt reply to both of you. However the proposed solution do 
not work in my case. After implementing the begin-for-syntax alternative I now 
get

scheme@(guile-user) (load main.scm)
;;; compiling /Users/mgubi/t/build-64-guile-2.0/test-modules/main.scm
;;; note: source file 
/Users/mgubi/t/build-64-guile-2.0/test-modules/test-modules.scm
;;;   newer than compiled 
/Users/mgubi/.cache/guile/ccache/2.0-LE-8-2.0/Users/mgubi/t/build-64-guile-2.0/test-modules/test-modules.scm.go
;;; compiling /Users/mgubi/t/build-64-guile-2.0/test-modules/test-modules.scm
;;; /Users/mgubi/t/build-64-guile-2.0/test-modules/test-modules.scm:15:34: 
warning: possibly unbound variable `compile-interface-spec'
;;; /Users/mgubi/t/build-64-guile-2.0/test-modules/test-modules.scm:32:11: 
warning: possibly unbound variable `:use'
;;; /Users/mgubi/t/build-64-guile-2.0/test-modules/test-modules.scm:33:11: 
warning: possibly unbound variable `:inherit'
;;; /Users/mgubi/t/build-64-guile-2.0/test-modules/test-modules.scm:34:11: 
warning: possibly unbound variable `:export'
;;; compiled 
/Users/mgubi/.cache/guile/ccache/2.0-LE-8-2.0/Users/mgubi/t/build-64-guile-2.0/test-modules/test-modules.scm.go
;;; WARNING: compilation of 
/Users/mgubi/t/build-64-guile-2.0/test-modules/main.scm failed:
;;; ERROR: No variable named %module-public-interface in #directory (sub 
mymodule) 10507ed80
ERROR: In procedure scm-error:
ERROR: No variable named %module-public-interface in #directory (sub mymodule) 
10507ed80

Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
scheme@(guile-user) [1] 

if I understand correctly this backtrace it seems that the module is not 
completely loaded at compile time and there is not public interface available. 
How can I force the evaluation of the loaded modules in order to get a list of 
exported symbols?

Best
massimiliano




On Mar 7, 2012, at 9:32 PM, Andy Wingo wrote:

 Hi!
 
 Mark gave great answers; I just wanted to give one more option:
 
 On Tue 06 Mar 2012 22:48, Gubinelli Massimiliano m.gubine...@gmail.com 
 writes:
 
 (load test-modules.scm)
 
 Add a definition first:
 
  (cond-expand
   (guile-2
(define-syntax-rule (begin-for-syntax form ...)
  (eval-when (load compile eval) (begin form ...
   (else
(define begin-for-syntax begin)))
 
 Then:
 
  (begin-for-syntax
   (load test-modules.scm))
 
 Regards,
 
 Andy
 -- 
 http://wingolog.org/

On Mar 7, 2012, at 9:32 PM, Andy Wingo wrote:

 Hi!
 
 Mark gave great answers; I just wanted to give one more option:
 
 On Tue 06 Mar 2012 22:48, Gubinelli Massimiliano m.gubine...@gmail.com 
 writes:
 
 (load test-modules.scm)
 
 Add a definition first:
 
  (cond-expand
   (guile-2
(define-syntax-rule (begin-for-syntax form ...)
  (eval-when (load compile eval) (begin form ...
   (else
(define begin-for-syntax begin)))
 
 Then:
 
  (begin-for-syntax
   (load test-modules.scm))
 
 Regards,
 
 Andy
 -- 
 http://wingolog.org/




  1   2   >