Thoughts on safe GC-less slices

Paul Backus snarwin at gmail.com
Wed Nov 17 01:33:46 UTC 2021


On Tuesday, 16 November 2021 at 23:31:47 UTC, Ben Jones wrote:
> The syntax for that is obviously not great, but we might be 
> able to do better by stealing from functional languages.  
> Perhaps something like this:
>
> ```
> let (borrowedSlice; owningSlice) in {
>    //code
> }
> ```
>
> mean essentially the same as
>
> ```
> owningSlice.apply( (borrowedSlice) => { //code} );
> ```

This is basically the same lowering already provided by 
[`opApply`][1]. The only differences are

- `opApply` returns an integer code (used for control flow) 
rather than the return value of the callback.
- `opApply` uses the `foreach` keyword instead of `let`.

[1]: https://dlang.org/spec/statement.html#foreach-statement


More information about the Digitalmars-d mailing list