<br><br><div class="gmail_quote">El 5 de febrero de 2010 14:17, Álvaro Castro-Castilla <span dir="ltr"><<a href="mailto:alvaro.castro.castilla@gmail.com">alvaro.castro.castilla@gmail.com</a>></span> escribió:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<div class="gmail_quote">El 5 de febrero de 2010 13:25, Mikael <span dir="ltr"><<a href="mailto:mikael.trash@gmail.com" target="_blank">mikael.trash@gmail.com</a>></span> escribió:<div><div></div><div class="h5"><br>

<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Then  (import nameofyourlibrary), presuming it is located in nameofyourlibrary.scm in your current working directory. (module-compile! 'nameofyourlibrary) it first if it does not contain C FFI calls (which would force compile on import) and you want it compiled.<br>



<br><div class="gmail_quote"><div>2010/2/5 Álvaro Castro-Castilla <span dir="ltr"><<a href="mailto:alvaro.castro.castilla@gmail.com" target="_blank">alvaro.castro.castilla@gmail.com</a>></span><br></div>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="gmail_quote">El 5 de febrero de 2010 10:51, Per Eckerdal <span dir="ltr"><<a href="mailto:per.eckerdal@gmail.com" target="_blank">per.eckerdal@gmail.com</a>></span> escribió:<div><div></div><div>
<div><div></div><div>
<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<br>
5 feb 2010 kl. 01.25 skrev Álvaro Castro-Castilla:<br>
<div><br>
> Hi!<br>
><br>
> I'm new to this list and also to Gambit. I'm trying to get used to it, and I like most of the things very much (taking into account that I'm new to Scheme).<br>
><br>
> I'm trying to use Black Hole module system, and I've found out something that I don't understand how it works or what I'm doing wrong.<br>
><br>
> If you have this scheme file, called for example "bhtest.scm"<br>
><br>
> (load "/usr/lib/modules/build")<br>
> (import (std srfi/14))<br>
><br>
><br>
> and you try to execute it with "gsc -i bhtest.scm", you'll get this:<br>
><br>
> *** ERROR IN "blackhole.scm"@3.2 -- Unbound variable: import<br>
<br>
</div>I think a clarification to why this doesn't work (and the same code in the REPL does) would be helpful not only to understand Black Hole, but also other similar issues.<br>
<br>
When you type the load expression into the REPL, Gambit will load Black Hole, and Black Hole will override two hooks, ##expand-source and c#expand-source. These two functions are by default the identity function (that is, (lambda (x) x)). ##expand-source is called every time code is evaluated, and Black Hole adds its macro expander there.<br>






<br>
After loading BH in the REPL, BH's macro expander will be there, so in the next line, when you type (import ...), BH will recognize it and take proper action.<br>
<br>
However, when loading a file containing both (load "/usr/lib/modules/build") and (import (std srfi/14)), what will happen is that Gambit will parse the whole file, then call ##expand-source on the resulting s-expression, then eval that expression. Black Hole will get loaded, but when it is, the whole file's code will already have been macro-expanded, so the import will be seen as a normal procedure call, which obviously won't work.<br>






<br>
This is a kind problem that many people that are new to Gambit (and probably other implementations of Scheme as well) seem to have. The difference between typing something into the REPL, load-ing a file with the same expressions, or include-ing a file is not very easy to understand at first.<br>






<br>
For me, it helped to think like this (it's not entirely correct, but kind of): It's possible to implement both load and include, assuming that read-file is a function that reads a file's s-exps and wraps them in a begin, as an example would bhtest.scm yield (begin (load "/usr/lib/modules/build") (import (std srfi/14)))<br>






<br>
(define (load filename)<br>
  (eval (read-file filename)))<br>
<br>
(define-macro (include filename)<br>
  (read-file filename))<br>
<br>
<br>
The main reason why you're not supposed to have a load expression inside of your scheme files is that I have tried hard to design BH in a way that makes it easy to share code. Having a load expression in the beginning of each file would ruin that, because everyone will not have BH installed at the same place. Also, this ensures that very simple code is kept very simple and clean, yet it will scale and still be useful in larger applications. An example of a typical BH module is a simple FIFO queue library that I have written:<br>






<br>
<a href="http://github.com/pereckerdal/blackhole-libs/blob/master/ds/queue.scm" target="_blank">http://github.com/pereckerdal/blackhole-libs/blob/master/ds/queue.scm</a><br>
<br>
It's possible to import it like this: (import "<a href="http://github.com/pereckerdal/blackhole-libs/raw/master/ds/queue.scm" target="_blank">http://github.com/pereckerdal/blackhole-libs/raw/master/ds/queue.scm</a>")<br>






<br>
<br>
This mail turned out somewhat messy, I hope it helps.<br>
<font color="#888888"><br>
/Per<br>
<br>
</font></blockquote></div></div></div></div></div><div><div></div><div><br>Thanks a lot for your explanations!<br><br>It works with the code that you said in the .gambcini<br>I understand now the reasons why it doesn't work, it makes sense.<br>


What I don't fully understand is why I'm not supposed to use "loads" now anymore... At the moment, I was compiling bindings and some "libraries" that I needed to use, to speed up the code, how am I supposed to deal with that now? (they were not done thinking in Black Hole, but they don't use any namespaces functionality, AFAIK).<br>





<br>Thanks again for your prompt response.<br><font color="#888888"><br>Álvaro Castro-Castilla<br>
</font><br></div></div><div>_______________________________________________<br>
Gambit-list mailing list<br>
<a href="mailto:Gambit-list@iro.umontreal.ca" target="_blank">Gambit-list@iro.umontreal.ca</a><br>
<a href="https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list" target="_blank">https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list</a><br>
<br></div></blockquote></div><br>
</blockquote></div></div></div><br><br>It seems I can compile modules in this way, but I stilla have problems:<br><br>I'm working now in opengl bindings, taken from Space Invaders. I have a file called opengl.scm, and other called opengl-header.scm<br>


opengl.scm imports opengl-header.scm,<br>then a test module imports (or compile-module!) opengl.scm<br><br>A) If I use import, it says that c-lambda is not available in interpreted mode. But then I'm trying with compile-modules!<br>


However, it tries to write to /usr/lib/modules/ns.dat, and I don't have the permission. Using this compiler option:<br><br>bsc -:~~DIR=/data/projects/scheme -i<br><br>doesn't help.<br><br>*** ERROR IN module#save-ns-table, "/usr/lib64/modules/module.scm"@730.3 -- Permission denied<br>


(with-output-to-file "~~/lib/modules/ns.dat" '#<procedure #2>)<br><br>B) If I execute it again (with compile-module, as "import" doesn't work), I get another o2, and then o3, o4...<br><br>


<br>What I want is just a method to work with BH so I can have the FFI modules compiled (and, if possible also some other big libraries, such as SSAX-SXML) and then being able to run interpreted the rest of the program.<br>


<br><br><br>Thanks for all your help<br><br>
</blockquote></div><br>I think force-compile did B<br><br>but I still can't fix A.<br>