unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Srfi-159/166 - monadic formatting for guile
@ 2019-06-02 13:38 Linus Björnstam
  2019-06-02 20:31 ` Arne Babenhauserheide
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Linus Björnstam @ 2019-06-02 13:38 UTC (permalink / raw)
  To: guile-user

Hi there!

I just ported the reference implementation of SRFI-159/166 (166 being the successor of 159) from the reference implementation in chibi scheme. The srfi document is here: https://srfi.schemers.org/srfi-166/srfi-166.html

SRFI-166 is like (ice-9 format) on steroids, drenched in molasses. It can do a lot more than (ice-9 format), but about 3x slower. I haven't started trying to make it fast just yet, but there are some low hanging fruit (like speeding up simple cases). I will wait with optimization until the srfi is finalized (and also maybe hear with Alex what he has in mind before trying to half-ass it myself). 

Anyway, the repo is here: https://bitbucket.org/bjoli/guile-srfi-159 . I haven't ported the tests, but playing with it in guile and chibi scheme produces the same result. Tests are up, but I'm travelling without computer the next week, so there is no time.

-- 
  Linus Björnstam



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

* Re: Srfi-159/166 - monadic formatting for guile
  2019-06-02 13:38 Srfi-159/166 - monadic formatting for guile Linus Björnstam
@ 2019-06-02 20:31 ` Arne Babenhauserheide
  2019-06-02 20:41 ` Ludovic Courtès
  2019-06-11 22:01 ` Mark H Weaver
  2 siblings, 0 replies; 12+ messages in thread
From: Arne Babenhauserheide @ 2019-06-02 20:31 UTC (permalink / raw)
  To: guile-user

[-- Attachment #1: Type: text/plain, Size: 654 bytes --]


Linus Björnstam <linus.internet@fastmail.se> writes:

> I just ported the reference implementation of SRFI-159/166 (166 being the successor of 159) from the reference implementation in chibi scheme. The srfi document is here: https://srfi.schemers.org/srfi-166/srfi-166.html
> Anyway, the repo is here: https://bitbucket.org/bjoli/guile-srfi-159 . I haven't ported the tests, but playing with it in guile and chibi scheme produces the same result. Tests are up, but I'm travelling without computer the next week, so there is no time.

Cool! Thank you!

Best wishes,
Arne
-- 
Unpolitisch sein
heißt politisch sein
ohne es zu merken

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 1076 bytes --]

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

* Re: Srfi-159/166 - monadic formatting for guile
  2019-06-02 13:38 Srfi-159/166 - monadic formatting for guile Linus Björnstam
  2019-06-02 20:31 ` Arne Babenhauserheide
@ 2019-06-02 20:41 ` Ludovic Courtès
  2019-06-03  5:34   ` Linus Björnstam
  2019-06-11 22:01 ` Mark H Weaver
  2 siblings, 1 reply; 12+ messages in thread
From: Ludovic Courtès @ 2019-06-02 20:41 UTC (permalink / raw)
  To: guile-user

Hi Linus,

Linus Björnstam <linus.internet@fastmail.se> skribis:

> Anyway, the repo is here: https://bitbucket.org/bjoli/guile-srfi-159 . I haven't ported the tests, but playing with it in guile and chibi scheme produces the same result. Tests are up, but I'm travelling without computer the next week, so there is no time.

Really cool!  I’ve just pushed a Guix package for it:

  https://git.savannah.gnu.org/cgit/guix.git/commit/?id=dec4b3aa18e24466841244c3e34b255201bbcc9e

Thanks,
Ludo’.




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

* Re: Srfi-159/166 - monadic formatting for guile
  2019-06-02 20:41 ` Ludovic Courtès
@ 2019-06-03  5:34   ` Linus Björnstam
  2019-06-03 13:07     ` Ludovic Courtès
  0 siblings, 1 reply; 12+ messages in thread
From: Linus Björnstam @ 2019-06-03  5:34 UTC (permalink / raw)
  To: Ludovic Courtès, guile-user

Thanks Ludo!

When SRFI-166 stabilizes I will probably make a pull request myself and convert the srfi document to a texi file. 

I want to package it as (srfi srfi-166) whenever that happens, and maybe try to get it into guile (or at least become the maintainer for the guix package myself). 

This is quite some time into the future though. I need to try to make it faster (Alex mentions CL-style compiler macros and make some fast path for common cases). I don't know if that kind of hack is a show stopper for guile though.

-- 
  Linus Björnstam

On Sun, 2 Jun 2019, at 22:42, Ludovic Courtès wrote:
> Hi Linus,
> 
> Linus Björnstam <linus.internet@fastmail.se> skribis:
> 
> > Anyway, the repo is here: https://bitbucket.org/bjoli/guile-srfi-159 . I haven't ported the tests, but playing with it in guile and chibi scheme produces the same result. Tests are up, but I'm travelling without computer the next week, so there is no time.
> 
> Really cool!  I’ve just pushed a Guix package for it:
> 
>   
> https://git.savannah.gnu.org/cgit/guix.git/commit/?id=dec4b3aa18e24466841244c3e34b255201bbcc9e
> 
> Thanks,
> Ludo’.
> 
> 
>



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

* Re: Srfi-159/166 - monadic formatting for guile
  2019-06-03  5:34   ` Linus Björnstam
@ 2019-06-03 13:07     ` Ludovic Courtès
  0 siblings, 0 replies; 12+ messages in thread
From: Ludovic Courtès @ 2019-06-03 13:07 UTC (permalink / raw)
  To: Linus Björnstam; +Cc: guile-user

Hi!

Linus Björnstam <linus.internet@fastmail.se> skribis:

> When SRFI-166 stabilizes I will probably make a pull request myself and convert the srfi document to a texi file. 
>
> I want to package it as (srfi srfi-166) whenever that happens, and maybe try to get it into guile (or at least become the maintainer for the guix package myself). 

That’d be great!

BTW, I was surprised to see that this module lives in the (srfi-159)
name space and not (srfi srfi-159) as we’re used to, but it doesn’t
matter much.

Thanks,
Ludo’.



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

* Re: Srfi-159/166 - monadic formatting for guile
  2019-06-02 13:38 Srfi-159/166 - monadic formatting for guile Linus Björnstam
  2019-06-02 20:31 ` Arne Babenhauserheide
  2019-06-02 20:41 ` Ludovic Courtès
@ 2019-06-11 22:01 ` Mark H Weaver
  2019-06-14  9:38   ` Linus Björnstam
  2 siblings, 1 reply; 12+ messages in thread
From: Mark H Weaver @ 2019-06-11 22:01 UTC (permalink / raw)
  To: Linus Björnstam; +Cc: guile-user

Hi Linus,

Linus Björnstam <linus.internet@fastmail.se> writes:

> I just ported the reference implementation of SRFI-159/166 (166 being
> the successor of 159) from the reference implementation in chibi
> scheme. The srfi document is here:
> https://srfi.schemers.org/srfi-166/srfi-166.html
>
> SRFI-166 is like (ice-9 format) on steroids, drenched in molasses. It
> can do a lot more than (ice-9 format), but about 3x slower. I haven't
> started trying to make it fast just yet, but there are some low
> hanging fruit (like speeding up simple cases). I will wait with
> optimization until the srfi is finalized (and also maybe hear with
> Alex what he has in mind before trying to half-ass it myself).
>
> Anyway, the repo is here: https://bitbucket.org/bjoli/guile-srfi-159
> . I haven't ported the tests, but playing with it in guile and chibi
> scheme produces the same result. Tests are up, but I'm travelling
> without computer the next week, so there is no time.

I would be in favor of integrating this into Guile at some point,
although first I would like to make a careful review of the
implementation to make sure that it integrates well with Guile's related
mechanisms, e.g. custom record printers, printer options, and print
states, and that it supports all Guile data types.  In particular, I
remember finding it difficult to properly implement cycle detection
while supporting Guile's existing mechanisms.  I'm not sure it can be
done without modifying Guile's built-in printer.

I'll also want to take a close look at the numeric formatter, to make
sure that it achieves the same properties as our built-in printer,
e.g. that it prints inexacts with the minimal number of digits required
to ensure that the same number will be read back in (unless specifically
asked to limit the precision).

Anyway, thanks very much for sharing this!

    Regards,
      Mark



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

* Re: Srfi-159/166 - monadic formatting for guile
  2019-06-11 22:01 ` Mark H Weaver
@ 2019-06-14  9:38   ` Linus Björnstam
  2019-06-16  6:35     ` Mark H Weaver
  0 siblings, 1 reply; 12+ messages in thread
From: Linus Björnstam @ 2019-06-14  9:38 UTC (permalink / raw)
  To: Mark H Weaver; +Cc: guile-user

Hi Mark!

I am not sure I understand what you mean, but i suspect it is already solved, since for simple cases show will use display/write. So unless you try to do advanced formatting of circular lists it will do whatever display or write does. The same thing goes for custom printers. In fact, anything that isn't a regular procedure will be printed just as it does in guile. Due to formatters being procedures, it is currently not possible to distinguish between formatters and other lambdas, but wrapping a lambda in (written ...) works just as (write ...). 

So unless you tell show to do something else, it will default do guile's standard way. 

(show #t (exact->inexact 1/7)) is the same as (display (exact->inexact 1/7)), however (show #t (with ((precision 2)) ...)) is not.

I don't know what circular structures guile uses internally, but (show...)ing a circular list without any formatter is, like numbers, the same as whatever guile does. (show #t (circular-list 1 2 3)) displays the same as (display (circular-list 1 2 3)).

Did I misunderstand your questions?

-- 
  Linus Björnstam

On Wed, 12 Jun 2019, at 00:03, Mark H Weaver wrote:
> Hi Linus,
> 
> Linus Björnstam <linus.internet@fastmail.se> writes:
> 
> > I just ported the reference implementation of SRFI-159/166 (166 being
> > the successor of 159) from the reference implementation in chibi
> > scheme. The srfi document is here:
> > https://srfi.schemers.org/srfi-166/srfi-166.html
> >
> > SRFI-166 is like (ice-9 format) on steroids, drenched in molasses. It
> > can do a lot more than (ice-9 format), but about 3x slower. I haven't
> > started trying to make it fast just yet, but there are some low
> > hanging fruit (like speeding up simple cases). I will wait with
> > optimization until the srfi is finalized (and also maybe hear with
> > Alex what he has in mind before trying to half-ass it myself).
> >
> > Anyway, the repo is here: https://bitbucket.org/bjoli/guile-srfi-159
> > . I haven't ported the tests, but playing with it in guile and chibi
> > scheme produces the same result. Tests are up, but I'm travelling
> > without computer the next week, so there is no time.
> 
> I would be in favor of integrating this into Guile at some point,
> although first I would like to make a careful review of the
> implementation to make sure that it integrates well with Guile's related
> mechanisms, e.g. custom record printers, printer options, and print
> states, and that it supports all Guile data types.  In particular, I
> remember finding it difficult to properly implement cycle detection
> while supporting Guile's existing mechanisms.  I'm not sure it can be
> done without modifying Guile's built-in printer.
> 
> I'll also want to take a close look at the numeric formatter, to make
> sure that it achieves the same properties as our built-in printer,
> e.g. that it prints inexacts with the minimal number of digits required
> to ensure that the same number will be read back in (unless specifically
> asked to limit the precision).
> 
> Anyway, thanks very much for sharing this!
> 
>     Regards,
>       Mark
>



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

* Re: Srfi-159/166 - monadic formatting for guile
  2019-06-14  9:38   ` Linus Björnstam
@ 2019-06-16  6:35     ` Mark H Weaver
  2019-06-16 16:20       ` John Cowan
  2019-06-16 20:30       ` Linus Björnstam
  0 siblings, 2 replies; 12+ messages in thread
From: Mark H Weaver @ 2019-06-16  6:35 UTC (permalink / raw)
  To: Linus Björnstam; +Cc: guile-user

Hi Linus,

Linus Björnstam <linus.internet@fastmail.se> writes:

> I am not sure I understand what you mean, but i suspect it is already
> solved, since for simple cases show will use display/write. So unless
> you try to do advanced formatting of circular lists it will do
> whatever display or write does. The same thing goes for custom
> printers.

How do you implement 'written-shared', 'pretty-shared', and
'trimmed/lazy'?  In particular, how do you avoid non-termination when
asked to print cyclic data, when the cycle includes a non-standard data
type printed using a custom printer?  For example, what if you print a
list that includes an object whose custom printer will print output that
includes the same list that you started with?

     Regards,
       Mark



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

* Re: Srfi-159/166 - monadic formatting for guile
  2019-06-16  6:35     ` Mark H Weaver
@ 2019-06-16 16:20       ` John Cowan
  2019-06-16 19:30         ` Mark H Weaver
  2019-06-16 20:30       ` Linus Björnstam
  1 sibling, 1 reply; 12+ messages in thread
From: John Cowan @ 2019-06-16 16:20 UTC (permalink / raw)
  To: Mark H Weaver; +Cc: guile-user

On Sun, Jun 16, 2019 at 2:47 AM Mark H Weaver <mhw@netris.org> wrote:


> How do you implement 'written-shared', 'pretty-shared', and
> 'trimmed/lazy'?  In particular, how do you avoid non-termination when
> asked to print cyclic data, when the cycle includes a non-standard data
> type printed using a custom printer?  For example, what if you print a
> list that includes an object whose custom printer will print output that
> includes the same list that you started with?
>

Of course it can't cope with that.  But consider an object whose custom
printer outputs its instance variables where one of those instance variables
has been assigned to the object itself.  No procedure other than the object
printer itself is going to be able to break *that* loop.


John Cowan          http://vrici.lojban.org/~cowan        cowan@ccil.org
Yes, chili in the eye is bad, but so is your ear.  However, I would
suggest you wash your hands thoroughly before going to the toilet.
        --gadicath


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

* Re: Srfi-159/166 - monadic formatting for guile
  2019-06-16 16:20       ` John Cowan
@ 2019-06-16 19:30         ` Mark H Weaver
  2019-06-18 10:39           ` Linus Björnstam
  0 siblings, 1 reply; 12+ messages in thread
From: Mark H Weaver @ 2019-06-16 19:30 UTC (permalink / raw)
  To: John Cowan; +Cc: guile-user

Hi John,

John Cowan <cowan@ccil.org> writes:

> On Sun, Jun 16, 2019 at 2:47 AM Mark H Weaver <mhw@netris.org> wrote:
>
>
>> How do you implement 'written-shared', 'pretty-shared', and
>> 'trimmed/lazy'?  In particular, how do you avoid non-termination when
>> asked to print cyclic data, when the cycle includes a non-standard data
>> type printed using a custom printer?  For example, what if you print a
>> list that includes an object whose custom printer will print output that
>> includes the same list that you started with?
>>
>
> Of course it can't cope with that.  But consider an object whose custom
> printer outputs its instance variables where one of those instance variables
> has been assigned to the object itself.  No procedure other than the object
> printer itself is going to be able to break *that* loop.

The built-in 'write' and 'display' procedures can break the loop, which
is the approach that I chose when I last looked at this.

     Regards,
       Mark



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

* Re: Srfi-159/166 - monadic formatting for guile
  2019-06-16  6:35     ` Mark H Weaver
  2019-06-16 16:20       ` John Cowan
@ 2019-06-16 20:30       ` Linus Björnstam
  1 sibling, 0 replies; 12+ messages in thread
From: Linus Björnstam @ 2019-06-16 20:30 UTC (permalink / raw)
  To: Mark H Weaver; +Cc: guile-user

Well, in the written-shared/pretty-shared case, Alex Shinn (I just ported his reference implementation) relies on display/write for everything except lists and vectors, and those are, from what I can tell, exhaustively checked for cycles. 

trimmed/lazy I have to have a read through in some other way than black-on-white text on my 3.5" phone. 

Best regards
Linus

-- 
  Linus Björnstam

On Sun, 16 Jun 2019, at 08:37, Mark H Weaver wrote:
> Hi Linus,
> 
> Linus Björnstam <linus.internet@fastmail.se> writes:
> 
> > I am not sure I understand what you mean, but i suspect it is already
> > solved, since for simple cases show will use display/write. So unless
> > you try to do advanced formatting of circular lists it will do
> > whatever display or write does. The same thing goes for custom
> > printers.
> 
> How do you implement 'written-shared', 'pretty-shared', and
> 'trimmed/lazy'?  In particular, how do you avoid non-termination when
> asked to print cyclic data, when the cycle includes a non-standard data
> type printed using a custom printer?  For example, what if you print a
> list that includes an object whose custom printer will print output that
> includes the same list that you started with?
> 
>      Regards,
>        Mark
>



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

* Re: Srfi-159/166 - monadic formatting for guile
  2019-06-16 19:30         ` Mark H Weaver
@ 2019-06-18 10:39           ` Linus Björnstam
  0 siblings, 0 replies; 12+ messages in thread
From: Linus Björnstam @ 2019-06-18 10:39 UTC (permalink / raw)
  To: guile-user

So, I have had a look and played around with trimmed/lazy and it does nothing fancy. It relies solely on guiles own procedures for custom printers, which means we get guile's guarrantees for free. Recursive records are no problem, nor are circular lists of any rank or vectors any problem.


trimmed/lazy is also well-behaved when printing circular lists/vectors. (show #t (trimmed/lazy 100 (each-in-list (circular-list 1 2 3 4)))) works just fine and displays 1 2 3 4 ... until the 100 character limit is met.

I will have to do some porting to delimited continuations or CPS because currently it is relying on call/cc and the overhead is quite noticeable.
-- 
  Linus Björnstam

On Sun, 16 Jun 2019, at 21:35, Mark H Weaver wrote:
> Hi John,
> 
> John Cowan <cowan@ccil.org> writes:
> 
> > On Sun, Jun 16, 2019 at 2:47 AM Mark H Weaver <mhw@netris.org> wrote:
> >
> >
> >> How do you implement 'written-shared', 'pretty-shared', and
> >> 'trimmed/lazy'?  In particular, how do you avoid non-termination when
> >> asked to print cyclic data, when the cycle includes a non-standard data
> >> type printed using a custom printer?  For example, what if you print a
> >> list that includes an object whose custom printer will print output that
> >> includes the same list that you started with?
> >>
> >
> > Of course it can't cope with that.  But consider an object whose custom
> > printer outputs its instance variables where one of those instance variables
> > has been assigned to the object itself.  No procedure other than the object
> > printer itself is going to be able to break *that* loop.
> 
> The built-in 'write' and 'display' procedures can break the loop, which
> is the approach that I chose when I last looked at this.
> 
>      Regards,
>        Mark
> 
>



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

end of thread, other threads:[~2019-06-18 10:39 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-02 13:38 Srfi-159/166 - monadic formatting for guile Linus Björnstam
2019-06-02 20:31 ` Arne Babenhauserheide
2019-06-02 20:41 ` Ludovic Courtès
2019-06-03  5:34   ` Linus Björnstam
2019-06-03 13:07     ` Ludovic Courtès
2019-06-11 22:01 ` Mark H Weaver
2019-06-14  9:38   ` Linus Björnstam
2019-06-16  6:35     ` Mark H Weaver
2019-06-16 16:20       ` John Cowan
2019-06-16 19:30         ` Mark H Weaver
2019-06-18 10:39           ` Linus Björnstam
2019-06-16 20:30       ` Linus Björnstam

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