e as a variable name in the main function
(it would obviously be dangerous to do this deliberately, but
this happened by accident).
The first demo runs OK.
The second fails with a 'circular reference' error.
My question is simply why this is a problem at all - the scope of
any names used i
On Wednesday, 6 September 2023 at 12:15:02 UTC, Adam D Ruppe
wrote:
On Wednesday, 6 September 2023 at 12:04:40 UTC, d007 wrote:
extern(C) int test(ref scope const(ubyte)[32] b);
extern(C) int test(ref scope const(ubyte[32]) b);
These are the same thing since the ref cannot be rebound
anyway
On Wednesday, 6 September 2023 at 12:04:40 UTC, d007 wrote:
extern(C) int test(ref scope const(ubyte)[32] b);
extern(C) int test(ref scope const(ubyte[32]) b);
These are the same thing since the ref cannot be rebound anyway;
a static array just is its contents.
```d
extern(C) int test(ref scope const(ubyte)[32] b);
```
This will automatic become this in ctfe relection
```d
extern(C) int test(ref scope const(ubyte[32]) b);
```
LDC2 1.34.0 DMD v2.104.2
On 6/26/23 2:42 PM, Cecil Ward wrote:
==
{
size_t p = offset;
++p;
scope(exit) { writeOutput( 0, p );
++p
…
++p;
return;
}
==
The correctness of its behaviour depends on what the value of p is when
it calls writeOutput(), and the value of p is being changed. To be
correct, the final value
On Monday, 26 June 2023 at 17:41:16 UTC, Paul Backus wrote:
On Saturday, 24 June 2023 at 17:00:36 UTC, Cecil Ward wrote:
I would like to use scope guards but in the guard I need to
get access to some local variables at the end of the routine.
This doesn’t really seem to make sense as to how
On Saturday, 24 June 2023 at 17:00:36 UTC, Cecil Ward wrote:
I would like to use scope guards but in the guard I need to get
access to some local variables at the end of the routine. This
doesn’t really seem to make sense as to how it would work,
because their values depend on the exact point
On Saturday, 19 November 2022 at 14:07:59 UTC, Nick Treleaven
wrote:
Hi,
The following seems like a bug to me (reduced code, FILE*
changed to int*):
```d
@safe:
struct LockedFile
{
private int* fps;
auto fp() return scope => fps;
}
void main()
{
int* p;
{
auto
On Thursday, 15 December 2022 at 20:02:38 UTC, Nick Treleaven
wrote:
auto f() return @trusted => p ? p : v.ptr;
Whoops, that can't be @trusted unless I `assert(p)`.
On Saturday, 19 November 2022 at 15:24:33 UTC, Dukc wrote:
On Saturday, 19 November 2022 at 15:02:54 UTC, Nick Treleaven
wrote:
OK, so how do I make `lf` implicitly scope?
Have the `int*` inside it to point to a local, or assign
another `scope int*` to it.
Thanks, this works:
```d
@safe
On Friday, 25 November 2022 at 15:03:57 UTC, ShadoLight wrote:
I don't grok how `lf` can survive the local scope. Or am I
missing something?
Perhaps because the local scope is not pushed as a separate
(anonymous) function on the stack... if true then, yes, then
`lf` will indeed have the same
On Friday, 25 November 2022 at 17:45:57 UTC, Paul Backus wrote:
On Friday, 25 November 2022 at 14:07:28 UTC, ShadoLight wrote:
On Saturday, 19 November 2022 at 15:00:16 UTC, Paul Backus
wrote:
Since, in your example, `lf` has global lifetime, the
compiler deduces that `lf.fp` also has global
On Friday, 25 November 2022 at 14:07:28 UTC, ShadoLight wrote:
On Saturday, 19 November 2022 at 15:00:16 UTC, Paul Backus
wrote:
Since, in your example, `lf` has global lifetime, the compiler
deduces that `lf.fp` also has global lifetime, and therefore
there is nothing wrong with assigning it
On Friday, 25 November 2022 at 14:07:28 UTC, ShadoLight wrote:
On Saturday, 19 November 2022 at 14:07:59 UTC, Nick Treleaven
```d
@safe:
struct LockedFile
{
private int* fps;
auto fp() return scope => fps;
}
void main()
{
int* p;
{
auto lf = LockedFile(new
scope => fps;
}
void main()
{
int* p;
{
auto lf = LockedFile(new int);
p = lf.fp;
}
assert(p != null); // address escaped
}
```
There's no error with -dip1000.
I'll file this unless I overlooked something.
I think this is intended behavior, because you *do*
On Saturday, 19 November 2022 at 15:02:54 UTC, Nick Treleaven
wrote:
On Saturday, 19 November 2022 at 14:52:23 UTC, ag0aep6g wrote:
That's essentially just a function that returns its pointer
parameter. So the program boils down to this:
```D
@safe:
int* fp(return scope int* p) { return p
On Saturday, 19 November 2022 at 15:02:54 UTC, Nick Treleaven
wrote:
OK, so how do I make `lf` implicitly scope?
By explicit/implicit I just meant this:
scope explicit = new int;
int x;
auto implicit =
That's probably not helping with whatever you want to accomplish.
On Saturday, 19 November 2022 at 14:52:23 UTC, ag0aep6g wrote:
That's essentially just a function that returns its pointer
parameter. So the program boils down to this:
@safe:
int* fp(return scope int* p) { return p; }
void main()
{
int* p;
{
auto lf = new int;
p
On Saturday, 19 November 2022 at 14:07:59 UTC, Nick Treleaven
wrote:
Hi,
The following seems like a bug to me (reduced code, FILE*
changed to int*):
```d
@safe:
struct LockedFile
{
private int* fps;
auto fp() return scope => fps;
}
void main()
{
int* p;
{
auto
On 19.11.22 15:07, Nick Treleaven wrote:
Hi,
The following seems like a bug to me (reduced code, FILE* changed to int*):
```d
@safe:
struct LockedFile
{
private int* fps;
auto fp() return scope => fps;
}
void main()
{
int* p;
{
auto lf = LockedFile(new
Hi,
The following seems like a bug to me (reduced code, FILE* changed
to int*):
```d
@safe:
struct LockedFile
{
private int* fps;
auto fp() return scope => fps;
}
void main()
{
int* p;
{
auto lf = LockedFile(new int);
p = lf.fp;
}
assert(p != n
accomplished is this:
```
enum LowerCaseToken { u, l, c }
struct Foo {
@safe:
int* dummy;
string[int][LowerCaseToken] _headers;
this(return ref int i)
{
dummy =
}
string[] getHeader(LowerCaseToken name) scope return
{
return _headers[name].values
like the one here[0], just annoted with
`scope` `scope return` etc. all over the place. I’m sorry, I
don’t have any copy of that around anymore (as I’ve never
commited it and already discarded my code + the idea of using
`scope` – in its current state – in real world code).
and I suspect
On Sunday, 13 November 2022 at 19:06:40 UTC, 0xEAB wrote:
Why does only the latter sample compile?
The former leads to the following warning:
Can you please provide a full example? I'm missing the
definitions of _headers, hstring, values, and I suspect there's
at least one `@safe` annotation
On Sunday, 13 November 2022 at 19:06:40 UTC, 0xEAB wrote:
```d
struct Foo { /* … */
hstring[] getHeader(LowerCaseToken name) scope return
{
return _headers[name].values;
}
[...]
There's an old saying "you can't make sense out of scope"
```d
struct Foo { /* … */
hstring[] getHeader(LowerCaseToken name) scope return
{
return _headers[name].values;
}
hstring[] getHeader(hstring name)() scope return
{
enum token = LowerCaseToken.makeConverted(name);
return this.getHeader(token); // line
On Saturday, 5 November 2022 at 16:13:18 UTC, 0xEAB wrote:
Apparently there a difference between:
- ```d
Message withBody(Body body_) return scope { /* … */ }
```
- ```d
Message withBody(Body body_) scope return { /* … */ }
```
```
Deprecation: returning `this._body` escapes
Apparently there a difference between:
- ```d
Message withBody(Body body_) return scope { /* … */ }
```
- ```d
Message withBody(Body body_) scope return { /* … */ }
```
```
Deprecation: returning `this._body` escapes a reference to
parameter `this`
perhaps change the `return
typeof(screen.output.findSplit("")) s;
Perfect. That was the "essence" of my question. But thanks to
Ali, I don't have to use such esoteric syntax. D is a wonderful
language, but I seem to shoot myself in the foot :)
On 10/25/22 6:07 PM, WhatMeWorry wrote:
I'm naturally getting a undefined identifier `s` error in the return.
Is there some way to refactor my code? I tried to declare s outside of
the else brackets like:
auto screen = executeShell(cmdLine);
auto s;
...
{
s =
On 10/25/22 15:07, WhatMeWorry wrote:
> auto screen = executeShell(cmdLine);
> auto s;
That can't work because there is no information to infer the type of
's'. Judging from the return type of getPath, perhaps it's string[]:
string[] s;
This is the question we should answer first: What
I'm naturally getting a undefined identifier `s` error in the
return. Is there some way to refactor my code? I tried to
declare s outside of the else brackets like:
auto screen = executeShell(cmdLine);
auto s;
...
{
s = screen.output.findSplit("REG_SZ");
}
but that doesn't compile
On Monday, 20 June 2022 at 13:56:04 UTC, Ruby The Roobster wrote:
Is there any way to define variables in an outer scope from an
inner scope? I was thinking
```d
void main()
{
int .y = 3;
}
```
would work, but it doesn't.
No and it would only lead to bugs.
If you have access
Is there any way to define variables in an outer scope from an inner
scope? I was thinking
```d
void main()
{
int .y = 3;
}
```
would work, but it doesn't.
On Friday, 6 May 2022 at 17:17:01 UTC, Dennis wrote:
On Friday, 6 May 2022 at 09:24:06 UTC, vit wrote:
[...]
They were recently updated to match the implementation in 2.100.
[...]
`return scope` means pointer members (such `this.ptr`, `C.ptr`)
may not escape the function, unless
On Friday, 6 May 2022 at 09:24:06 UTC, vit wrote:
It look like examples at page
https://dlang.org/spec/function.html#ref-return-scope-parameters are no longer relevant.
They were recently updated to match the implementation in 2.100.
What difference are between `return scope`, `scope return
Hello, new dmd (2.100) has return/scope changes.
It look like examples at page
https://dlang.org/spec/function.html#ref-return-scope-parameters
are no longer relevant.
What difference are between `return scope`, `scope return` and
`return`?
Why `void* ptr` in struct change effect of `scope
On 11.04.22 11:11, Salih Dincer wrote:
How is this possible? Why is it compiled? Don't the same names in the
same scope conflict?
```d
int function(int) square;
void main()
{
square = (int a) => a * a;
int square = 5.square;
assert(square == 25);
}
```
Thanks, SDB@79
- Lo
On Monday, 11 April 2022 at 09:11:06 UTC, Salih Dincer wrote:
How is this possible? Why is it compiled? Don't the same names
in the same scope conflict?
```d
int function(int) square;
void main()
{
square = (int a) => a * a;
int square = 5.square;
assert(square == 25);
}
```
Thanks,
How is this possible? Why is it compiled? Don't the same names in
the same scope conflict?
```d
int function(int) square;
void main()
{
square = (int a) => a * a;
int square = 5.square;
assert(square == 25);
}
```
Thanks, SDB@79
On Saturday, 9 April 2022 at 10:39:33 UTC, vit wrote:
Why doesn't this code compile?
`proxySwap1` is lying about its attributes. It says `rhs` is
`scope`, but it escapes by assignment `this.ptr = rhs.ptr;`. The
compiler doesn't raise an error because it's marked `@trusted`.
`proxySwap2
Hello,
Why doesn't this code compile?
```d
static struct Foo{
void *ptr;
void proxySwap1(scope ref typeof(this) rhs)scope pure nothrow
@trusted @nogc{
auto tmp = this.ptr;
this.ptr = rhs.ptr;
rhs.ptr = tmp;
}
void proxySwap2()(scope ref typeof
On Wednesday, 30 March 2022 at 12:46:07 UTC, Vijay Nayar wrote:
Consider the following code example:
```d
import std.stdio;
void main()
{
alias DelegateT = string delegate();
// An array of delegates, each has their own scope.
DelegateT[] funcs;
foreach (i; ["ham"
On Wednesday, 30 March 2022 at 12:56:39 UTC, Vijay Nayar wrote:
On Wednesday, 30 March 2022 at 12:53:10 UTC, vit wrote:
use two delegates :)
```d
(){
// Deliberately create a copy to keep in delegate scope.
string myStr = i.dup
On Wednesday, 30 March 2022 at 12:53:10 UTC, vit wrote:
use two delegates :)
```d
(){
// Deliberately create a copy to keep in delegate scope.
string myStr = i.dup;
// The delegate will hopefully carry this copy around in its
own scope
On Wednesday, 30 March 2022 at 12:46:07 UTC, Vijay Nayar wrote:
Consider the following code example:
```d
import std.stdio;
void main()
{
alias DelegateT = string delegate();
// An array of delegates, each has their own scope.
DelegateT[] funcs;
foreach (i; ["ham"
Consider the following code example:
```d
import std.stdio;
void main()
{
alias DelegateT = string delegate();
// An array of delegates, each has their own scope.
DelegateT[] funcs;
foreach (i; ["ham", "cheese"]) {
// Deliberately create a copy to keep in delega
On Saturday, 12 March 2022 at 13:12:25 UTC, vit wrote:
```d
enum touch_T = __traits(hasMember, T, "touch");
```
I think you meant build instead of touch?
```d
struct Query {
public const SharedPtr!Builder builder;
}
interface Builder {
void build(ref Query query);
}
struct SharedPtr(T)
`ref Query query` is scope then there is error?
```d
struct Query{
public const SharedPtr!Builder builder;
}
interface Builder{
void build(scope ref Query query); //SCOPE
}
struct SharedPtr(T){
enum touch_T = __traits(hasMember, T, "touch");
//...
}
void main(){
Yes, the `return` attribute is what should do it. You also need
to compile the code with -dip1000 option.
tly to c functions that
accept `ctype *`. But how do I either: ensure `rc` stays in scope
or have compile-time protection against escaping `ptr` past the
lifetime of `rc`. Is this possible with either `scope` or
`@live`? Could I add attributes to the C bindings to help with
this?
On Thursday, 26 August 2021 at 19:31:54 UTC, DLearner wrote:
if (typeof(v).stringof == "int" ) {
Tip: you can instead of string of do
if (is(typeof(v) == int))
That is operator lets you compare types directly.
(stringof is something you will almost never use as you learn
more of the
On Thursday, 26 August 2021 at 16:28:22 UTC, Adam D Ruppe wrote:
On Thursday, 26 August 2021 at 16:16:55 UTC, DLearner wrote:
Please confirm that mixins of format:
You really shouldn't use string mixins like this at all. If you
want to work with a variable, pass the variable itself as an
On Thursday, 26 August 2021 at 18:07:48 UTC, Ali Çehreli wrote:
In some cases it's more useful to have a 'static if' inside a
single function template instead of two separate function
templates.
In most cases that's better. A template constraint is really a
way to say "this template cannot
On 8/26/21 10:45 AM, Adam D Ruppe wrote:
On Thursday, 26 August 2021 at 17:39:16 UTC, Ali Çehreli wrote:
String mixins are appealing because they can inject code like C macros
do. It's not trivially possible to do the same with template mixins.
Template mixins are great, but obviously totally
On Thursday, 26 August 2021 at 17:39:16 UTC, Ali Çehreli wrote:
String mixins are appealing because they can inject code like C
macros do. It's not trivially possible to do the same with
template mixins.
Template mixins are great, but obviously totally inappropriate
here. I'm just talking
On 8/26/21 10:06 AM, Adam D Ruppe wrote:
On Thursday, 26 August 2021 at 17:01:06 UTC, DLearner wrote:
The object was to take a variable, and do alternative things with it
depending on (say) whether it was an 'int' or an 'int*'.
That's *very* easy to do with the alias. You can just check
On Thursday, 26 August 2021 at 17:01:06 UTC, DLearner wrote:
The object was to take a variable, and do alternative things
with it depending on (say) whether it was an 'int' or an 'int*'.
That's *very* easy to do with the alias. You can just check
`typeof(v)` in there.
On Thursday, 26 August 2021 at 16:28:22 UTC, Adam D Ruppe wrote:
On Thursday, 26 August 2021 at 16:16:55 UTC, DLearner wrote:
Please confirm that mixins of format:
You really shouldn't use string mixins like this at all. If you
want to work with a variable, pass the variable itself as an
On Thursday, 26 August 2021 at 16:16:55 UTC, DLearner wrote:
Please confirm that mixins of format:
You really shouldn't use string mixins like this at all. If you
want to work with a variable, pass the variable itself as an
argument to the function and use it with regular code instead of
On Thursday, 26 August 2021 at 16:16:55 UTC, DLearner wrote:
Please confirm that mixins of format:
```
string mxn1(string VarName) {
...
}
```
Invoked like:
```
mixin(mxn1("Var1"));
```
Have a wider scope than mixins like:
```
string mxn2(string VarName)() {
...
}
```
In
Please confirm that mixins of format:
```
string mxn1(string VarName) {
...
}
```
Invoked like:
```
mixin(mxn1("Var1"));
```
Have a wider scope than mixins like:
```
string mxn2(string VarName)() {
...
}
```
Invoked like:
```
mixin(mxn2!"Var2");
```
I tried direct r
On Wednesday, 25 August 2021 at 15:30:57 UTC, Steven
Schveighoffer wrote:
[...]
Another approach is to let the compiler deal with the error
handling and not muddy your return type. Swift does something
similar, where it rewrites the throw/catch into a standard
return and doesn't do actual
On 8/25/21 10:58 AM, WebFreak001 wrote:
Hm I'm not quite seeing how the error handler is related to an "Expected
type interface" that the compiler could expect.
This would be without compiler changes.
Currently with exceptions the scope things are implemented using
try-cat
On Wednesday, 25 August 2021 at 14:42:07 UTC, Steven
Schveighoffer wrote:
I think it's possible to work with some mechanics that aren't
necessarily desirable. Something like:
```d
ErrorHandler error = registerErrorHandler;
error.onFailure({writeln("division failed");});
On Wednesday, 25 August 2021 at 14:52:34 UTC, Steven
Schveighoffer wrote:
On 8/25/21 10:42 AM, Steven Schveighoffer wrote:
I think it's possible to work with some mechanics that aren't
necessarily desirable. Something like:
One has to weigh how much this is preferred to actual exception
d be messy and
likely brittle.
Hm I'm not quite seeing how the error handler is related to an
"Expected type interface" that the compiler could expect.
Currently with exceptions the scope things are implemented using
try-catch-finally, this would be even simpler:
```d
scope(ex
On 8/25/21 10:42 AM, Steven Schveighoffer wrote:
I think it's possible to work with some mechanics that aren't
necessarily desirable. Something like:
One has to weigh how much this is preferred to actual exception handling...
If something like DIP1008 could become usable, it might
On 8/25/21 10:22 AM, Paul Backus wrote:
On Wednesday, 25 August 2021 at 14:04:54 UTC, WebFreak001 wrote:
Would it be possible to extend `scope(exit)` and `scope(success)` to
trigger properly for functions returning `Expected!T` as defined in
the [expectations](https://code.dlang.org/packages
On Wednesday, 25 August 2021 at 14:22:26 UTC, Paul Backus wrote:
On Wednesday, 25 August 2021 at 14:04:54 UTC, WebFreak001 wrote:
[...]
Probably the only principled way to make this work would be to
define some kind of "concept"/structural interface that's
recognized by the compiler to mean
On Wednesday, 25 August 2021 at 14:04:54 UTC, WebFreak001 wrote:
Would it be possible to extend `scope(exit)` and
`scope(success)` to trigger properly for functions returning
`Expected!T` as defined in the
[expectations](https://code.dlang.org/packages/expectations)
and [expected](https
Would it be possible to extend `scope(exit)` and `scope(success)`
to trigger properly for functions returning `Expected!T` as
defined in the
[expectations](https://code.dlang.org/packages/expectations) and
[expected](https://code.dlang.org/packages/expected) DUB
libraries?
For example
On Saturday, 14 August 2021 at 08:23:20 UTC, user1234 wrote:
On Saturday, 14 August 2021 at 04:09:34 UTC, Tejas wrote:
[...]
Oh right, the ```.``` operator will reference variable in the
_module_ scope, not just the _immediate outer scope_,
you can use the module name to disambiguate as well
On Saturday, 14 August 2021 at 04:09:34 UTC, Tejas wrote:
[...]
Oh right, the ```.``` operator will reference variable in the
_module_ scope, not just the _immediate outer scope_,
you can use the module name to disambiguate as well. To extend
Mike answer, the general rule is that if you can
()
{
writeln(macro_1(15, 20));
alias macro_1 = def;// is this NOT considered variable
shadowing?
writeln(macro_1(100, 20));
}
```
Shadowing local symbols is illegal. But it's okay for local
symbols to have the same name as module-scope symbols. You can
disambigbuate with [the module
;// is this NOT considered variable
shadowing?
writeln(macro_1(100, 20));
}
```
Shadowing local symbols is illegal. But it's okay for local
symbols to have the same name as module-scope symbols. You can
disambigbuate with [the module scope operator][1]:
```d
void main()
macro_1
```d
import std;
auto abc(T)(auto ref T a, auto ref T b){
return a+b;
}
auto def(T)(auto ref T a, auto ref T b){
return a*b;
}
alias macro_1 = abc;
void main()
{
writeln(macro_1(15, 20));
alias macro_1 = def;// is this NOT considered variable
shadowing?
On Sunday, 11 July 2021 at 13:21:35 UTC, DLearner wrote:
Is there a 'D' way of avoiding the issue?
Pass the size as a parameter to the thing instead of trying to
combine things. like
mixin template Thing(size_t size) {
ubyte[size] pool;
}
and where you want it like
mixin
On Sunday, 11 July 2021 at 12:47:48 UTC, Adam D Ruppe wrote:
On Sunday, 11 July 2021 at 12:37:20 UTC, DLearner wrote:
C:\Users\SoftDev\Documents\BDM\D\Examples\CTFE\T2>type k_mod.d
// k_mod.d
ubyte[MemSiz] MemPool;
You didn't import the other module here.
D's imports aren't like C's
On Sunday, 11 July 2021 at 12:37:20 UTC, DLearner wrote:
C:\Users\SoftDev\Documents\BDM\D\Examples\CTFE\T2>type k_mod.d
// k_mod.d
ubyte[MemSiz] MemPool;
You didn't import the other module here.
D's imports aren't like C's includes. Each module is independent
and can only see what it
On Sunday, 11 July 2021 at 12:01:27 UTC, jfondren wrote:
On Sunday, 11 July 2021 at 10:58:58 UTC, DLearner wrote:
Is there a way of forcing DMD to extend the scope of `MemSiz`
to include `k_mod`?
Best regards
```
$ cat k_mod.d
import test01;
ubyte[MemSiz] MemPool;
$ cat test01.d
enum
On Sunday, 11 July 2021 at 10:58:58 UTC, DLearner wrote:
Is there a way of forcing DMD to extend the scope of `MemSiz`
to include `k_mod`?
Best regards
```
$ cat k_mod.d
import test01;
ubyte[MemSiz] MemPool;
$ cat test01.d
enum MemSiz = 240;
void main() {
import std.stdio, k_mod
has the enum `MemSiz`, but set to different values.
However, DMD does not recognise the enum `MemSiz` within `k_mod`,
failing with 'undefined identifier'.
Is there a way of forcing DMD to extend the scope of `MemSiz` to
include `k_mod`?
Best regards
On Sunday, 4 July 2021 at 10:07:08 UTC, jfondren wrote:
Not cleaning up after an Error is thrown is allowed by the D
spec. This enhancement allows much better code to be generated
for `nothrow` code when `scope` is used. It will also not
unwind declarations with destructors in `nothrow` code
) RangeError to exit without properly unwinding the
stack.
By that, what you're running into is an unpleasant interaction
between
1. scope(exit)s that you're writing
2. Errors being thrown rather than Exceptions
3. anonymous functions getting inferred as nothrow
I did https://issues.dlang.org
On Sunday, 4 July 2021 at 10:07:08 UTC, jfondren wrote:
By that, what you're running into is an unpleasant interaction
between
1. scope(exit)s that you're writing
2. Errors being thrown rather than Exceptions
3. anonymous functions getting inferred as nothrow
And a resolution could
you're running into is an unpleasant interaction
between
1. scope(exit)s that you're writing
2. Errors being thrown rather than Exceptions
3. anonymous functions getting inferred as nothrow
And a resolution could be to submit an issue to make #1 prevent
#3: if someone wants nothrow on an anonoymous
On Saturday, 3 July 2021 at 22:52:39 UTC, frame wrote:
On Saturday, 3 July 2021 at 22:04:04 UTC, Luis wrote:
scope(exit) it's syntactic sugar for a classic `try {} finally
{}` . The documentation says that must be executed.
It works if you replace printf() with writeln() or use
writeln
On Saturday, 3 July 2021 at 22:04:04 UTC, Luis wrote:
scope(exit) it's syntactic sugar for a classic `try {} finally
{}` . The documentation says that must be executed.
It works if you replace printf() with writeln() or use writeln()
after. There must be some buffer issue.
or handler is
found, execution resumes there. If not, the default Error
handler is run, which displays
the message and terminates the program.
scope(exit) it's syntactic sugar for a classic `try {} finally
{}` . The documentation says that must be executed.
On Saturday, 3 July 2021 at 17:47:47 UTC, Dennis wrote:
On Saturday, 3 July 2021 at 17:20:47 UTC, Luis wrote:
scope(exit) inside of a anonymous functions, it's never called.
I think the compiler infers the function `nothrow` since you
don't throw any `Exception`, only an `Error`. Errors
On 7/3/21 4:08 PM, frame wrote:
On Saturday, 3 July 2021 at 17:39:18 UTC, Steven Schveighoffer wrote:
But in practice, the compiler does not have to clean up anything when
an `Error` is thrown. Whether it does or not is defined by the
implementation.
This should be really mentionend in the
On Saturday, 3 July 2021 at 17:39:18 UTC, Steven Schveighoffer
wrote:
But in practice, the compiler does not have to clean up
anything when an `Error` is thrown. Whether it does or not is
defined by the implementation.
This should be really mentionend in the docs? "Guard", yeah...
On Saturday, 3 July 2021 at 17:20:47 UTC, Luis wrote:
scope(exit) inside of a anonymous functions, it's never called.
I think the compiler infers the function `nothrow` since you
don't throw any `Exception`, only an `Error`. Errors represent
unrecoverable bugs, after which the program
On Saturday, 3 July 2021 at 17:20:47 UTC, Luis wrote:
This is intentional ?
...
scope(exit) inside of a anonymous functions, it's never called.
```
$ rdmd --eval 'iota(2).map!((int x) { scope(exit) writeln("got:
", x); return x+1; }).array.writeln'
got: 0
got: 1
[1, 2]
```
On 7/3/21 1:20 PM, Luis wrote:
This is intentional ?
```
should(function void() {
auto emptyStack = SimpleStack!int();
scope(exit) emptyStack.free; // <= This is never called
emptyStack.reserve(16);
emptyStack.top;
}).Th
On Saturday, 3 July 2021 at 17:20:47 UTC, Luis wrote:
This is intentional ?
```
should(function void() {
auto emptyStack = SimpleStack!int();
scope(exit) emptyStack.free; // <= This is never
called
emptyStack.reserve(16);
emptyStack.
This is intentional ?
```
should(function void() {
auto emptyStack = SimpleStack!int();
scope(exit) emptyStack.free; // <= This is never
called
emptyStack.reserve(16);
emptyStack.top;
}).Throw!RangeError;
```
scope(exit) ins
On 13.06.21 19:49, vit wrote:
Is possible create and use scope output range allocated on stack in
@safe code?
Example:
```d
//-dip1000
struct OutputRange{
private bool valid = true;
private void* ptr;
int count = 0;
void put(Val)(auto ref scope Val
On Sunday, 13 June 2021 at 17:49:50 UTC, vit wrote:
Is possible create and use scope output range allocated on
stack in @safe code?
Example:
```d
//-dip1000
struct OutputRange{
private bool valid = true;
private void* ptr;
int count = 0;
void put(Val
1 - 100 of 669 matches
Mail list logo