Re: [CM] R7RS support

2022-01-17 Thread mike
Thanks Iain, great observations and info. Yes, we’ve read s7.html many 
times and will continue to do so. There’s a lot of great info there! 
(We’ve found many of the included scm files are also good sources 
too.)


FYI, we’re looking at adopting R7RS more as a future-proofing strategy 
than “we need every single feature and exact compatibility”. Having 
successfully shipped some basic functionality on iOS as a 
proof-of-concept, we’re stepping back and tweaking our development 
environment & tooling. Currently we’re attempting to run our code with 
Guile and its R7RS libraries, in part to take advantage of the nice 
tooling in Geiser in Emacs. The goal is to have our integration & unit 
tests run in both s7 and Guile (and/or other R7RS-compatible Schemes) 
with minimal shim layers. If we can keep the ease of embedding, small 
size and performance of s7 for mobile while doing this, then dare I say 
we’ll have our cake and eat it too? :)


Cheers, Michael

On 17 Jan 2022, at 23:52, Iain Duncan wrote:

Hi Rudolf, Bill would be the person to address this better than me, 
but I
think the Egghead team should read through the s7.html page pretty 
closely

to see if s7 is a good fit. It's pretty clear in there that there is
*limited* R7RS compatibility, but that s7 is not R7RS and nor is that 
a

stated goal. For example, s7 does not do macros with syntax-case or
syntax-rules, but uses CL style macros. If R7RS is what you need, you 
might
be better off with an implementation that makes that a goal, such as 
Chibi.

I use s7 embedded in audio programs, which shares a fair bit of domain
space with games, and I personally chose s7 because the performance 
and

ease of embedding made up for that, but YMMV!

HTH
iain

On Mon, Jan 17, 2022 at 7:36 AM Rudolf Adamkovič  
wrote:



Hi there!

At Egghead Games, we would like to use Scheme for in-app scripting.  
We
wired up s7 and SQLite to kick things off, but s7 support for R7RS 
does

not seem to work.  Below, I include some examples to illustrate my
point.

A basic example from the R7RS standard, page 54, …

(with-exception-handler
(lambda (x)
  (display "something went wrong\n"))
  (lambda ()
(+ 1 (raise ’an-error

… results in:

Error: catch error handler should accept two arguments: #(x)>


The simplest library …

(load "r7rs.scm")
(define-library (some lib)
  (export some-proc)
  (import (scheme base)
  (scheme r5rs))
  (begin
(define (some-proc x)
  (display x

… results in:

Error: symbol->value first argument, {gensym}-1, is a macro but 
should

be a symbol (define-macro ({gensym}-1 . names)...


We picked s7 because the website says …


I believe it is compatible with r5rs and r7r


… but per a quick grep, there seem to exist no tests for 
define-library

or with-exception-handler.

Any ideas?

Rudy
--
"Logic is a science of the necessary laws of thought, without which 
no
employment of the understanding and the reason takes place." -- 
Immanuel

Kant, 1785

Rudolf Adamkovič  [he/him]
Studenohorská 25
84103 Bratislava
Slovakia

___
Cmdist mailing list
Cmdist@ccrma.stanford.edu
https://cm-mail.stanford.edu/mailman/listinfo/cmdist




___
Cmdist mailing list
Cmdist@ccrma.stanford.edu
https://cm-mail.stanford.edu/mailman/listinfo/cmdist
___
Cmdist mailing list
Cmdist@ccrma.stanford.edu
https://cm-mail.stanford.edu/mailman/listinfo/cmdist


Re: [CM] TeXmacs & S7

2022-01-17 Thread bil

Do I understand you correclty that the patch I
implemented break some assumption of your code


In general, yes.  I'd have to read through the
code -- I glanced at it a few months ago, but
can't remember any details, except that it struck
me as written for Guile 1.8? and perhaps
awkward for s7 (something about modules?).

___
Cmdist mailing list
Cmdist@ccrma.stanford.edu
https://cm-mail.stanford.edu/mailman/listinfo/cmdist


Re: [CM] TeXmacs & S7

2022-01-17 Thread Massimiliano Gubinelli
Dear Bill,
 thanks for the remarks. Do I understand you correclty that the patch I 
implemented break some assumption of your code. Is there a way to be sure I'm 
not introducing any bug?

Best,
Max


> On 17. Jan 2022, at 21:13, b...@ccrma.stanford.edu  
> wrote:
> 
> Currently, s7's optimizer sometimes depends on the position of the variables
> in environments, so your change is only safe if the optimizer gives up.
> Since the order matters, a hash-table lookup is unlikely to work without
> some serious overhead.  Most environments have only a handful of locals, and
> a small linear search is faster than a hash-table lookup (and the search is
> unnecessary if the variables have unique names).
> 

___
Cmdist mailing list
Cmdist@ccrma.stanford.edu
https://cm-mail.stanford.edu/mailman/listinfo/cmdist


Re: [CM] TeXmacs & S7

2022-01-17 Thread Elijah Stone

Environments come and go at an amazing pace


That's why I suggest to only build a hash table only after a certain 
number of accesses.


 -E
___
Cmdist mailing list
Cmdist@ccrma.stanford.edu
https://cm-mail.stanford.edu/mailman/listinfo/cmdist


Re: [CM] TeXmacs & S7

2022-01-17 Thread bil

Another idea is inline caching...


And probably better than a hash-table, but it's yet
another layer in an already complicated process.
I might try that just to see what happens --
thanks for the suggestion!

___
Cmdist mailing list
Cmdist@ccrma.stanford.edu
https://cm-mail.stanford.edu/mailman/listinfo/cmdist


Re: [CM] TeXmacs & S7

2022-01-17 Thread bil
Why not maintain a hash table whose values are offsets into the flat 
environment?
Then it's a cheap branch or two on lookup to see: 1) is there a hash 
table;
2) should I build one (is the env big enough, and have there been 
enough lookups).


I call that serious overhead.  Environments come and go at an amazing
pace.  Most lookups are already immediate (do not involve a search).
In some cases (non-recursive, safe functions), I can save
the environment and reuse it, so some analysis might be acceptable.
I doubt that applies here because apparently the optimizer already
threw up its hands.

(Environments in s7 are very dynamic -- I do not currently
try to keep the env's length stored somewhere, and to get it
is nearly as bad as a linear search).

___
Cmdist mailing list
Cmdist@ccrma.stanford.edu
https://cm-mail.stanford.edu/mailman/listinfo/cmdist


Re: [CM] TeXmacs & S7

2022-01-17 Thread Elijah Stone

Another idea is inline caching...

On Mon, 17 Jan 2022, Elijah Stone wrote:


On Mon, 17 Jan 2022, b...@ccrma.stanford.edu wrote:

Currently, s7's optimizer sometimes depends on the position of the 
variables in environments, so your change is only safe if the optimizer 
gives up. Since the order matters, a hash-table lookup is unlikely to work 
without some serious overhead.  Most environments have only a handful of 
locals, and a small linear search is faster than a hash-table lookup (and 
the search is unnecessary if the variables have unique names).


Why not maintain a hash table whose values are offsets into the flat 
environment?  Then it's a cheap branch or two on lookup to see: 1) is there a 
hash table; 2) should I build one (is the env big enough, and have there been 
enough lookups).


-E
___
Cmdist mailing list
Cmdist@ccrma.stanford.edu
https://cm-mail.stanford.edu/mailman/listinfo/cmdist


___
Cmdist mailing list
Cmdist@ccrma.stanford.edu
https://cm-mail.stanford.edu/mailman/listinfo/cmdist


Re: [CM] TeXmacs & S7

2022-01-17 Thread Elijah Stone

On Mon, 17 Jan 2022, b...@ccrma.stanford.edu wrote:

Currently, s7's optimizer sometimes depends on the position of the 
variables in environments, so your change is only safe if the optimizer 
gives up. Since the order matters, a hash-table lookup is unlikely to 
work without some serious overhead.  Most environments have only a 
handful of locals, and a small linear search is faster than a hash-table 
lookup (and the search is unnecessary if the variables have unique 
names).


Why not maintain a hash table whose values are offsets into the flat 
environment?  Then it's a cheap branch or two on lookup to see: 1) is 
there a hash table; 2) should I build one (is the env big enough, and have 
there been enough lookups).


 -E
___
Cmdist mailing list
Cmdist@ccrma.stanford.edu
https://cm-mail.stanford.edu/mailman/listinfo/cmdist


Re: [CM] TeXmacs & S7

2022-01-17 Thread bil

Thanks for the observations -- I'm glad s7 has
worked out reasonably well.  On your questions:


1) would it be possible to have lookup_from implemented via some hash 
table...?

   Alternatively, can our patch be made into the official version?

Currently, s7's optimizer sometimes depends on the position of the 
variables

in environments, so your change is only safe if the optimizer gives up.
Since the order matters, a hash-table lookup is unlikely to work without
some serious overhead.  Most environments have only a handful of locals, 
and
a small linear search is faster than a hash-table lookup (and the search 
is

unnecessary if the variables have unique names).

I think your situation is an unusual case: you apparently have more than
100 local variables in an environment, and the ones you want do not have
unique names.  I wonder if you could use a hash-table for the local 
variables.

Or (kinda ugly) look at the code and place the most used variables so
they are at the front of the list of slots (I can't immediately remember
whether that means first or last in the list of let variables).


2) Suggestions to explain the high memory usage?

(*s7* 'memory-usage) can tell you what is taking up the space.
If that doesn't help, you might be able to tune the GC with
the gc-related fields in *s7*.


___
Cmdist mailing list
Cmdist@ccrma.stanford.edu
https://cm-mail.stanford.edu/mailman/listinfo/cmdist


[CM] TeXmacs & S7

2022-01-17 Thread Massimiliano Gubinelli
Dear all,

 integration of S7 in the TeXmacs document editor (www.texmacs.org) has been 
quite successful so far. You can grab the associated development branch here at 
github

https://github.com/texmacs/texmacs/tree/wip_s7

you will need Qt 4/5 and some other libraries to compile it. Some preliminary 
tests (which I think I've already posted on this list) and comments on the 
intergation of various kinds of schemes in TeXmacs are here

https://texmacs.github.io/notes/docs/scheming.html

Speed is great, much better than guile 1.8 (our standard scheme implementation) 
for the most part. Some users reported slowing down in some tasks (like 
converting to LaTeX) but I still haven't measured this.

We use a mostly unmodified version of S7 where only the patch attached below is 
used. It modifies the way lookup_from works, by putting at the beginning of the 
symbol list symbols which are way back and are looked upon. For us this is a 
game-changer : without it TeXmacs/S7 is unusable. We rely on scheme on many 
places, in particular the menus and the UI is dynamically generated from scheme 
descriptions at each keypress, in response to changes of the position of the 
cursor in the document (which affects which element the user is current 
focussing and therefore which UI elements are appropriate to show). 

We experience problems with the memory footprint of the program. TeXmacs/Guile 
uses usually ~500MB on my Mac while TeXmacs/S7 goes slowly up to ~1GB and some 
users saw also ~2GB of memory footprint. 

I have a couple of requests for the developer(s?):

1) would it be possible to have loopup_from implemented via some hash table or 
some speedier lookup? It would be great to shave some more performances out of 
this. Alternatively, can our patch be made into the official version? (or maybe 
some improved version of it)

2) Suggestions to explain the high memory usage? Do somebody else also 
experience these problems?

Thanks for this great program.

Best regards,
Massimiliano Gubinelli 


--

diff --git a/src/src/Scheme/S7/s7.c b/src/src/Scheme/S7/s7.c
index ed5965591..f0c3488dd 100644
--- a/src/src/Scheme/S7/s7.c
+++ b/src/src/Scheme/S7/s7.c
@@ -10124,10 +10124,20 @@ static inline s7_pointer lookup_from(s7_scheme *sc, 
const s7_pointer symbol, s7_
 }
   for (; is_let(e); e = let_outlet(e))
 {
-  s7_pointer y;
-  for (y = let_slots(e); tis_slot(y); y = next_slot(y))
-   if (slot_symbol(y) == symbol)
- return(slot_value(y));
+  s7_pointer y, py;
+  int steps = 0;
+  for (y = let_slots(e); tis_slot(y); py = y, y = next_slot(y), steps++)
+  if (slot_symbol(y) == symbol) {
+/* (TeXmacs) We try to bring back symbols which are used frequently to the
+   beginning of the list. This improves the lookup in TeXmacs.
+   The threshold is chosen heuristically.*/
+if (steps > 100) {
+   next_slot(py) = next_slot(y);
+   next_slot(y) = let_slots(e);
+   let_slots(e) = y;
+}
+return(slot_value(y));
+  }
 }
   if (is_slot(global_slot(symbol)))
 return(slot_value(global_slot(symbol)));


___
Cmdist mailing list
Cmdist@ccrma.stanford.edu
https://cm-mail.stanford.edu/mailman/listinfo/cmdist


Re: [CM] R7RS support

2022-01-17 Thread bil

The with-exception definition in r7rs.scm probably should be

(define (with-exception-handler handler thunk)
  (catch #t thunk (lambda args (apply handler args

The define-library code dates from the days (years ago)
when s7's define-macro returned the symbol rather than
the value.  Also, I apparently missed the built-in library
for r5rs names.  For the latter add

(apply define (symbol (object->string '(scheme r5rs))) (inlet) ())

For the former

295c296
< (cons 'export (symbol->value
---

 (cons 'export ;(symbol->value

297c298
<  `(set! *export* (append ',names 
*export*))
---

  `(set! *export* (append ',names 
*export*);)


That is, symbol->value is probably not needed anymore.

___
Cmdist mailing list
Cmdist@ccrma.stanford.edu
https://cm-mail.stanford.edu/mailman/listinfo/cmdist


Re: [CM] R7RS support

2022-01-17 Thread Iain Duncan
Hi Rudolf, Bill would be the person to address this better than me, but I
think the Egghead team should read through the s7.html page pretty closely
to see if s7 is a good fit. It's pretty clear in there that there is
*limited* R7RS compatibility, but that s7 is not R7RS and nor is that a
stated goal. For example, s7 does not do macros with syntax-case or
syntax-rules, but uses CL style macros. If R7RS is what you need, you might
be better off with an implementation that makes that a goal, such as Chibi.
I use s7 embedded in audio programs, which shares a fair bit of domain
space with games, and I personally chose s7 because the performance and
ease of embedding made up for that, but YMMV!

HTH
iain

On Mon, Jan 17, 2022 at 7:36 AM Rudolf Adamkovič  wrote:

> Hi there!
>
> At Egghead Games, we would like to use Scheme for in-app scripting.  We
> wired up s7 and SQLite to kick things off, but s7 support for R7RS does
> not seem to work.  Below, I include some examples to illustrate my
> point.
>
> A basic example from the R7RS standard, page 54, …
>
> (with-exception-handler
> (lambda (x)
>   (display "something went wrong\n"))
>   (lambda ()
> (+ 1 (raise ’an-error
>
> … results in:
>
> > Error: catch error handler should accept two arguments: #
>
> The simplest library …
>
> (load "r7rs.scm")
> (define-library (some lib)
>   (export some-proc)
>   (import (scheme base)
>   (scheme r5rs))
>   (begin
> (define (some-proc x)
>   (display x
>
> … results in:
>
> > Error: symbol->value first argument, {gensym}-1, is a macro but should
> > be a symbol (define-macro ({gensym}-1 . names)...
>
> We picked s7 because the website says …
>
> > I believe it is compatible with r5rs and r7r
>
> … but per a quick grep, there seem to exist no tests for define-library
> or with-exception-handler.
>
> Any ideas?
>
> Rudy
> --
> "Logic is a science of the necessary laws of thought, without which no
> employment of the understanding and the reason takes place." -- Immanuel
> Kant, 1785
>
> Rudolf Adamkovič  [he/him]
> Studenohorská 25
> 84103 Bratislava
> Slovakia
>
> ___
> Cmdist mailing list
> Cmdist@ccrma.stanford.edu
> https://cm-mail.stanford.edu/mailman/listinfo/cmdist
>
___
Cmdist mailing list
Cmdist@ccrma.stanford.edu
https://cm-mail.stanford.edu/mailman/listinfo/cmdist