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 13:34:46 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

>> On Sun, Apr 10, 2022 at 02:22:13PM +0430, Mohammad-Reza Nabipoor wrote:
>>> Hello.
>>> 
>>> On Sat, Apr 09, 2022 at 07:55:16PM +0200, apache2 wrote:
>>> > type void_lambda = ()void;
>>> > fun with_cur_ios = (string filename, void_lambda callback)void:
>>> >   {
>>> >...
>>> >   }
>>> 
>>> 
>>> What about changing the function paramater `callback` to `do`, and change 
>>> the
>>> `filename` to `handle`, then user can use:
>>> 
>>> ```poke
>>> with_cur_ios
>>>   :handle "Hi"
>>>   :do lambda void:
>>>       {
>>>       };
>>> 
>>> ```
>
> This is a really nice way to use named argument calls :)
>
> It also fixes the problem of passing flags, etc, since with all
> arguments getting default values, we can omit all/only some of them, and
> call them in any order.
>
> You know what, using this style we can actually just live with one
> function, by having a default value for `handler' to the
> `get_temp_handler' function that mohammad wrote, which would generate an
> unique name for a memory IOS.
>
> Then we can simply do:
>
> with_cur_ios
>   :do lambda void: {
>        ...
>       }
>
> And it will use a temporary MEM IOS with an unique (and not really
> interesting to the user) name.

Actually... I think we need two calls.

I propose this:

with_cur_ios :ios ID :do lambda void: { ... }

  Will switch to the IOS ID (which is a descriptor) an execute the given
  lambda.  It will guaranteed that upon exitting the lambda (in any way)
  the previously selected IOS (if any) is restored.  This will not open
  nor close any IO space.

  This doesn't get handler nor flags arguments obvioulsy.

with_temp_ios :handler "whatever" :do lambda void: { ... }

  Will _open_ an IOS based on `handler' (if the handler is not specified
  it is a memory IOS with an unique name) and execute the lambda.  It is
  guaranteed that upon exitting the lambda (in any way) the temporary
  IOS gets closed and the previously selcted IOS (if any) is restored.


And I think I agree with mnabipoor: it is best to have these functions
in the standard library rather than in the run-time.

Thoughts?



reply via email to

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