some refining...

func Experimental(src, dst string) error {

    //goto jumps to "label" if present; selects values right to left; is 
ignored with value´s zero value
    goto r, err := os.Open(src)
    defer r.Close()
    goto w, err := os.Create(dst)
    defer w.Close()
    goto v, err := io.Copy(w, r)
    goto err := w.Close()

    //new: a "label" is a block also holding pointer to the actual value
v:  {
    //do something with value here...
    //return error
    }

err:{
    defer os.Remove(dst)
    return fmt.Errorf("copy %s %s: %v", src, dst, err)
    }

    return nil

}

Ian Lance Taylor schrieb am Donnerstag, 14. April 2022 um 00:04:22 UTC+2:

> On Wed, Apr 13, 2022 at 2:44 PM Matthias Mädel
> <medienwer...@gmail.com> wrote:
> >
> > Please some advice if something like the following could be helpful and 
> if it is possible to implement with the compiler.
> >
> > Thank You
> >
> > func Experimental(src, dst string) error {
> >
> > //goto is blocked with err == nil
> > goto r, err := os.Open(src)
> > defer r.Close()
> > goto w, err := os.Create(dst)
> > goto v, err := io.Copy(w, r)
> > goto err := w.Close()
> > return nil
> >
> > //alternative
> > goto err {
> > r, err := os.Open(src)
> > defer r.Close()
> > w, err := os.Create(dst)
> > v, err := io.Copy(w, r)
> > err := w.Close()
> > return nil
> > }
> >
> > return err:
> > w.Close()
> > os.Remove(dst)
> > fmt.Errorf("copy %s %s: %v", src, dst, err)
>
> Has some similarities to
>
> https://go.dev/issue/32611
> https://go.dev/issue/34140
> https://go.dev/issue/37035
>
> Ian
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/047076f1-fa45-4063-8038-61b7f8c10cf5n%40googlegroups.com.

Reply via email to