poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PROPOSAL] with_cur_ios() function in the stdlib


From: Jose E. Marchesi
Subject: Re: [PROPOSAL] with_cur_ios() function in the stdlib
Date: Sun, 10 Apr 2022 08:51:53 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Hi apache.

> As per discussion with Mohammad-Reza and Jose, here is a function
> proposed for inclusion in the stdlib:

Yes... this is looking good :)

> // with_cur_ios(fn, cb) calls cb with fn opened as the current ios.
> // if an exception is raised, fn will be closed before the exception
> // is re-raised, allowing the enclosed code to fail without global
> // side effects.

In the Poke source files distributed with poke we tend to use /* */
comments, especially in comments that span for more than one line.

> type void_lambda = ()void;

I think we need a more conspicuous name for that type, something less
generic.  Also, we use Camel_Case for type names as a convention.

What about With_Ios_Fn?  Then it can be used in both with_cur_ios and
with_temp_ios.

> fun with_cur_ios = (string filename, void_lambda callback)void:
>   {
>     var old_ios = get_ios ?! E_no_ios ? get_ios : -1;
>     var new_ios = open(fn);
>     set_ios(new_ios);
>     try {
>       callback();
>       close(new_ios);
>       if (-1 != old_ios) set_ios(old_ios);
>     } catch (Exception exc) {
>       close(new_ios);
>       if (-1 != old_ios) set_ios(old_ios);
>       raise exc;
>     }
>   }

The code logic looks good to me.  But in order to integrate the code in
poke the style better matches the existing style, i.e.

- Put a space between ) and void:.
- Use braces like:

  foo
  {
    ...
  }
  bar
  {
    ...
  }

  Instead of 

  foo {
    ...
  } bar {
    ...
  }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]