unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* "Missing" libraries/concepts found in other languages/ecosystems?
@ 2020-07-08  7:38 Simen Endsjø
  2020-07-08  8:15 ` Vladimir Zhbanov
                   ` (3 more replies)
  0 siblings, 4 replies; 36+ messages in thread
From: Simen Endsjø @ 2020-07-08  7:38 UTC (permalink / raw)
  To: guile-user


Hi, I'm new to scheme/lisp, so I'm trying to find out how to do 
things the "lisp
way". On the other hand, I like things from other ecosystems too, 
and I'm having
problems finding this for Guile. It might be because there's no 
need for it/I'm
terrible at searching/nobody had the time yet, or something else.

I've been trying to find implementations for https://reactivex.io 
without any
luck. And I'm unable to find implementation of FP concepts as 
found in Haskell
and other languages. Functor, Monad, lenses (and other helpers for 
working with
immutable data).

Does things like this exists, or is it better to use something 
else?

Regards Simen


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

* Re: "Missing" libraries/concepts found in other languages/ecosystems?
  2020-07-08  7:38 "Missing" libraries/concepts found in other languages/ecosystems? Simen Endsjø
@ 2020-07-08  8:15 ` Vladimir Zhbanov
  2020-07-08 10:08 ` Catonano
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 36+ messages in thread
From: Vladimir Zhbanov @ 2020-07-08  8:15 UTC (permalink / raw)
  To: guile-user

On Wed, Jul 08, 2020 at 09:38:28AM +0200, Simen Endsjø wrote:
> 
> Hi, I'm new to scheme/lisp, so I'm trying to find out how to do things the
> "lisp
> way". On the other hand, I like things from other ecosystems too, and I'm
> having
> problems finding this for Guile. It might be because there's no need for
> it/I'm
> terrible at searching/nobody had the time yet, or something else.
> 
> I've been trying to find implementations for https://reactivex.io without
> any
> luck. And I'm unable to find implementation of FP concepts as found in
> Haskell
> and other languages. Functor, Monad, lenses (and other helpers for working
> with
> immutable data).
> 
> Does things like this exists, or is it better to use something else?


While I'm not sure if it'll be of any help, but...

...One of the interesting resources related to your question is
http://okmij.org/, for instance:

  http://okmij.org/ftp/Scheme/monad-in-Scheme.html

-- 
  Vladimir

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



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

* Re: "Missing" libraries/concepts found in other languages/ecosystems?
  2020-07-08  7:38 "Missing" libraries/concepts found in other languages/ecosystems? Simen Endsjø
  2020-07-08  8:15 ` Vladimir Zhbanov
@ 2020-07-08 10:08 ` Catonano
  2020-07-08 11:29 ` Chris Vine
  2020-07-10 12:15 ` Christopher Lam
  3 siblings, 0 replies; 36+ messages in thread
From: Catonano @ 2020-07-08 10:08 UTC (permalink / raw)
  To: Simen Endsjø; +Cc: Guile User

Il giorno mer 8 lug 2020 alle ore 09:38 Simen Endsjø <simendsjo@gmail.com>
ha scritto:

>
> Hi, I'm new to scheme/lisp, so I'm trying to find out how to do
> things the "lisp
> way". On the other hand, I like things from other ecosystems too,
> and I'm having
> problems finding this for Guile. It might be because there's no
> need for it/I'm
> terrible at searching/nobody had the time yet, or something else.
>
> I've been trying to find implementations for https://reactivex.io
> without any
> luck. And I'm unable to find implementation of FP concepts as
> found in Haskell
> and other languages. Functor, Monad, lenses (and other helpers for
>
> as for guile based lenses you can take a look at this project

https://gitlab.com/a-sassmannshausen/guile-lens


Another couple of projects I feel I can suggest you are

https://hg.sr.ht/~bjoli/guile-fash/
and
https://hg.sr.ht/~bjoli/guile-fector

Also, you might be interested in this list

http://sph.mn/foreign/guile-software.html

How do I know these things ?

There's no central source, I think this stuff is not even on he Guile web
site and as far as I know, Fash and Fecor are not in the Guix collection (I
didn't check, they might be)

If you look at this list
https://libreplanet.org/wiki/Group:Guix/Wishlist

the Guile section is empty

I know these things because I have been lurking the Guile channels for years

That's how discoverability works in Guile: hang on the channels for years

The Guile community seems to be completely oblivious to the problem of
discoverability

Recently I've seen someone interrogating the bot on the irc channel, and
get some interesting information in return, I don't remember if such
information was about packages or usage patterns

I didn't bother to take a note because by now I am exhausted by this
attitude

And it's not only about packages

It's about usage patterns too

After years I discovered purely by chance a blog post by a member of the
Guile community about how to get a list of defined procedures in a given
module programmatically

The manual assumes you are going to read it ALL and throughout, it's
strictly segregates issues and completely disregard the experience of any
newcomer

You're assumed to have good knowledge of the Posix/Gnu system

The manual is strictly a reference for people with that knowledge and
cognitive style

No tutorials, no use cases, no examples

I suggest you to take a look at this blog post
https://www.hillelwayne.com/post/learning-a-language/

Guile fares pretty bad on many of the points raised in that post

Acquiring knowledge about how to do things in Guile is excruciating

And honestly I think this concurred in making Python the extension language
de facto instead of Guile

So that's why you don't find stuff ¯\_(ツ)_/¯


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

* Re: "Missing" libraries/concepts found in other languages/ecosystems?
  2020-07-08  7:38 "Missing" libraries/concepts found in other languages/ecosystems? Simen Endsjø
  2020-07-08  8:15 ` Vladimir Zhbanov
  2020-07-08 10:08 ` Catonano
@ 2020-07-08 11:29 ` Chris Vine
  2020-07-10 12:15 ` Christopher Lam
  3 siblings, 0 replies; 36+ messages in thread
From: Chris Vine @ 2020-07-08 11:29 UTC (permalink / raw)
  To: guile-user

On Wed, 08 Jul 2020 09:38:28 +0200
Simen Endsjø <simendsjo@gmail.com> wrote:
> Hi, I'm new to scheme/lisp, so I'm trying to find out how to do 
> things the "lisp
> way". On the other hand, I like things from other ecosystems too, 
> and I'm having
> problems finding this for Guile. It might be because there's no 
> need for it/I'm
> terrible at searching/nobody had the time yet, or something else.
> 
> I've been trying to find implementations for https://reactivex.io 
> without any
> luck. And I'm unable to find implementation of FP concepts as 
> found in Haskell
> and other languages. Functor, Monad, lenses (and other helpers for 
> working with
> immutable data).
> 
> Does things like this exists, or is it better to use something 
> else?

I should go with where the particular language leads you.  Scheme has:

1.  Dynamic typing rather than static typing, so that amongst other
    things functions can take and return multiple different types;

2.  Mutable variable bindings (set! and so on);

3.  Mutable objects (mutable fields in records, setcar! and setcdr! for
    lists, and so on);

4.  Exceptions and continuation objects.

5.  Macros which operate at compile time on s-expressions.

Functors (mappables) abound in scheme, notably in the form of lists,
and scheme has mandatory tail call elimination which encourages
some immutable techniques such as iterative recursion.  However I don't
think that in practice monadic uses, such as the state monad or option
or result monad, are really of much value in scheme, apart from for
pedagogical purposes (flatmap though can be very useful).  I have
written scheme code which for various reasons used a result type
indicating success and failure instead of exceptions, with associated
bind (and map), but I think that for that case using exceptions is
generally easier and more natural, and how guile itself operates.

If you want to see where scheme can take you, you might want to google
for the "Structure and Interpretation of Computer Programs" (SICP):
still a classic.



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

* Re: "Missing" libraries/concepts found in other languages/ecosystems?
       [not found] <mailman.75.1594224014.21222.guile-user@gnu.org>
@ 2020-07-08 18:22 ` Zelphir Kaltstahl
  2020-07-09 18:12   ` Leo Butler
                     ` (2 more replies)
  0 siblings, 3 replies; 36+ messages in thread
From: Zelphir Kaltstahl @ 2020-07-08 18:22 UTC (permalink / raw)
  To: simendsjo; +Cc: guile-user

Hi Simen!

On 7/8/20 6:00 PM, guile-user-request@gnu.org wrote:
> Hi, I'm new to scheme/lisp, so I'm trying to find out how to do 
> things the "lisp
> way". On the other hand, I like things from other ecosystems too, 
> and I'm having
> problems finding this for Guile. It might be because there's no 
> need for it/I'm
> terrible at searching/nobody had the time yet, or something else.
>
> I've been trying to find implementations for https://reactivex.io 
> without any
> luck. And I'm unable to find implementation of FP concepts as 
> found in Haskell
> and other languages. Functor, Monad, lenses (and other helpers for 
> working with
> immutable data).
>
> Does things like this exists, or is it better to use something 
> else?
>
> Regards Simen

To what others already have written I will add:

From time to time one can copy ideas from Racket or look at what exists
in Racket for solving a problem or seeing what the approach is.

Catonano identified already the lack of examples in the Guile guide. I
fight with that myself, so I created a repository with examples. Perhaps
I should somehow add them to the guide. I've not looked into how to do
that. Probably some commit in a repo somewhere for the guide:

https://notabug.org/ZelphirKaltstahl/guile-examples

Hope this can help!

If you want to create something the Guile ecosystem lacks, I guess you
can find things from other language ecosystems, but it is probably a
good idea to ask in specific about anything existing on the mailing list
and I don't know where else.

So far we have GNU Artanis and the very basic web server module(s). So
in the area of web development on the server side, there is probably a
lot of space for improvements.

On the other hand we Schemers are often minimalistic people in our
approach to programming. Or is that by accident?

Regards,
Zelphir




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

* Re: "Missing" libraries/concepts found in other languages/ecosystems?
  2020-07-08 18:22 ` Zelphir Kaltstahl
@ 2020-07-09 18:12   ` Leo Butler
  2020-07-09 19:34     ` Zelphir Kaltstahl
  2020-07-10  7:39   ` Aleix Conchillo Flaqué
  2020-07-10  8:49   ` Catonano
  2 siblings, 1 reply; 36+ messages in thread
From: Leo Butler @ 2020-07-09 18:12 UTC (permalink / raw)
  To: guile-user

Zelphir Kaltstahl <zelphirkaltstahl@gmail.com> writes:

<snip>

> To what others already have written I will add:
>
> From time to time one can copy ideas from Racket or look at what exists
> in Racket for solving a problem or seeing what the approach is.
>
> Catonano identified already the lack of examples in the Guile guide. I
> fight with that myself, so I created a repository with examples. Perhaps
> I should somehow add them to the guide. I've not looked into how to do
> that. Probably some commit in a repo somewhere for the guide:
>
> https://notabug.org/ZelphirKaltstahl/guile-examples
>
> Hope this can help!

Oh yes, thank you. That repository is a gem.

(I think it wouldn't take too much work to transform the repo as is into
a texinfo document on its own.)

---

The guile guide has been knocked. I agree that it could use more
examples, but I have found it is well-written and accurate.

Leo



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

* Re: "Missing" libraries/concepts found in other languages/ecosystems?
  2020-07-09 18:12   ` Leo Butler
@ 2020-07-09 19:34     ` Zelphir Kaltstahl
  0 siblings, 0 replies; 36+ messages in thread
From: Zelphir Kaltstahl @ 2020-07-09 19:34 UTC (permalink / raw)
  To: Leo Butler, guile-user

Hi Leo!

On 7/9/20 8:12 PM, Leo Butler wrote:
> Zelphir Kaltstahl <zelphirkaltstahl@gmail.com> writes:
>
> <snip>
>
>> To what others already have written I will add:
>>
>> From time to time one can copy ideas from Racket or look at what exists
>> in Racket for solving a problem or seeing what the approach is.
>>
>> Catonano identified already the lack of examples in the Guile guide. I
>> fight with that myself, so I created a repository with examples. Perhaps
>> I should somehow add them to the guide. I've not looked into how to do
>> that. Probably some commit in a repo somewhere for the guide:
>>
>> https://notabug.org/ZelphirKaltstahl/guile-examples
>>
>> Hope this can help!
> Oh yes, thank you. That repository is a gem.
>
> (I think it wouldn't take too much work to transform the repo as is into
> a texinfo document on its own.)
>
> ---
>
> The guile guide has been knocked. I agree that it could use more
> examples, but I have found it is well-written and accurate.
>
> Leo

Thanks for the compliment.

I agree with the guide being well written. Once I see an example or
figure one out (not always hard to do, but sometimes), I think: "Hmm ah
yes, actually that was sort of in the guide …". Perhaps I am a different
kind of learner or too used to the "example culture" in other languages,
where you can find almost everything on StackOverflow.

Of course examples would be nice to have, not going to argue against that.






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

* Re: "Missing" libraries/concepts found in other languages/ecosystems?
  2020-07-08 18:22 ` Zelphir Kaltstahl
  2020-07-09 18:12   ` Leo Butler
@ 2020-07-10  7:39   ` Aleix Conchillo Flaqué
  2020-07-10  8:14     ` Alex Sassmannshausen
  2020-07-10  8:49   ` Catonano
  2 siblings, 1 reply; 36+ messages in thread
From: Aleix Conchillo Flaqué @ 2020-07-10  7:39 UTC (permalink / raw)
  To: Zelphir Kaltstahl; +Cc: guile-user

On Wed, Jul 8, 2020 at 11:22 AM Zelphir Kaltstahl <
zelphirkaltstahl@gmail.com> wrote:

> To what others already have written I will add:
>
> From time to time one can copy ideas from Racket or look at what exists
> in Racket for solving a problem or seeing what the approach is.
>
> Catonano identified already the lack of examples in the Guile guide. I
> fight with that myself, so I created a repository with examples. Perhaps
> I should somehow add them to the guide. I've not looked into how to do
> that. Probably some commit in a repo somewhere for the guide:
>
> https://notabug.org/ZelphirKaltstahl/guile-examples
>
> Hope this can help!
>
>
Wow! I didn't know about this one. This is great Zelphir! Thanks!

Best,

Aleix


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

* Re: "Missing" libraries/concepts found in other languages/ecosystems?
  2020-07-10  7:39   ` Aleix Conchillo Flaqué
@ 2020-07-10  8:14     ` Alex Sassmannshausen
  0 siblings, 0 replies; 36+ messages in thread
From: Alex Sassmannshausen @ 2020-07-10  8:14 UTC (permalink / raw)
  To: Aleix Conchillo Flaqué, Zelphir Kaltstahl; +Cc: guile-user

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

On Fri, 2020-07-10 at 00:39 -0700, Aleix Conchillo Flaqué wrote:
> On Wed, Jul 8, 2020 at 11:22 AM Zelphir Kaltstahl <
> zelphirkaltstahl@gmail.com> wrote:
> 
> > To what others already have written I will add:
> > 
> > From time to time one can copy ideas from Racket or look at what
> > exists
> > in Racket for solving a problem or seeing what the approach is.
> > 
> > Catonano identified already the lack of examples in the Guile
> > guide. I
> > fight with that myself, so I created a repository with examples.
> > Perhaps
> > I should somehow add them to the guide. I've not looked into how to
> > do
> > that. Probably some commit in a repo somewhere for the guide:
> > 
> > https://notabug.org/ZelphirKaltstahl/guile-examples
> > 
> > Hope this can help!
> > 
> > 
> Wow! I didn't know about this one. This is great Zelphir! Thanks!
> 
> Best,
> 
> Aleix

Seconded!  Excellent resource!

Alex

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 273 bytes --]

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

* Re: "Missing" libraries/concepts found in other languages/ecosystems?
  2020-07-08 18:22 ` Zelphir Kaltstahl
  2020-07-09 18:12   ` Leo Butler
  2020-07-10  7:39   ` Aleix Conchillo Flaqué
@ 2020-07-10  8:49   ` Catonano
  2020-07-10 10:21     ` Chris Vine
  2 siblings, 1 reply; 36+ messages in thread
From: Catonano @ 2020-07-10  8:49 UTC (permalink / raw)
  To: Zelphir Kaltstahl; +Cc: Guile User

Il giorno mer 8 lug 2020 alle ore 20:22 Zelphir Kaltstahl <
zelphirkaltstahl@gmail.com> ha scritto:

> Hi Simen!
>
> On 7/8/20 6:00 PM, guile-user-request@gnu.org wrote:
> > Hi, I'm new to scheme/lisp, so I'm trying to find out how to do
> > things the "lisp
> > way". On the other hand, I like things from other ecosystems too,
> > and I'm having
> > problems finding this for Guile. It might be because there's no
> > need for it/I'm
> > terrible at searching/nobody had the time yet, or something else.
> >
> > I've been trying to find implementations for https://reactivex.io
> > without any
> > luck. And I'm unable to find implementation of FP concepts as
> > found in Haskell
> > and other languages. Functor, Monad, lenses (and other helpers for
> > working with
> > immutable data).
> >
> > Does things like this exists, or is it better to use something
> > else?
> >
> > Regards Simen
>
> To what others already have written I will add:
>
> From time to time one can copy ideas from Racket or look at what exists
> in Racket for solving a problem or seeing what the approach is.
>
> Catonano identified already the lack of examples in the Guile guide. I
> fight with that myself, so I created a repository with examples. Perhaps
> I should somehow add them to the guide. I've not looked into how to do
> that. Probably some commit in a repo somewhere for the guide:
>
> https://notabug.org/ZelphirKaltstahl/guile-examples
>
> Hope this can help!
>

Thank you, yes that helps

In fact, it's a precious resource !

I was especially delighted with the examples of using exceptions !

I had so missed examples of those !

As for the manual, very recently a mention of Guile Hall ended up being
included in the manual

The same could be done with your examples collection

I also think that your collection could be mentioned by the Guile web site,
maybe in the "learn" section

Here's the repo for the web site:
https://git.savannah.gnu.org/cgit/guile/guile-web.git/

a regular patch could do

What do people think of mentioning this resource on the Guile web site ?


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

* Re: "Missing" libraries/concepts found in other languages/ecosystems?
  2020-07-10  8:49   ` Catonano
@ 2020-07-10 10:21     ` Chris Vine
  2020-07-10 11:20       ` Catonano
  0 siblings, 1 reply; 36+ messages in thread
From: Chris Vine @ 2020-07-10 10:21 UTC (permalink / raw)
  To: guile-user

On Fri, 10 Jul 2020 10:49:37 +0200
Catonano <catonano@gmail.com> wrote:
> Il giorno mer 8 lug 2020 alle ore 20:22 Zelphir Kaltstahl <
> zelphirkaltstahl@gmail.com> ha scritto:
> 
> > Hi Simen!
> >
> > On 7/8/20 6:00 PM, guile-user-request@gnu.org wrote:
> > > Hi, I'm new to scheme/lisp, so I'm trying to find out how to do
> > > things the "lisp
> > > way". On the other hand, I like things from other ecosystems too,
> > > and I'm having
> > > problems finding this for Guile. It might be because there's no
> > > need for it/I'm
> > > terrible at searching/nobody had the time yet, or something else.
> > >
> > > I've been trying to find implementations for https://reactivex.io
> > > without any
> > > luck. And I'm unable to find implementation of FP concepts as
> > > found in Haskell
> > > and other languages. Functor, Monad, lenses (and other helpers for
> > > working with
> > > immutable data).
> > >
> > > Does things like this exists, or is it better to use something
> > > else?
> > >
> > > Regards Simen
> >
> > To what others already have written I will add:
> >
> > From time to time one can copy ideas from Racket or look at what exists
> > in Racket for solving a problem or seeing what the approach is.
> >
> > Catonano identified already the lack of examples in the Guile guide. I
> > fight with that myself, so I created a repository with examples. Perhaps
> > I should somehow add them to the guide. I've not looked into how to do
> > that. Probably some commit in a repo somewhere for the guide:
> >
> > https://notabug.org/ZelphirKaltstahl/guile-examples
> >
> > Hope this can help!
> >
> 
> Thank you, yes that helps
> 
> In fact, it's a precious resource !
> 
> I was especially delighted with the examples of using exceptions !
> 
> I had so missed examples of those !
> 
> As for the manual, very recently a mention of Guile Hall ended up being
> included in the manual
> 
> The same could be done with your examples collection
> 
> I also think that your collection could be mentioned by the Guile web site,
> maybe in the "learn" section
> 
> Here's the repo for the web site:
> https://git.savannah.gnu.org/cgit/guile/guile-web.git/
> 
> a regular patch could do
> 
> What do people think of mentioning this resource on the Guile web site ?

Whilst I don't have strong feelings, as a general approach I think it is
better to include additional examples (where needed) in the body of the
manual, which I think is generally well written.

Also, at this level of detail what some find helpful others don't.  You
were delighted above with the exceptions example, whereas (if I read
the right one) I thought that that was one of the weaker ones.  It
concentrates on R6RS/R7RS exceptions and with-exception-handler rather
than with guile's much easier to use catch expression (for guile-2.2)
or (for guile-3.0) its beefed-up with-exception-handler and exception
objects.

with-exception-handler is a tricky beast and the example didn't deal
with the main case: most uses of exceptions involve handling them and
moving on with program execution from the point where the exception is
caught, and to do that using with-exception-handler instead of
guile's 'catch' form you have to have a call/ec helper (or with
guile-3.0 you can just set the #unwind argument to true).  Instead you
are left with the idea that you use continuable exceptions for that
(which while they do stop the program exiting are something different)
or the R6RS/R7RS guard form.

I am not trying to be critical here - I think examples are useful to
convey points and some of them were fine.  My point is more about venue.



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

* Re: "Missing" libraries/concepts found in other languages/ecosystems?
  2020-07-10 10:21     ` Chris Vine
@ 2020-07-10 11:20       ` Catonano
  2020-07-11  0:19         ` Zelphir Kaltstahl
  0 siblings, 1 reply; 36+ messages in thread
From: Catonano @ 2020-07-10 11:20 UTC (permalink / raw)
  To: Chris Vine; +Cc: Guile User

Il giorno ven 10 lug 2020 alle ore 12:21 Chris Vine <vine35792468@gmail.com>
ha scritto:

> On Fri, 10 Jul 2020 10:49:37 +0200
> Catonano <catonano@gmail.com> wrote:
> > Il giorno mer 8 lug 2020 alle ore 20:22 Zelphir Kaltstahl <
> > zelphirkaltstahl@gmail.com> ha scritto:
> >
> > > Hi Simen!
> > >
> > > On 7/8/20 6:00 PM, guile-user-request@gnu.org wrote:
> > > > Hi, I'm new to scheme/lisp, so I'm trying to find out how to do
> > > > things the "lisp
> > > > way". On the other hand, I like things from other ecosystems too,
> > > > and I'm having
> > > > problems finding this for Guile. It might be because there's no
> > > > need for it/I'm
> > > > terrible at searching/nobody had the time yet, or something else.
> > > >
> > > > I've been trying to find implementations for https://reactivex.io
> > > > without any
> > > > luck. And I'm unable to find implementation of FP concepts as
> > > > found in Haskell
> > > > and other languages. Functor, Monad, lenses (and other helpers for
> > > > working with
> > > > immutable data).
> > > >
> > > > Does things like this exists, or is it better to use something
> > > > else?
> > > >
> > > > Regards Simen
> > >
> > > To what others already have written I will add:
> > >
> > > From time to time one can copy ideas from Racket or look at what exists
> > > in Racket for solving a problem or seeing what the approach is.
> > >
> > > Catonano identified already the lack of examples in the Guile guide. I
> > > fight with that myself, so I created a repository with examples.
> Perhaps
> > > I should somehow add them to the guide. I've not looked into how to do
> > > that. Probably some commit in a repo somewhere for the guide:
> > >
> > > https://notabug.org/ZelphirKaltstahl/guile-examples
> > >
> > > Hope this can help!
> > >
> >
> > Thank you, yes that helps
> >
> > In fact, it's a precious resource !
> >
> > I was especially delighted with the examples of using exceptions !
> >
> > I had so missed examples of those !
> >
> > As for the manual, very recently a mention of Guile Hall ended up being
> > included in the manual
> >
> > The same could be done with your examples collection
> >
> > I also think that your collection could be mentioned by the Guile web
> site,
> > maybe in the "learn" section
> >
> > Here's the repo for the web site:
> > https://git.savannah.gnu.org/cgit/guile/guile-web.git/
> >
> > a regular patch could do
> >
> > What do people think of mentioning this resource on the Guile web site ?
>
> Whilst I don't have strong feelings, as a general approach I think it is
> better to include additional examples (where needed) in the body of the
> manual, which I think is generally well written.
>

As long as some examples are reachable from an officially sanctioned
documentation source, I'm ok with that

What I find problematic is the casualness in referring to bits scattered
all around

The web site was just an idea, the manual would be perfectly fine

Also, at this level of detail what some find helpful others don't.  You
> were delighted above with the exceptions example, whereas (if I read
> the right one) I thought that that was one of the weaker ones.  It
> concentrates on R6RS/R7RS exceptions and with-exception-handler rather
> than with guile's much easier to use catch expression (for guile-2.2)
> or (for guile-3.0) its beefed-up with-exception-handler and exception
> objects.
>

Ah there has been a misunderstanding here

I was convinced that the exceptions example was of the last layout for
using exceptions reached recently in Guile 3.x

If it's not, I agree it's less valuable

But I think the author was just confused or led astray by the casualness of
referring to scattered bits, I'm not blaming them

I'd be grateful if anyone with enough understanding of the issue would
contribute a proper example of how to use exceptions according to the last
exceptions reorganization in Guile 3.x

I would be happy to send a patch for the manual containing such example and
a few words, as I did with the mention of Guile Hall


with-exception-handler is a tricky beast and the example didn't deal
> with the main case: most uses of exceptions involve handling them and
> moving on with program execution from the point where the exception is
> caught, and to do that using with-exception-handler instead of
> guile's 'catch' form you have to have a call/ec helper (or with
> guile-3.0 you can just set the #unwind argument to true).  Instead you
> are left with the idea that you use continuable exceptions for that
> (which while they do stop the program exiting are something different)
> or the R6RS/R7RS guard form.
>

I'm not following you on this because I don't know enough of both the Guile
new idea of how to use exceptions and the R6/7RS one


> I am not trying to be critical here - I think examples are useful to
> convey points and some of them were fine.  My point is more about venue.
>

 No, that's ok, that's why I asked

In fact, should we end up with a proper example in the manual, that would
be a positive outcome

I'd say more, here

I'd go systematically through all the examples in that repo and do a
similar assessment if we can add it to the manual as is or if it needs
refinement

I can't do this on my own because in many cases I don't know enough to come
up with valid examples myself

But I'd be happy to prepare patches for the manual, given the right
directions


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

* Re: "Missing" libraries/concepts found in other languages/ecosystems?
  2020-07-08  7:38 "Missing" libraries/concepts found in other languages/ecosystems? Simen Endsjø
                   ` (2 preceding siblings ...)
  2020-07-08 11:29 ` Chris Vine
@ 2020-07-10 12:15 ` Christopher Lam
  2020-07-10 15:52   ` Chris Vine
  3 siblings, 1 reply; 36+ messages in thread
From: Christopher Lam @ 2020-07-10 12:15 UTC (permalink / raw)
  Cc: guile-user

With respect to looking for guile examples, I've seen examples whereby
LISPers would run some code, dynamically changing the code while running in
production, and immediately the new code would be replaced in-memory. Not
sure if this is possible in scheme. Any live pointers would be appreciated
:)

On Wed, 8 Jul 2020 at 07:38, Simen Endsjø <simendsjo@gmail.com> wrote:

>
> Hi, I'm new to scheme/lisp, so I'm trying to find out how to do
> things the "lisp
> way". On the other hand, I like things from other ecosystems too,
> and I'm having
> problems finding this for Guile. It might be because there's no
> need for it/I'm
> terrible at searching/nobody had the time yet, or something else.
>
> I've been trying to find implementations for https://reactivex.io
> without any
> luck. And I'm unable to find implementation of FP concepts as
> found in Haskell
> and other languages. Functor, Monad, lenses (and other helpers for
> working with
> immutable data).
>
> Does things like this exists, or is it better to use something
> else?
>
> Regards Simen
>


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

* Re: "Missing" libraries/concepts found in other languages/ecosystems?
  2020-07-10 12:15 ` Christopher Lam
@ 2020-07-10 15:52   ` Chris Vine
  0 siblings, 0 replies; 36+ messages in thread
From: Chris Vine @ 2020-07-10 15:52 UTC (permalink / raw)
  To: guile-user

On Fri, 10 Jul 2020 12:15:55 +0000
Christopher Lam <christopher.lck@gmail.com> top posted:
> With respect to looking for guile examples, I've seen examples whereby
> LISPers would run some code, dynamically changing the code while running in
> production, and immediately the new code would be replaced in-memory. Not
> sure if this is possible in scheme. Any live pointers would be appreciated
[snip]

If you haven't tried geiser in emacs, I should give it a go.



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

* Re: "Missing" libraries/concepts found in other languages/ecosystems?
  2020-07-10 11:20       ` Catonano
@ 2020-07-11  0:19         ` Zelphir Kaltstahl
  2020-07-11  0:34           ` Zelphir Kaltstahl
  2020-07-11 10:13           ` Chris Vine
  0 siblings, 2 replies; 36+ messages in thread
From: Zelphir Kaltstahl @ 2020-07-11  0:19 UTC (permalink / raw)
  To: Catonano, Chris Vine; +Cc: Guile User

Hi all!

On 7/10/20 1:20 PM, Catonano wrote:
> Il giorno ven 10 lug 2020 alle ore 12:21 Chris Vine <vine35792468@gmail.com>
> ha scritto:
>
>> On Fri, 10 Jul 2020 10:49:37 +0200
>> Catonano <catonano@gmail.com> wrote:
>>> Il giorno mer 8 lug 2020 alle ore 20:22 Zelphir Kaltstahl <
>>> zelphirkaltstahl@gmail.com> ha scritto:
>>>
>>>> Hi Simen!
>>>>
>>>> On 7/8/20 6:00 PM, guile-user-request@gnu.org wrote:
>>>>> Hi, I'm new to scheme/lisp, so I'm trying to find out how to do
>>>>> things the "lisp
>>>>> way". On the other hand, I like things from other ecosystems too,
>>>>> and I'm having
>>>>> problems finding this for Guile. It might be because there's no
>>>>> need for it/I'm
>>>>> terrible at searching/nobody had the time yet, or something else.
>>>>>
>>>>> I've been trying to find implementations for https://reactivex.io
>>>>> without any
>>>>> luck. And I'm unable to find implementation of FP concepts as
>>>>> found in Haskell
>>>>> and other languages. Functor, Monad, lenses (and other helpers for
>>>>> working with
>>>>> immutable data).
>>>>>
>>>>> Does things like this exists, or is it better to use something
>>>>> else?
>>>>>
>>>>> Regards Simen
>>>> To what others already have written I will add:
>>>>
>>>> From time to time one can copy ideas from Racket or look at what exists
>>>> in Racket for solving a problem or seeing what the approach is.
>>>>
>>>> Catonano identified already the lack of examples in the Guile guide. I
>>>> fight with that myself, so I created a repository with examples.
>> Perhaps
>>>> I should somehow add them to the guide. I've not looked into how to do
>>>> that. Probably some commit in a repo somewhere for the guide:
>>>>
>>>> https://notabug.org/ZelphirKaltstahl/guile-examples
>>>>
>>>> Hope this can help!
>>>>
>>> Thank you, yes that helps
>>>
>>> In fact, it's a precious resource !
>>>
>>> I was especially delighted with the examples of using exceptions !
>>>
>>> I had so missed examples of those !
>>>
>>> As for the manual, very recently a mention of Guile Hall ended up being
>>> included in the manual
>>>
>>> The same could be done with your examples collection
>>>
>>> I also think that your collection could be mentioned by the Guile web
>> site,
>>> maybe in the "learn" section
>>>
>>> Here's the repo for the web site:
>>> https://git.savannah.gnu.org/cgit/guile/guile-web.git/
>>>
>>> a regular patch could do
>>>
>>> What do people think of mentioning this resource on the Guile web site ?
>> Whilst I don't have strong feelings, as a general approach I think it is
>> better to include additional examples (where needed) in the body of the
>> manual, which I think is generally well written.
>>
> As long as some examples are reachable from an officially sanctioned
> documentation source, I'm ok with that
>
> What I find problematic is the casualness in referring to bits scattered
> all around
>
> The web site was just an idea, the manual would be perfectly fine
>
> Also, at this level of detail what some find helpful others don't.  You
>> were delighted above with the exceptions example, whereas (if I read
>> the right one) I thought that that was one of the weaker ones.  It
>> concentrates on R6RS/R7RS exceptions and with-exception-handler rather
>> than with guile's much easier to use catch expression (for guile-2.2)
>> or (for guile-3.0) its beefed-up with-exception-handler and exception
>> objects.
>>
> Ah there has been a misunderstanding here
>
> I was convinced that the exceptions example was of the last layout for
> using exceptions reached recently in Guile 3.x
>
> If it's not, I agree it's less valuable
>
> But I think the author was just confused or led astray by the casualness of
> referring to scattered bits, I'm not blaming them
>
> I'd be grateful if anyone with enough understanding of the issue would
> contribute a proper example of how to use exceptions according to the last
> exceptions reorganization in Guile 3.x
>
> I would be happy to send a patch for the manual containing such example and
> a few words, as I did with the mention of Guile Hall
>
>
> with-exception-handler is a tricky beast and the example didn't deal
>> with the main case: most uses of exceptions involve handling them and
>> moving on with program execution from the point where the exception is
>> caught, and to do that using with-exception-handler instead of
>> guile's 'catch' form you have to have a call/ec helper (or with
>> guile-3.0 you can just set the #unwind argument to true).  Instead you
>> are left with the idea that you use continuable exceptions for that
>> (which while they do stop the program exiting are something different)
>> or the R6RS/R7RS guard form.
>>
> I'm not following you on this because I don't know enough of both the Guile
> new idea of how to use exceptions and the R6/7RS one
>
>
>> I am not trying to be critical here - I think examples are useful to
>> convey points and some of them were fine.  My point is more about venue.
>>
>  No, that's ok, that's why I asked
>
> In fact, should we end up with a proper example in the manual, that would
> be a positive outcome
>
> I'd say more, here
>
> I'd go systematically through all the examples in that repo and do a
> similar assessment if we can add it to the manual as is or if it needs
> refinement
>
> I can't do this on my own because in many cases I don't know enough to come
> up with valid examples myself
>
> But I'd be happy to prepare patches for the manual, given the right
> directions


I would be glad, if any non-optimal example was extended or updated by a
more knowledgeable person or I was told what I could improve in some
example. The examples in the repository are only, what I was able to
understand and I often find myself looking up, how to do something again.

If anyone wants to take any example and put it in the docs, go ahead.
Only don't think that my examples are the last word on how to do things.
Far from it!

About the exceptions thing: Aha! I should look into that again. I
thought the "conditions" thing was already pretty cool and useful. Once
an exception happens, you can react on it. I did not understand the
"call/ec helper" part, but perhaps I can understand it, when I check the
docs for the new exceptions in Guile 3.

I had another thought: Why do we not create this kind of so called
"awesome list" for Guile? There were some links in this discussion,
which might be a good fit on such a list and it is kind of informal,
easy to extend. Whenever someone asks for pointers, we could also
mention that list and perhaps they can find cool things in it. They
could see, that Guile is viable, because there are so many things people
do with Guile, or they could see their use case covered already.

Best regards,
Zelphir




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

* Re: "Missing" libraries/concepts found in other languages/ecosystems?
  2020-07-11  0:19         ` Zelphir Kaltstahl
@ 2020-07-11  0:34           ` Zelphir Kaltstahl
  2020-07-11 10:14             ` Chris Vine
  2020-07-11 14:46             ` Linus Björnstam
  2020-07-11 10:13           ` Chris Vine
  1 sibling, 2 replies; 36+ messages in thread
From: Zelphir Kaltstahl @ 2020-07-11  0:34 UTC (permalink / raw)
  To: Catonano, Chris Vine; +Cc: Guile User

The comments about exception handling also reminded me of the following
blog post:

https://blog.sulami.xyz/posts/common-lisp-restarts/

Pretty cool concept as well.

If there anything like it in Guile or is something like it possible
(probably, right?)?


On 7/11/20 2:19 AM, Zelphir Kaltstahl wrote:
> Hi all!
>
> On 7/10/20 1:20 PM, Catonano wrote:
>> Il giorno ven 10 lug 2020 alle ore 12:21 Chris Vine <vine35792468@gmail.com>
>> ha scritto:
>>
>>> On Fri, 10 Jul 2020 10:49:37 +0200
>>> Catonano <catonano@gmail.com> wrote:
>>>> Il giorno mer 8 lug 2020 alle ore 20:22 Zelphir Kaltstahl <
>>>> zelphirkaltstahl@gmail.com> ha scritto:
>>>>
>>>>> Hi Simen!
>>>>>
>>>>> On 7/8/20 6:00 PM, guile-user-request@gnu.org wrote:
>>>>>> Hi, I'm new to scheme/lisp, so I'm trying to find out how to do
>>>>>> things the "lisp
>>>>>> way". On the other hand, I like things from other ecosystems too,
>>>>>> and I'm having
>>>>>> problems finding this for Guile. It might be because there's no
>>>>>> need for it/I'm
>>>>>> terrible at searching/nobody had the time yet, or something else.
>>>>>>
>>>>>> I've been trying to find implementations for https://reactivex.io
>>>>>> without any
>>>>>> luck. And I'm unable to find implementation of FP concepts as
>>>>>> found in Haskell
>>>>>> and other languages. Functor, Monad, lenses (and other helpers for
>>>>>> working with
>>>>>> immutable data).
>>>>>>
>>>>>> Does things like this exists, or is it better to use something
>>>>>> else?
>>>>>>
>>>>>> Regards Simen
>>>>> To what others already have written I will add:
>>>>>
>>>>> From time to time one can copy ideas from Racket or look at what exists
>>>>> in Racket for solving a problem or seeing what the approach is.
>>>>>
>>>>> Catonano identified already the lack of examples in the Guile guide. I
>>>>> fight with that myself, so I created a repository with examples.
>>> Perhaps
>>>>> I should somehow add them to the guide. I've not looked into how to do
>>>>> that. Probably some commit in a repo somewhere for the guide:
>>>>>
>>>>> https://notabug.org/ZelphirKaltstahl/guile-examples
>>>>>
>>>>> Hope this can help!
>>>>>
>>>> Thank you, yes that helps
>>>>
>>>> In fact, it's a precious resource !
>>>>
>>>> I was especially delighted with the examples of using exceptions !
>>>>
>>>> I had so missed examples of those !
>>>>
>>>> As for the manual, very recently a mention of Guile Hall ended up being
>>>> included in the manual
>>>>
>>>> The same could be done with your examples collection
>>>>
>>>> I also think that your collection could be mentioned by the Guile web
>>> site,
>>>> maybe in the "learn" section
>>>>
>>>> Here's the repo for the web site:
>>>> https://git.savannah.gnu.org/cgit/guile/guile-web.git/
>>>>
>>>> a regular patch could do
>>>>
>>>> What do people think of mentioning this resource on the Guile web site ?
>>> Whilst I don't have strong feelings, as a general approach I think it is
>>> better to include additional examples (where needed) in the body of the
>>> manual, which I think is generally well written.
>>>
>> As long as some examples are reachable from an officially sanctioned
>> documentation source, I'm ok with that
>>
>> What I find problematic is the casualness in referring to bits scattered
>> all around
>>
>> The web site was just an idea, the manual would be perfectly fine
>>
>> Also, at this level of detail what some find helpful others don't.  You
>>> were delighted above with the exceptions example, whereas (if I read
>>> the right one) I thought that that was one of the weaker ones.  It
>>> concentrates on R6RS/R7RS exceptions and with-exception-handler rather
>>> than with guile's much easier to use catch expression (for guile-2.2)
>>> or (for guile-3.0) its beefed-up with-exception-handler and exception
>>> objects.
>>>
>> Ah there has been a misunderstanding here
>>
>> I was convinced that the exceptions example was of the last layout for
>> using exceptions reached recently in Guile 3.x
>>
>> If it's not, I agree it's less valuable
>>
>> But I think the author was just confused or led astray by the casualness of
>> referring to scattered bits, I'm not blaming them
>>
>> I'd be grateful if anyone with enough understanding of the issue would
>> contribute a proper example of how to use exceptions according to the last
>> exceptions reorganization in Guile 3.x
>>
>> I would be happy to send a patch for the manual containing such example and
>> a few words, as I did with the mention of Guile Hall
>>
>>
>> with-exception-handler is a tricky beast and the example didn't deal
>>> with the main case: most uses of exceptions involve handling them and
>>> moving on with program execution from the point where the exception is
>>> caught, and to do that using with-exception-handler instead of
>>> guile's 'catch' form you have to have a call/ec helper (or with
>>> guile-3.0 you can just set the #unwind argument to true).  Instead you
>>> are left with the idea that you use continuable exceptions for that
>>> (which while they do stop the program exiting are something different)
>>> or the R6RS/R7RS guard form.
>>>
>> I'm not following you on this because I don't know enough of both the Guile
>> new idea of how to use exceptions and the R6/7RS one
>>
>>
>>> I am not trying to be critical here - I think examples are useful to
>>> convey points and some of them were fine.  My point is more about venue.
>>>
>>  No, that's ok, that's why I asked
>>
>> In fact, should we end up with a proper example in the manual, that would
>> be a positive outcome
>>
>> I'd say more, here
>>
>> I'd go systematically through all the examples in that repo and do a
>> similar assessment if we can add it to the manual as is or if it needs
>> refinement
>>
>> I can't do this on my own because in many cases I don't know enough to come
>> up with valid examples myself
>>
>> But I'd be happy to prepare patches for the manual, given the right
>> directions
>
> I would be glad, if any non-optimal example was extended or updated by a
> more knowledgeable person or I was told what I could improve in some
> example. The examples in the repository are only, what I was able to
> understand and I often find myself looking up, how to do something again.
>
> If anyone wants to take any example and put it in the docs, go ahead.
> Only don't think that my examples are the last word on how to do things.
> Far from it!
>
> About the exceptions thing: Aha! I should look into that again. I
> thought the "conditions" thing was already pretty cool and useful. Once
> an exception happens, you can react on it. I did not understand the
> "call/ec helper" part, but perhaps I can understand it, when I check the
> docs for the new exceptions in Guile 3.
>
> I had another thought: Why do we not create this kind of so called
> "awesome list" for Guile? There were some links in this discussion,
> which might be a good fit on such a list and it is kind of informal,
> easy to extend. Whenever someone asks for pointers, we could also
> mention that list and perhaps they can find cool things in it. They
> could see, that Guile is viable, because there are so many things people
> do with Guile, or they could see their use case covered already.
>
> Best regards,
> Zelphir
>
>



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

* Re: "Missing" libraries/concepts found in other languages/ecosystems?
  2020-07-11  0:19         ` Zelphir Kaltstahl
  2020-07-11  0:34           ` Zelphir Kaltstahl
@ 2020-07-11 10:13           ` Chris Vine
  2020-07-11 18:20             ` John Cowan
  2020-07-12 16:08             ` Catonano
  1 sibling, 2 replies; 36+ messages in thread
From: Chris Vine @ 2020-07-11 10:13 UTC (permalink / raw)
  To: guile-user

On Sat, 11 Jul 2020 02:19:43 +0200
Zelphir Kaltstahl <zelphirkaltstahl@posteo.de> wrote:
[snip]
> I would be glad, if any non-optimal example was extended or updated by a
> more knowledgeable person or I was told what I could improve in some
> example. The examples in the repository are only, what I was able to
> understand and I often find myself looking up, how to do something again.
> 
> If anyone wants to take any example and put it in the docs, go ahead.
> Only don't think that my examples are the last word on how to do things.
> Far from it!
> 
> About the exceptions thing: Aha! I should look into that again. I
> thought the "conditions" thing was already pretty cool and useful. Once
> an exception happens, you can react on it. I did not understand the
> "call/ec helper" part, but perhaps I can understand it, when I check the
> docs for the new exceptions in Guile 3.

The issue is that "non-continuable" in "non-continuable exception" does
not mean an exception that the program cannot survive, it means an
exception for which, after handling, control cannot return to the point
at which the exception was raised[1].  (To answer the question in your
following email, continuable exceptions are in some sense analogous to
common lisp restarts.)  Most guile exceptions are non-continuable.  The
point arising from this is that in the case of a non-continuable
exception the handler procedure passed to with-exception-handler must
not return, or a &non-continuable exception will be raised when
control does attempt to return.

With R6RS/R7RS's with-exception-handler, for non-continuable exceptions
the handler procedure should normally therefore either invoke a call/ec
continuation object to unwind the stack to the point where the
exception is handled, or it should (after it has done what it is
intended to do) re-raise the exception to be handled and/or unwound
elsewhere.  Guile-3.0's with-exception-handler procedure will do the
former for you automatically if you set its #:unwind? argument to
true.  The nearest to guile-2.2's catch expression in guile-3.0's
exception system is to use with-exception-handler with #:unwind? set
as #t.  R6RS/R7RS's guard form is a wrapper for this which also
incorporates a cond form to enable different exception types to be
handled by different handlers. 

I therefore suggest that your first example using
with-exception-handler should set #:unwind? to #t so that the program
does not end with a &non-continuable exception.  I also suggest that,
if intended for guile-3.0 and not guile-2.2, you should use guile's
exception objects rather than R6RS conditions (basically you use
'make-exception' instead of 'condition' - the two are in effect the
same).

If intended also for guile-2.2 the other issue is that its R6RS/R7RS
exception procedures can only handle R6RS/R7RS exceptions emitted by
raise or raise-continuable, and not guile exceptions raised by throw.
This means that your divide by 0 example will not work in guile-2.2.

Chris

[1]  Microsoft in its C++ and .NET languages amalgamates machine
exceptions, and some signal exceptions, with language exceptions.  In
their nomenclature "non-continuable exception" does mean an exception
that the program cannot survive, such as SIGSEGV or an irrecoverable
hardware exception.  This is not however its general meaning.  Most
languages do not have continuable exceptions.  Scheme, common lisp and
smalltalk do.



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

* Re: "Missing" libraries/concepts found in other languages/ecosystems?
  2020-07-11  0:34           ` Zelphir Kaltstahl
@ 2020-07-11 10:14             ` Chris Vine
  2020-07-11 13:45               ` Stefan Israelsson Tampe
  2020-07-11 14:46             ` Linus Björnstam
  1 sibling, 1 reply; 36+ messages in thread
From: Chris Vine @ 2020-07-11 10:14 UTC (permalink / raw)
  To: guile-user

On Sat, 11 Jul 2020 02:34:22 +0200
Zelphir Kaltstahl <zelphirkaltstahl@posteo.de> wrote:
> The comments about exception handling also reminded me of the following
> blog post:
> 
> https://blog.sulami.xyz/posts/common-lisp-restarts/
> 
> Pretty cool concept as well.
> 
> If there anything like it in Guile or is something like it possible
> (probably, right?)?

I think common lisp restarts are by and large useless.  They rely on
the assumption that the caller of a procedure which throws knows better
how to handle an exception arising in that procedure than the procedure
itself.  That is rarely the case.  Usually the code at the site of the
error should do what it can to remedy the problem and then (if it cannot
be fully rectified) throw an exception which unwinds the stack, for the
exception to be picked up elsewhere.

That is how most exception systems work.  Scheme's continuable
exceptions are analogous to restarts (albeit only having the exception
site as their destination) and suffer from the same problem in my
view.  The only place I have seen restarts used in action are in
building REPLs.



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

* Re: "Missing" libraries/concepts found in other languages/ecosystems?
  2020-07-11 10:14             ` Chris Vine
@ 2020-07-11 13:45               ` Stefan Israelsson Tampe
  0 siblings, 0 replies; 36+ messages in thread
From: Stefan Israelsson Tampe @ 2020-07-11 13:45 UTC (permalink / raw)
  To: Chris Vine; +Cc: Guile User

Intersting discussion, thanks. Was able to fix a bug thanks to you.

On Sat, Jul 11, 2020 at 12:14 PM Chris Vine <vine35792468@gmail.com> wrote:

> On Sat, 11 Jul 2020 02:34:22 +0200
> Zelphir Kaltstahl <zelphirkaltstahl@posteo.de> wrote:
> > The comments about exception handling also reminded me of the following
> > blog post:
> >
> > https://blog.sulami.xyz/posts/common-lisp-restarts/
> >
> > Pretty cool concept as well.
> >
> > If there anything like it in Guile or is something like it possible
> > (probably, right?)?
>
> I think common lisp restarts are by and large useless.  They rely on
> the assumption that the caller of a procedure which throws knows better
> how to handle an exception arising in that procedure than the procedure
> itself.  That is rarely the case.  Usually the code at the site of the
> error should do what it can to remedy the problem and then (if it cannot
> be fully rectified) throw an exception which unwinds the stack, for the
> exception to be picked up elsewhere.
>
> That is how most exception systems work.  Scheme's continuable
> exceptions are analogous to restarts (albeit only having the exception
> site as their destination) and suffer from the same problem in my
> view.  The only place I have seen restarts used in action are in
> building REPLs.
>
>


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

* Re: "Missing" libraries/concepts found in other languages/ecosystems?
  2020-07-11  0:34           ` Zelphir Kaltstahl
  2020-07-11 10:14             ` Chris Vine
@ 2020-07-11 14:46             ` Linus Björnstam
  1 sibling, 0 replies; 36+ messages in thread
From: Linus Björnstam @ 2020-07-11 14:46 UTC (permalink / raw)
  To: Zelphir Kaltstahl, Catonano, Chris Vine; +Cc: Guile User


On Sat, 11 Jul 2020, at 02:34, Zelphir Kaltstahl wrote:
> The comments about exception handling also reminded me of the following
> blog post:
> 
> https://blog.sulami.xyz/posts/common-lisp-restarts/
> 
> Pretty cool concept as well.
> 
> If there anything like it in Guile or is something like it possible
> (probably, right?)?

I implemented a restart system in top of call/cc back in 2012, but that was slow and had some interesting (as in completely wrong) edge cases. 

Doing it with delimited continuations should be fast and a lot simpler. Someone took my code and made it useful for chez, and then I saw something that looked vaguely similar in one of the r7rs-large dockets. 

Anyway, it is possible and probably not more than 100loc to do it properly using continuations.
> 
> 
> On 7/11/20 2:19 AM, Zelphir Kaltstahl wrote:
> > Hi all!
> >
> > On 7/10/20 1:20 PM, Catonano wrote:
> >> Il giorno ven 10 lug 2020 alle ore 12:21 Chris Vine <vine35792468@gmail.com>
> >> ha scritto:
> >>
> >>> On Fri, 10 Jul 2020 10:49:37 +0200
> >>> Catonano <catonano@gmail.com> wrote:
> >>>> Il giorno mer 8 lug 2020 alle ore 20:22 Zelphir Kaltstahl <
> >>>> zelphirkaltstahl@gmail.com> ha scritto:
> >>>>
> >>>>> Hi Simen!
> >>>>>
> >>>>> On 7/8/20 6:00 PM, guile-user-request@gnu.org wrote:
> >>>>>> Hi, I'm new to scheme/lisp, so I'm trying to find out how to do
> >>>>>> things the "lisp
> >>>>>> way". On the other hand, I like things from other ecosystems too,
> >>>>>> and I'm having
> >>>>>> problems finding this for Guile. It might be because there's no
> >>>>>> need for it/I'm
> >>>>>> terrible at searching/nobody had the time yet, or something else.
> >>>>>>
> >>>>>> I've been trying to find implementations for https://reactivex.io
> >>>>>> without any
> >>>>>> luck. And I'm unable to find implementation of FP concepts as
> >>>>>> found in Haskell
> >>>>>> and other languages. Functor, Monad, lenses (and other helpers for
> >>>>>> working with
> >>>>>> immutable data).
> >>>>>>
> >>>>>> Does things like this exists, or is it better to use something
> >>>>>> else?
> >>>>>>
> >>>>>> Regards Simen
> >>>>> To what others already have written I will add:
> >>>>>
> >>>>> From time to time one can copy ideas from Racket or look at what exists
> >>>>> in Racket for solving a problem or seeing what the approach is.
> >>>>>
> >>>>> Catonano identified already the lack of examples in the Guile guide. I
> >>>>> fight with that myself, so I created a repository with examples.
> >>> Perhaps
> >>>>> I should somehow add them to the guide. I've not looked into how to do
> >>>>> that. Probably some commit in a repo somewhere for the guide:
> >>>>>
> >>>>> https://notabug.org/ZelphirKaltstahl/guile-examples
> >>>>>
> >>>>> Hope this can help!
> >>>>>
> >>>> Thank you, yes that helps
> >>>>
> >>>> In fact, it's a precious resource !
> >>>>
> >>>> I was especially delighted with the examples of using exceptions !
> >>>>
> >>>> I had so missed examples of those !
> >>>>
> >>>> As for the manual, very recently a mention of Guile Hall ended up being
> >>>> included in the manual
> >>>>
> >>>> The same could be done with your examples collection
> >>>>
> >>>> I also think that your collection could be mentioned by the Guile web
> >>> site,
> >>>> maybe in the "learn" section
> >>>>
> >>>> Here's the repo for the web site:
> >>>> https://git.savannah.gnu.org/cgit/guile/guile-web.git/
> >>>>
> >>>> a regular patch could do
> >>>>
> >>>> What do people think of mentioning this resource on the Guile web site ?
> >>> Whilst I don't have strong feelings, as a general approach I think it is
> >>> better to include additional examples (where needed) in the body of the
> >>> manual, which I think is generally well written.
> >>>
> >> As long as some examples are reachable from an officially sanctioned
> >> documentation source, I'm ok with that
> >>
> >> What I find problematic is the casualness in referring to bits scattered
> >> all around
> >>
> >> The web site was just an idea, the manual would be perfectly fine
> >>
> >> Also, at this level of detail what some find helpful others don't.  You
> >>> were delighted above with the exceptions example, whereas (if I read
> >>> the right one) I thought that that was one of the weaker ones.  It
> >>> concentrates on R6RS/R7RS exceptions and with-exception-handler rather
> >>> than with guile's much easier to use catch expression (for guile-2.2)
> >>> or (for guile-3.0) its beefed-up with-exception-handler and exception
> >>> objects.
> >>>
> >> Ah there has been a misunderstanding here
> >>
> >> I was convinced that the exceptions example was of the last layout for
> >> using exceptions reached recently in Guile 3.x
> >>
> >> If it's not, I agree it's less valuable
> >>
> >> But I think the author was just confused or led astray by the casualness of
> >> referring to scattered bits, I'm not blaming them
> >>
> >> I'd be grateful if anyone with enough understanding of the issue would
> >> contribute a proper example of how to use exceptions according to the last
> >> exceptions reorganization in Guile 3.x
> >>
> >> I would be happy to send a patch for the manual containing such example and
> >> a few words, as I did with the mention of Guile Hall
> >>
> >>
> >> with-exception-handler is a tricky beast and the example didn't deal
> >>> with the main case: most uses of exceptions involve handling them and
> >>> moving on with program execution from the point where the exception is
> >>> caught, and to do that using with-exception-handler instead of
> >>> guile's 'catch' form you have to have a call/ec helper (or with
> >>> guile-3.0 you can just set the #unwind argument to true).  Instead you
> >>> are left with the idea that you use continuable exceptions for that
> >>> (which while they do stop the program exiting are something different)
> >>> or the R6RS/R7RS guard form.
> >>>
> >> I'm not following you on this because I don't know enough of both the Guile
> >> new idea of how to use exceptions and the R6/7RS one
> >>
> >>
> >>> I am not trying to be critical here - I think examples are useful to
> >>> convey points and some of them were fine.  My point is more about venue.
> >>>
> >>  No, that's ok, that's why I asked
> >>
> >> In fact, should we end up with a proper example in the manual, that would
> >> be a positive outcome
> >>
> >> I'd say more, here
> >>
> >> I'd go systematically through all the examples in that repo and do a
> >> similar assessment if we can add it to the manual as is or if it needs
> >> refinement
> >>
> >> I can't do this on my own because in many cases I don't know enough to come
> >> up with valid examples myself
> >>
> >> But I'd be happy to prepare patches for the manual, given the right
> >> directions
> >
> > I would be glad, if any non-optimal example was extended or updated by a
> > more knowledgeable person or I was told what I could improve in some
> > example. The examples in the repository are only, what I was able to
> > understand and I often find myself looking up, how to do something again.
> >
> > If anyone wants to take any example and put it in the docs, go ahead.
> > Only don't think that my examples are the last word on how to do things.
> > Far from it!
> >
> > About the exceptions thing: Aha! I should look into that again. I
> > thought the "conditions" thing was already pretty cool and useful. Once
> > an exception happens, you can react on it. I did not understand the
> > "call/ec helper" part, but perhaps I can understand it, when I check the
> > docs for the new exceptions in Guile 3.
> >
> > I had another thought: Why do we not create this kind of so called
> > "awesome list" for Guile? There were some links in this discussion,
> > which might be a good fit on such a list and it is kind of informal,
> > easy to extend. Whenever someone asks for pointers, we could also
> > mention that list and perhaps they can find cool things in it. They
> > could see, that Guile is viable, because there are so many things people
> > do with Guile, or they could see their use case covered already.
> >
> > Best regards,
> > Zelphir
> >
> >
> 
>



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

* Re: "Missing" libraries/concepts found in other languages/ecosystems?
  2020-07-11 10:13           ` Chris Vine
@ 2020-07-11 18:20             ` John Cowan
  2020-07-11 22:39               ` Chris Vine
  2020-07-12 16:08             ` Catonano
  1 sibling, 1 reply; 36+ messages in thread
From: John Cowan @ 2020-07-11 18:20 UTC (permalink / raw)
  To: Chris Vine; +Cc: guile-user

On Sat, Jul 11, 2020 at 6:14 AM Chris Vine <vine35792468@gmail.com> wrote:


> (To answer the question in your
> following email, continuable exceptions are in some sense analogous to
> common lisp restarts.)


Continuable and non-continuable in Scheme are exactly like CL raise and
error (and its variants), except that the machinery is different.  Restarts
are another matter, independent of the condition system (though often
considered with it).  I have a pre-SRFI for them at <
https://github.com/johnwcowan/r7rs-work/blob/master/RestartsCowan.md>,
similar to but simpler than the CL restart system, and using first-class
restarts.  It currently lacks restart-case.

The point arising from this is that in the case of a non-continuable
> exception the handler procedure passed to with-exception-handler must
> not return, or a &non-continuable exception will be raised when
> control does attempt to return.
>

In CL the exact machinery is different: a CL handler refuses to handle a
condition by returning.  A continuable exception must use a non-local exit
to get back to the signaler, whereas an unhandled non-continuable exception
drops into the semi-standardized facility called the debugger.


> R6RS/R7RS's guard form is a wrapper for this which also
> incorporates a cond form to enable different exception types to be
> handled by different handlers.
>

Is the intention to provide `guard` in Guile 3.x?

I think common lisp restarts are by and large useless.  They rely on
> the assumption that the caller of a procedure which throws knows better
> how to handle an exception arising in that procedure than the procedure
> itself.  That is rarely the case.  Usually the code at the site of the
> error should do what it can to remedy the problem and then (if it cannot
> be fully rectified) throw an exception which unwinds the stack, for the
> exception to be picked up elsewhere.


Here's a straightforward example of restarts in action.  Suppose a library
reads a file in a format known to itself, performs some complex in-memory
transformations of the data, and then writes the data to another or the
same file in the same format. Of course the files may be inaccessible to
the library for whatever reasons, and some kind of recovery is needed.

The usual approach is to export three procedures: one to read the input
file and return the data in an opaque internal format, one to process the
data and return the transformed data, and one to write the output file.
Any of them may throw exceptions if something goes wrong.  However, this
exposes the internal data format to the caller, and requires the caller to
strictly follow the input-process-output sequence of calls, a tiny design
pattern.

With continuable exceptions plus restarts, however, there can be just one
exposed procedure which is passed an input file name and an output file
name which does it all.  If any of the I/O components fail, a continuable
exception can be raised which when handled invokes a restart (of type
"use-value") with the name of a replacement file name to use instead.

As a result, the opaque data is now always concealed from the caller, but a
write failure does not require the already-transformed data to be
recomputed.  Just as a condition communicates information from a signaler
(which knows what is wrong) to a handler (which knows what to do), a
restart communicates information from the handler (which knows what should
be done) back to the signaler (which knows how to do it).



John Cowan          http://vrici.lojban.org/~cowan        cowan@ccil.org
All Norstrilians knew that humor was "pleasurable corrigible malfunction".
        --Cordwainer Smith, Norstrilia


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

* Re: "Missing" libraries/concepts found in other languages/ecosystems?
  2020-07-11 18:20             ` John Cowan
@ 2020-07-11 22:39               ` Chris Vine
  2020-07-11 22:41                 ` John Cowan
  2020-07-13 10:10                 ` Chris Vine
  0 siblings, 2 replies; 36+ messages in thread
From: Chris Vine @ 2020-07-11 22:39 UTC (permalink / raw)
  To: guile-user

On Sat, 11 Jul 2020 14:20:22 -0400
John Cowan <cowan@ccil.org> wrote:
> On Sat, Jul 11, 2020 at 6:14 AM Chris Vine <vine35792468@gmail.com> wrote:
> 
> > (To answer the question in your
> > following email, continuable exceptions are in some sense analogous to
> > common lisp restarts.)
>
> Continuable and non-continuable in Scheme are exactly like CL raise and
> error (and its variants), except that the machinery is different.  Restarts
> are another matter, independent of the condition system (though often
> considered with it).  I have a pre-SRFI for them at <
> https://github.com/johnwcowan/r7rs-work/blob/master/RestartsCowan.md>,
> similar to but simpler than the CL restart system, and using first-class
> restarts.  It currently lacks restart-case.

I am not an expert on CL so can you provide me with the hyperspec
reference to CL 'RAISE'?  (I know about CL 'ERROR' and 'SIGNAL'.)
 
[snip]
> > R6RS/R7RS's guard form is a wrapper for this which also
> > incorporates a cond form to enable different exception types to be
> > handled by different handlers.
> >
> 
> Is the intention to provide `guard` in Guile 3.x?

It's been in guile for as long as I can remember (at least since 2.0).



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

* Re: "Missing" libraries/concepts found in other languages/ecosystems?
  2020-07-11 22:39               ` Chris Vine
@ 2020-07-11 22:41                 ` John Cowan
  2020-07-11 23:09                   ` Chris Vine
  2020-07-13 10:10                 ` Chris Vine
  1 sibling, 1 reply; 36+ messages in thread
From: John Cowan @ 2020-07-11 22:41 UTC (permalink / raw)
  To: Chris Vine; +Cc: guile-user

Sorry, I meant SIGNAL, not RAISE, in CL.  I'm glad Guile supports `guard`.

On Sat, Jul 11, 2020 at 6:39 PM Chris Vine <vine35792468@gmail.com> wrote:

> On Sat, 11 Jul 2020 14:20:22 -0400
> John Cowan <cowan@ccil.org> wrote:
> > On Sat, Jul 11, 2020 at 6:14 AM Chris Vine <vine35792468@gmail.com>
> wrote:
> >
> > > (To answer the question in your
> > > following email, continuable exceptions are in some sense analogous to
> > > common lisp restarts.)
> >
> > Continuable and non-continuable in Scheme are exactly like CL raise and
> > error (and its variants), except that the machinery is different.
> Restarts
> > are another matter, independent of the condition system (though often
> > considered with it).  I have a pre-SRFI for them at <
> > https://github.com/johnwcowan/r7rs-work/blob/master/RestartsCowan.md>,
> > similar to but simpler than the CL restart system, and using first-class
> > restarts.  It currently lacks restart-case.
>
> I am not an expert on CL so can you provide me with the hyperspec
> reference to CL 'RAISE'?  (I know about CL 'ERROR' and 'SIGNAL'.)
>
> [snip]
> > > R6RS/R7RS's guard form is a wrapper for this which also
> > > incorporates a cond form to enable different exception types to be
> > > handled by different handlers.
> > >
> >
> > Is the intention to provide `guard` in Guile 3.x?
>
> It's been in guile for as long as I can remember (at least since 2.0).
>
>


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

* Re: "Missing" libraries/concepts found in other languages/ecosystems?
  2020-07-11 22:41                 ` John Cowan
@ 2020-07-11 23:09                   ` Chris Vine
  2020-07-12  1:52                     ` John Cowan
  0 siblings, 1 reply; 36+ messages in thread
From: Chris Vine @ 2020-07-11 23:09 UTC (permalink / raw)
  To: guile-user

On Sat, 11 Jul 2020 18:41:34 -0400
John Cowan <cowan@ccil.org> wrote:
> On Sat, Jul 11, 2020 at 6:39 PM Chris Vine <vine35792468@gmail.com> wrote:
> > On Sat, 11 Jul 2020 14:20:22 -0400
> > John Cowan <cowan@ccil.org> wrote:
> > > On Sat, Jul 11, 2020 at 6:14 AM Chris Vine <vine35792468@gmail.com>
> > wrote:
> > >
> > > > (To answer the question in your
> > > > following email, continuable exceptions are in some sense analogous to
> > > > common lisp restarts.)
> > >
> > > Continuable and non-continuable in Scheme are exactly like CL raise and
> > > error (and its variants), except that the machinery is different.
> > Restarts
> > > are another matter, independent of the condition system (though often
> > > considered with it).  I have a pre-SRFI for them at <
> > > https://github.com/johnwcowan/r7rs-work/blob/master/RestartsCowan.md>,
> > > similar to but simpler than the CL restart system, and using first-class
> > > restarts.  It currently lacks restart-case.
> >
> > I am not an expert on CL so can you provide me with the hyperspec
> > reference to CL 'RAISE'?  (I know about CL 'ERROR' and 'SIGNAL'.)
> >
> > [snip]
> > > > R6RS/R7RS's guard form is a wrapper for this which also
> > > > incorporates a cond form to enable different exception types to be
> > > > handled by different handlers.
> > > >
> > >
> > > Is the intention to provide `guard` in Guile 3.x?
> >
> > It's been in guile for as long as I can remember (at least since 2.0).
>
> Sorry, I meant SIGNAL, not RAISE, in CL.  I'm glad Guile supports `guard`.

So when you said "continuable and non-continuable in Scheme are exactly
like CL [signal] and error (and its variants)" are you then saying that
SIGNAL == continuable (ie raise-continuable in R6RS) and ERROR ==
non-continuable (ie raise in R6RS)?  If not, can you re-express what
you were intending to say?

In what way do you say that continuable exceptions are not in some sense
analogous to common lisp restarts (noting the "in some sense"?



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

* Re: "Missing" libraries/concepts found in other languages/ecosystems?
  2020-07-11 23:09                   ` Chris Vine
@ 2020-07-12  1:52                     ` John Cowan
  2020-07-12 20:26                       ` Chris Vine
  0 siblings, 1 reply; 36+ messages in thread
From: John Cowan @ 2020-07-12  1:52 UTC (permalink / raw)
  To: Chris Vine; +Cc: guile-user

On Sat, Jul 11, 2020 at 7:10 PM Chris Vine <vine35792468@gmail.com> wrote:

So when you said "continuable and non-continuable in Scheme are exactly
> like CL [signal] and error (and its variants)" are you then saying that
> SIGNAL == continuable (ie raise-continuable in R6RS) and ERROR ==
> non-continuable (ie raise in R6RS)?


That is what I meant.


> In what way do you say that continuable exceptions are not in some sense
> analogous to common lisp restarts (noting the "in some sense"?
>

Well, okay, but in *what* sense?  You made the claim in the first place; I
think the burden of persuasion lies with you.



John Cowan          http://vrici.lojban.org/~cowan        cowan@ccil.org
Mos Eisley spaceport.  You will never see a more wretched hive of scum
and villainy --unless you watch the Jerry Springer Show.
        --georgettesworld.com


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

* Re: "Missing" libraries/concepts found in other languages/ecosystems?
  2020-07-11 10:13           ` Chris Vine
  2020-07-11 18:20             ` John Cowan
@ 2020-07-12 16:08             ` Catonano
  2020-07-12 16:10               ` Catonano
                                 ` (3 more replies)
  1 sibling, 4 replies; 36+ messages in thread
From: Catonano @ 2020-07-12 16:08 UTC (permalink / raw)
  To: Chris Vine; +Cc: Guile User

Il giorno sab 11 lug 2020 alle ore 12:14 Chris Vine <vine35792468@gmail.com>
ha scritto:

> On Sat, 11 Jul 2020 02:19:43 +0200
> Zelphir Kaltstahl <zelphirkaltstahl@posteo.de> wrote:
> [snip]
> > I would be glad, if any non-optimal example was extended or updated by a
> > more knowledgeable person or I was told what I could improve in some
> > example. The examples in the repository are only, what I was able to
> > understand and I often find myself looking up, how to do something again.
> >
> > If anyone wants to take any example and put it in the docs, go ahead.
> > Only don't think that my examples are the last word on how to do things.
> > Far from it!
> >
> > About the exceptions thing: Aha! I should look into that again. I
> > thought the "conditions" thing was already pretty cool and useful. Once
> > an exception happens, you can react on it. I did not understand the
> > "call/ec helper" part, but perhaps I can understand it, when I check the
> > docs for the new exceptions in Guile 3.
>
> The issue is that "non-continuable" in "non-continuable exception" does
> not mean an exception that the program cannot survive, it means an
> exception for which, after handling, control cannot return to the point
> at which the exception was raised[1].  (To answer the question in your
> following email, continuable exceptions are in some sense analogous to
> common lisp restarts.)  Most guile exceptions are non-continuable.  The
> point arising from this is that in the case of a non-continuable
> exception the handler procedure passed to with-exception-handler must
> not return, or a &non-continuable exception will be raised when
> control does attempt to return.
>
> With R6RS/R7RS's with-exception-handler, for non-continuable exceptions
> the handler procedure should normally therefore either invoke a call/ec
> continuation object to unwind the stack to the point where the
> exception is handled, or it should (after it has done what it is
> intended to do) re-raise the exception to be handled and/or unwound
> elsewhere.  Guile-3.0's with-exception-handler procedure will do the
> former for you automatically if you set its #:unwind? argument to
> true.  The nearest to guile-2.2's catch expression in guile-3.0's
> exception system is to use with-exception-handler with #:unwind? set
> as #t.  R6RS/R7RS's guard form is a wrapper for this which also
> incorporates a cond form to enable different exception types to be
> handled by different handlers.
>
> I therefore suggest that your first example using
> with-exception-handler should set #:unwind? to #t so that the program
> does not end with a &non-continuable exception.  I also suggest that,
> if intended for guile-3.0 and not guile-2.2, you should use guile's
> exception objects rather than R6RS conditions (basically you use
> 'make-exception' instead of 'condition' - the two are in effect the
> same).
>


If it can be of any help, I applied your suggestions to the original
example

This is supposed to be compatible with Guile 3.x only

Here it is (a question follows)

(define even-simpler-display
  (lambda (sth)
    (display
     (simple-format
      #f "~a\n" sth))))


(define divide
  (lambda (a b)
    (cond
     [(= b 0)
      (raise-continuable
       (make-exception
        (make-exception-with-message "division by zero")
        (make-exception-with-irritants (list a b))
        (make-exception-with-origin 'divide)))]
     [else
      (/ a b)])))


(with-exception-handler
    (lambda (conditions-or-value)
      (even-simpler-display
       ;; We can get the simple exceptions from a compound exception with
the
       ;; `simple-exceptions` getter.
       (simple-exceptions conditions-or-value)))
  (lambda ()
    (divide 2 0))
    #:unwind? #t)

I run this in the REPL and it seems to work

The question, now, is:

say that the exception handler knows (somehow) that the correct divisor is
1 rather than 0

So we are saying that this exception is continuable

How would we continue ?

Can "divide" return as if it had been called with 1 as its second argument ?

Or have I misunderstood ?

How would you go about that ?


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

* Re: "Missing" libraries/concepts found in other languages/ecosystems?
  2020-07-12 16:08             ` Catonano
@ 2020-07-12 16:10               ` Catonano
  2020-07-12 17:46               ` John Cowan
                                 ` (2 subsequent siblings)
  3 siblings, 0 replies; 36+ messages in thread
From: Catonano @ 2020-07-12 16:10 UTC (permalink / raw)
  To: Chris Vine; +Cc: Guile User

I forgot to mention that tha modules I'm using, in this case are

(use-modules (ice-9 exceptions))

instead of the rnrs ones of the previous example


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

* Re: "Missing" libraries/concepts found in other languages/ecosystems?
  2020-07-12 16:08             ` Catonano
  2020-07-12 16:10               ` Catonano
@ 2020-07-12 17:46               ` John Cowan
  2020-07-12 19:14               ` Chris Vine
  2020-07-12 20:33               ` Zelphir Kaltstahl
  3 siblings, 0 replies; 36+ messages in thread
From: John Cowan @ 2020-07-12 17:46 UTC (permalink / raw)
  To: Catonano; +Cc: Guile User

On Sun, Jul 12, 2020 at 12:09 PM Catonano <catonano@gmail.com> wrote:

How would we continue ?
>

The simplest approach is just to return from the condition handler with the
value 1, and set up `divide` to take whatever `raise-continuable` returns
and use it as the new divisor.

However, if there are to be several different recovery schemes (for
example, change the divisor, signal a non-continuable error from `divide`,
tell `divide` to return +nan.0), then restarts are your friend.



John Cowan          http://vrici.lojban.org/~cowan        cowan@ccil.org
I could dance with you till the cows come home.  On second thought,
I'd rather dance with the cows when you come home.
        --Rufus T. Firefly


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

* Re: "Missing" libraries/concepts found in other languages/ecosystems?
  2020-07-12 16:08             ` Catonano
  2020-07-12 16:10               ` Catonano
  2020-07-12 17:46               ` John Cowan
@ 2020-07-12 19:14               ` Chris Vine
  2020-07-12 19:32                 ` Chris Vine
  2020-07-12 20:33               ` Zelphir Kaltstahl
  3 siblings, 1 reply; 36+ messages in thread
From: Chris Vine @ 2020-07-12 19:14 UTC (permalink / raw)
  To: guile-user

On Sun, 12 Jul 2020 18:08:33 +0200
Catonano <catonano@gmail.com> wrote:
> Il giorno sab 11 lug 2020 alle ore 12:14 Chris Vine <vine35792468@gmail.com>
> ha scritto:
> 
> > On Sat, 11 Jul 2020 02:19:43 +0200
> > Zelphir Kaltstahl <zelphirkaltstahl@posteo.de> wrote:
> > [snip]
> > > I would be glad, if any non-optimal example was extended or updated by a
> > > more knowledgeable person or I was told what I could improve in some
> > > example. The examples in the repository are only, what I was able to
> > > understand and I often find myself looking up, how to do something again.
> > >
> > > If anyone wants to take any example and put it in the docs, go ahead.
> > > Only don't think that my examples are the last word on how to do things.
> > > Far from it!
> > >
> > > About the exceptions thing: Aha! I should look into that again. I
> > > thought the "conditions" thing was already pretty cool and useful. Once
> > > an exception happens, you can react on it. I did not understand the
> > > "call/ec helper" part, but perhaps I can understand it, when I check the
> > > docs for the new exceptions in Guile 3.
> >
> > The issue is that "non-continuable" in "non-continuable exception" does
> > not mean an exception that the program cannot survive, it means an
> > exception for which, after handling, control cannot return to the point
> > at which the exception was raised[1].  (To answer the question in your
> > following email, continuable exceptions are in some sense analogous to
> > common lisp restarts.)  Most guile exceptions are non-continuable.  The
> > point arising from this is that in the case of a non-continuable
> > exception the handler procedure passed to with-exception-handler must
> > not return, or a &non-continuable exception will be raised when
> > control does attempt to return.
> >
> > With R6RS/R7RS's with-exception-handler, for non-continuable exceptions
> > the handler procedure should normally therefore either invoke a call/ec
> > continuation object to unwind the stack to the point where the
> > exception is handled, or it should (after it has done what it is
> > intended to do) re-raise the exception to be handled and/or unwound
> > elsewhere.  Guile-3.0's with-exception-handler procedure will do the
> > former for you automatically if you set its #:unwind? argument to
> > true.  The nearest to guile-2.2's catch expression in guile-3.0's
> > exception system is to use with-exception-handler with #:unwind? set
> > as #t.  R6RS/R7RS's guard form is a wrapper for this which also
> > incorporates a cond form to enable different exception types to be
> > handled by different handlers.
> >
> > I therefore suggest that your first example using
> > with-exception-handler should set #:unwind? to #t so that the program
> > does not end with a &non-continuable exception.  I also suggest that,
> > if intended for guile-3.0 and not guile-2.2, you should use guile's
> > exception objects rather than R6RS conditions (basically you use
> > 'make-exception' instead of 'condition' - the two are in effect the
> > same).
> >
> 
> 
> If it can be of any help, I applied your suggestions to the original
> example
> 
> This is supposed to be compatible with Guile 3.x only
> 
> Here it is (a question follows)
> 
> (define even-simpler-display
>   (lambda (sth)
>     (display
>      (simple-format
>       #f "~a\n" sth))))
> 
> 
> (define divide
>   (lambda (a b)
>     (cond
>      [(= b 0)
>       (raise-continuable
>        (make-exception
>         (make-exception-with-message "division by zero")
>         (make-exception-with-irritants (list a b))
>         (make-exception-with-origin 'divide)))]
>      [else
>       (/ a b)])))
> 
> 
> (with-exception-handler
>     (lambda (conditions-or-value)
>       (even-simpler-display
>        ;; We can get the simple exceptions from a compound exception with
> the
>        ;; `simple-exceptions` getter.
>        (simple-exceptions conditions-or-value)))
>   (lambda ()
>     (divide 2 0))
>     #:unwind? #t)
> 
> I run this in the REPL and it seems to work
> 
> The question, now, is:
> 
> say that the exception handler knows (somehow) that the correct divisor is
> 1 rather than 0
> 
> So we are saying that this exception is continuable
> 
> How would we continue ?
> 
> Can "divide" return as if it had been called with 1 as its second argument ?
> 
> Or have I misunderstood ?
> 
> How would you go about that ?

First, you would need to have #:unwind? set to #f (the default) so that
the stack doesn't unwind, otherwise the stack is unwound to the dynamic
context in which with-exception-handler was called.

Secondly, if the handler returns and #:unwind? is set to #f then
raise-continuable will return with the value returned by the handler.
So this:

  (with-exception-handler
      (lambda (x) (+ x 3))
    (lambda () (+ (raise-continuable 10) 6)))

will evaluate to 19: the variable 'x' in the handler will be bound to
the value raised, which in this case is a number (10), the handler will
accordingly return 13, and 6 is added to the value returned by the
handler.  (Here the exception raised is an integer and not a guile
exception object in order to demonstrate the principle, but the same
point applies if an exception object is raised.)

With that format you should be able to tell the code committing the
divide by 0 error what to do with respect to the divisor.



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

* Re: "Missing" libraries/concepts found in other languages/ecosystems?
  2020-07-12 19:14               ` Chris Vine
@ 2020-07-12 19:32                 ` Chris Vine
  2020-07-14 10:32                   ` Catonano
  0 siblings, 1 reply; 36+ messages in thread
From: Chris Vine @ 2020-07-12 19:32 UTC (permalink / raw)
  To: guile-user

On Sun, 12 Jul 2020 20:14:23 +0100
Chris Vine <vine35792468@gmail.com> wrote:
[snip]
> Secondly, if the handler returns and #:unwind? is set to #f then
> raise-continuable will return with the value returned by the handler.
> So this:
> 
>   (with-exception-handler
>       (lambda (x) (+ x 3))
>     (lambda () (+ (raise-continuable 10) 6)))

Ah I see you are using (ice-9 exceptions).  Better be consistent with this:

  (with-exception-handler
      (lambda (x) (+ x 3))
    (lambda () (+ (raise-exception 10 #:continuable? #t) 6))))



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

* Re: "Missing" libraries/concepts found in other languages/ecosystems?
  2020-07-12  1:52                     ` John Cowan
@ 2020-07-12 20:26                       ` Chris Vine
  0 siblings, 0 replies; 36+ messages in thread
From: Chris Vine @ 2020-07-12 20:26 UTC (permalink / raw)
  To: guile-user

On Sat, 11 Jul 2020 21:52:17 -0400
John Cowan <cowan@ccil.org> wrote:
> On Sat, Jul 11, 2020 at 7:10 PM Chris Vine <vine35792468@gmail.com> wrote:
> 
> So when you said "continuable and non-continuable in Scheme are exactly
> > like CL [signal] and error (and its variants)" are you then saying that
> > SIGNAL == continuable (ie raise-continuable in R6RS) and ERROR ==
> > non-continuable (ie raise in R6RS)?
> 
> That is what I meant.
> 
> > In what way do you say that continuable exceptions are not in some sense
> > analogous to common lisp restarts (noting the "in some sense"?
> 
> Well, okay, but in *what* sense?  You made the claim in the first place; I
> think the burden of persuasion lies with you.

I am not sure that burdens is the best way of looking at it.  But my
point of analogy was that with either restarts or continuable
exceptions, the stack is not unwound to the dynamic context in which
with-exception-handler was called, which is the norm in conventional
stack unwinding exception handling systems.  Control returns to (for
continuable exceptions) the point at which the exception was raised or
(for restarts) the relevant restart.



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

* Re: "Missing" libraries/concepts found in other languages/ecosystems?
  2020-07-12 16:08             ` Catonano
                                 ` (2 preceding siblings ...)
  2020-07-12 19:14               ` Chris Vine
@ 2020-07-12 20:33               ` Zelphir Kaltstahl
  3 siblings, 0 replies; 36+ messages in thread
From: Zelphir Kaltstahl @ 2020-07-12 20:33 UTC (permalink / raw)
  To: Catonano, Chris Vine; +Cc: Guile User

Hi!

On 7/12/20 6:08 PM, Catonano wrote:
> Il giorno sab 11 lug 2020 alle ore 12:14 Chris Vine <vine35792468@gmail.com>
> ha scritto:
>
>> On Sat, 11 Jul 2020 02:19:43 +0200
>> Zelphir Kaltstahl <zelphirkaltstahl@posteo.de> wrote:
>> [snip]
>>> I would be glad, if any non-optimal example was extended or updated by a
>>> more knowledgeable person or I was told what I could improve in some
>>> example. The examples in the repository are only, what I was able to
>>> understand and I often find myself looking up, how to do something again.
>>>
>>> If anyone wants to take any example and put it in the docs, go ahead.
>>> Only don't think that my examples are the last word on how to do things.
>>> Far from it!
>>>
>>> About the exceptions thing: Aha! I should look into that again. I
>>> thought the "conditions" thing was already pretty cool and useful. Once
>>> an exception happens, you can react on it. I did not understand the
>>> "call/ec helper" part, but perhaps I can understand it, when I check the
>>> docs for the new exceptions in Guile 3.
>> The issue is that "non-continuable" in "non-continuable exception" does
>> not mean an exception that the program cannot survive, it means an
>> exception for which, after handling, control cannot return to the point
>> at which the exception was raised[1].  (To answer the question in your
>> following email, continuable exceptions are in some sense analogous to
>> common lisp restarts.)  Most guile exceptions are non-continuable.  The
>> point arising from this is that in the case of a non-continuable
>> exception the handler procedure passed to with-exception-handler must
>> not return, or a &non-continuable exception will be raised when
>> control does attempt to return.
>>
>> With R6RS/R7RS's with-exception-handler, for non-continuable exceptions
>> the handler procedure should normally therefore either invoke a call/ec
>> continuation object to unwind the stack to the point where the
>> exception is handled, or it should (after it has done what it is
>> intended to do) re-raise the exception to be handled and/or unwound
>> elsewhere.  Guile-3.0's with-exception-handler procedure will do the
>> former for you automatically if you set its #:unwind? argument to
>> true.  The nearest to guile-2.2's catch expression in guile-3.0's
>> exception system is to use with-exception-handler with #:unwind? set
>> as #t.  R6RS/R7RS's guard form is a wrapper for this which also
>> incorporates a cond form to enable different exception types to be
>> handled by different handlers.
>>
>> I therefore suggest that your first example using
>> with-exception-handler should set #:unwind? to #t so that the program
>> does not end with a &non-continuable exception.  I also suggest that,
>> if intended for guile-3.0 and not guile-2.2, you should use guile's
>> exception objects rather than R6RS conditions (basically you use
>> 'make-exception' instead of 'condition' - the two are in effect the
>> same).
>>
>
> If it can be of any help, I applied your suggestions to the original
> example
>
> This is supposed to be compatible with Guile 3.x only
>
> Here it is (a question follows)
>
> (define even-simpler-display
>   (lambda (sth)
>     (display
>      (simple-format
>       #f "~a\n" sth))))
>
>
> (define divide
>   (lambda (a b)
>     (cond
>      [(= b 0)
>       (raise-continuable
>        (make-exception
>         (make-exception-with-message "division by zero")
>         (make-exception-with-irritants (list a b))
>         (make-exception-with-origin 'divide)))]
>      [else
>       (/ a b)])))
>
>
> (with-exception-handler
>     (lambda (conditions-or-value)
>       (even-simpler-display
>        ;; We can get the simple exceptions from a compound exception with
> the
>        ;; `simple-exceptions` getter.
>        (simple-exceptions conditions-or-value)))
>   (lambda ()
>     (divide 2 0))
>     #:unwind? #t)
>
> I run this in the REPL and it seems to work
>
> The question, now, is:
>
> say that the exception handler knows (somehow) that the correct divisor is
> 1 rather than 0
>
> So we are saying that this exception is continuable
>
> How would we continue ?
>
> Can "divide" return as if it had been called with 1 as its second argument ?
>
> Or have I misunderstood ?
>
> How would you go about that ?

Ah, I started putting "to do changes" in a list to apply them later,
with better understanding:
https://notabug.org/ZelphirKaltstahl/guile-examples/src/d670fa02369918cd3fa896cc19d5aa82966f64a3/exception-handling/notes.org
I was going to come back to points, if I do not understand anything
properly.

Perhaps I can already copy some parts from here^^

Thanks!
Zelphir




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

* Re: "Missing" libraries/concepts found in other languages/ecosystems?
  2020-07-11 22:39               ` Chris Vine
  2020-07-11 22:41                 ` John Cowan
@ 2020-07-13 10:10                 ` Chris Vine
  1 sibling, 0 replies; 36+ messages in thread
From: Chris Vine @ 2020-07-13 10:10 UTC (permalink / raw)
  To: guile-user

On Sat, 11 Jul 2020 23:39:18 +0100
Chris Vine <vine35792468@gmail.com> wrote:
> On Sat, 11 Jul 2020 14:20:22 -0400
> John Cowan <cowan@ccil.org> wrote:
> > Is the intention to provide `guard` in Guile 3.x?
> 
> It's been in guile for as long as I can remember (at least since 2.0).

By the way, guile-3.0's version of 'guard' doesn't comply with
R6RS/R7RS (I think Chez scheme's 'guard' is about the only one which
does).

After correction, R6RS and R7RS require the cond conditionals to be
evaluated and the body of any cond clause to execute in the dynamic
environment in which 'guard' was called.  If there is no cond
conditional evaluating to true and no else clause, then the dynamic
environment reverts to that of the site of the exception for the
exception to be re-raised by raise-continuable.

guile doesn't do that, I think mainly for efficiency reasons.  In
guile-3.0, the cond conditionals are evaluated in the dynamic
environment in which the exception arises, and only if there is a cond
conditional evaluating to true (or an else clause) does control pass to
the dynamic environment in which 'guard' was called for the relevant
cond clause body to execute.  So as with R6RS/R7RS, where an exception
is re-raised, that is done by raise-continuable in the dynamic context
in which the exception occurred, but a different route is chosen to get
there.

I prefer guile's approach but I imagine your view is probably different.



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

* Re: "Missing" libraries/concepts found in other languages/ecosystems?
  2020-07-12 19:32                 ` Chris Vine
@ 2020-07-14 10:32                   ` Catonano
  2020-07-14 11:06                     ` Catonano
  2020-07-14 16:21                     ` Chris Vine
  0 siblings, 2 replies; 36+ messages in thread
From: Catonano @ 2020-07-14 10:32 UTC (permalink / raw)
  To: Chris Vine; +Cc: Guile User

Il giorno dom 12 lug 2020 alle ore 21:33 Chris Vine <vine35792468@gmail.com>
ha scritto:

> On Sun, 12 Jul 2020 20:14:23 +0100
> Chris Vine <vine35792468@gmail.com> wrote:
> [snip]
> > Secondly, if the handler returns and #:unwind? is set to #f then
> > raise-continuable will return with the value returned by the handler.
> > So this:
> >
> >   (with-exception-handler
> >       (lambda (x) (+ x 3))
> >     (lambda () (+ (raise-continuable 10) 6)))
>
> Ah I see you are using (ice-9 exceptions).  Better be consistent with this:
>
>   (with-exception-handler
>       (lambda (x) (+ x 3))
>     (lambda () (+ (raise-exception 10 #:continuable? #t) 6))))
>
>

I find this a little bit confusing, admittedly

so is it

#:unwind #f

on with-exception-handler  and

#:continuable #t

on raise exception ?

Anyway, I'll try to write a new version as soon as I can bring myself to do
it

Thanks, for now


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

* Re: "Missing" libraries/concepts found in other languages/ecosystems?
  2020-07-14 10:32                   ` Catonano
@ 2020-07-14 11:06                     ` Catonano
  2020-07-14 16:21                     ` Chris Vine
  1 sibling, 0 replies; 36+ messages in thread
From: Catonano @ 2020-07-14 11:06 UTC (permalink / raw)
  To: Chris Vine; +Cc: Guile User

Il giorno mar 14 lug 2020 alle ore 12:32 Catonano <catonano@gmail.com> ha
scritto:

>
>
> Il giorno dom 12 lug 2020 alle ore 21:33 Chris Vine <
> vine35792468@gmail.com> ha scritto:
>
>> On Sun, 12 Jul 2020 20:14:23 +0100
>> Chris Vine <vine35792468@gmail.com> wrote:
>> [snip]
>> > Secondly, if the handler returns and #:unwind? is set to #f then
>> > raise-continuable will return with the value returned by the handler.
>> > So this:
>> >
>> >   (with-exception-handler
>> >       (lambda (x) (+ x 3))
>> >     (lambda () (+ (raise-continuable 10) 6)))
>>
>> Ah I see you are using (ice-9 exceptions).  Better be consistent with
>> this:
>>
>>   (with-exception-handler
>>       (lambda (x) (+ x 3))
>>     (lambda () (+ (raise-exception 10 #:continuable? #t) 6))))
>>
>>
>
> I find this a little bit confusing, admittedly
>
> so is it
>
> #:unwind #f
>
> on with-exception-handler  and
>
> #:continuable #t
>
> on raise exception ?
>
> Anyway, I'll try to write a new version as soon as I can bring myself to
> do it
>
> Thanks, for now
>
>


Obviously, should anyone want to step in and provide this example
themselves, I'd be only grateful  ¯\_(ツ)_/¯


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

* Re: "Missing" libraries/concepts found in other languages/ecosystems?
  2020-07-14 10:32                   ` Catonano
  2020-07-14 11:06                     ` Catonano
@ 2020-07-14 16:21                     ` Chris Vine
  1 sibling, 0 replies; 36+ messages in thread
From: Chris Vine @ 2020-07-14 16:21 UTC (permalink / raw)
  To: guile-user

On Tue, 14 Jul 2020 12:32:46 +0200
Catonano <catonano@gmail.com> wrote:
> Il giorno dom 12 lug 2020 alle ore 21:33 Chris Vine <vine35792468@gmail.com>
> ha scritto:
> > On Sun, 12 Jul 2020 20:14:23 +0100
> > Chris Vine <vine35792468@gmail.com> wrote:
> > [snip]
> > > Secondly, if the handler returns and #:unwind? is set to #f then
> > > raise-continuable will return with the value returned by the handler.
> > > So this:
> > >
> > >   (with-exception-handler
> > >       (lambda (x) (+ x 3))
> > >     (lambda () (+ (raise-continuable 10) 6)))
> >
> > Ah I see you are using (ice-9 exceptions).  Better be consistent with this:
> >
> >   (with-exception-handler
> >       (lambda (x) (+ x 3))
> >     (lambda () (+ (raise-exception 10 #:continuable? #t) 6))))
> 
> I find this a little bit confusing, admittedly
> 
> so is it
> 
> #:unwind #f
> 
> on with-exception-handler  and
> 
> #:continuable #t
> 
> on raise exception ?

If you want a continuable exception then you don't unwind.  If you
unwind there is no difference between a continuable exception and a
non-continuable one - you have unwound the stack and that's it.

If the exception is non-continuable (as most are), you must either
unwind, or you must in the exception handler re-raise the exception or
invoke your own continuation object.



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

end of thread, other threads:[~2020-07-14 16:21 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-08  7:38 "Missing" libraries/concepts found in other languages/ecosystems? Simen Endsjø
2020-07-08  8:15 ` Vladimir Zhbanov
2020-07-08 10:08 ` Catonano
2020-07-08 11:29 ` Chris Vine
2020-07-10 12:15 ` Christopher Lam
2020-07-10 15:52   ` Chris Vine
     [not found] <mailman.75.1594224014.21222.guile-user@gnu.org>
2020-07-08 18:22 ` Zelphir Kaltstahl
2020-07-09 18:12   ` Leo Butler
2020-07-09 19:34     ` Zelphir Kaltstahl
2020-07-10  7:39   ` Aleix Conchillo Flaqué
2020-07-10  8:14     ` Alex Sassmannshausen
2020-07-10  8:49   ` Catonano
2020-07-10 10:21     ` Chris Vine
2020-07-10 11:20       ` Catonano
2020-07-11  0:19         ` Zelphir Kaltstahl
2020-07-11  0:34           ` Zelphir Kaltstahl
2020-07-11 10:14             ` Chris Vine
2020-07-11 13:45               ` Stefan Israelsson Tampe
2020-07-11 14:46             ` Linus Björnstam
2020-07-11 10:13           ` Chris Vine
2020-07-11 18:20             ` John Cowan
2020-07-11 22:39               ` Chris Vine
2020-07-11 22:41                 ` John Cowan
2020-07-11 23:09                   ` Chris Vine
2020-07-12  1:52                     ` John Cowan
2020-07-12 20:26                       ` Chris Vine
2020-07-13 10:10                 ` Chris Vine
2020-07-12 16:08             ` Catonano
2020-07-12 16:10               ` Catonano
2020-07-12 17:46               ` John Cowan
2020-07-12 19:14               ` Chris Vine
2020-07-12 19:32                 ` Chris Vine
2020-07-14 10:32                   ` Catonano
2020-07-14 11:06                     ` Catonano
2020-07-14 16:21                     ` Chris Vine
2020-07-12 20:33               ` Zelphir Kaltstahl

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).