Re: stdin.readln line editing and recall with up arrow

2023-02-24 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn

On 25/02/2023 6:36 PM, Daren Scot Wilson wrote:
stdin.readln() works fine until I, out of habit, use the up arrow to 
recall an earlier input and the left/right to move around and change a 
character.   How do I get that to work?


Not with that module.

You can either use GNU readline itself, or Adam's version within arsd.


stdin.readln line editing and recall with up arrow

2023-02-24 Thread Daren Scot Wilson via Digitalmars-d-learn
stdin.readln() works fine until I, out of habit, use the up arrow 
to recall an earlier input and the left/right to move around and 
change a character.   How do I get that to work?


Re: Template alias parameter: error: need 'this' for ...

2023-02-24 Thread Elfstone via Digitalmars-d-learn
On Friday, 24 February 2023 at 15:28:18 UTC, Steven Schveighoffer 
wrote:

On 2/24/23 7:00 AM, Elfstone wrote:


Seems like the same bug is still there after ten years.



`static` should not affect module-level functions, but also, 
this code should work without `static`.


Reported, not sure if there's a previous bug, it was hard to 
come up with a good description:


https://issues.dlang.org/show_bug.cgi?id=23738

-Steve


It was marked duplicate. I read the comments to the previous 
issue and felt like reading C++ discussions, except C++ is a lot 
better documented.


Anyway surely `__traits(getAttributes, Bar.t)` compiles. The 
compiler should "need 'this'" when it actually need 'this' - 
unless there are attributes that can be bound to 'this'.




Re: dub.selections.json & optional dependencies: How's it work?

2023-02-24 Thread jmh530 via Digitalmars-d-learn
On Friday, 24 February 2023 at 19:37:41 UTC, Steven Schveighoffer 
wrote:

On 2/24/23 2:01 PM, jmh530 wrote:
I'm looking at the dub package format [1] about optional 
dependencies and it says:


"With this set to true, the dependency will only be used if 
explicitly selected in dub.selections.json. If omitted, this 
attribute defaults to false."


And it occurs to me that I don't know anything about how 
dub.selections.json works.


Let's say you have dependency A, which has an *optional* 
dependency on B.


In your project, if you depend on A, but don't explicitly 
depend on B, then A will be built without B as a dependency.


If you have a dependency on A *and* B, then B's optional 
dependency will kick in, and participate in the selection of 
it's version.


So for instance, you could depend on B version 1 or higher, and 
the optional dependency could be on v1.5 or higher, it will 
select the highest version of 1.5


dub.selections.json only applies to the primary project. So the 
decision on which versions of which dependencies to use is 
decided by the whole tree.


-Steve


Ok this makes sense. So it's all about dependencies downstream. 
For instance, if I list B as a dependency in my project but never 
use it in my own project, it will still compile in (so for 
instance if A's functionality differs depending on if B is 
included, then I will get that functionality even if I don't use 
B directly in my project).


Re: dub.selections.json & optional dependencies: How's it work?

2023-02-24 Thread Steven Schveighoffer via Digitalmars-d-learn

On 2/24/23 2:01 PM, jmh530 wrote:
I'm looking at the dub package format [1] about optional dependencies 
and it says:


"With this set to true, the dependency will only be used if explicitly 
selected in dub.selections.json. If omitted, this attribute defaults to 
false."


And it occurs to me that I don't know anything about how 
dub.selections.json works.


Let's say you have dependency A, which has an *optional* dependency on B.

In your project, if you depend on A, but don't explicitly depend on B, 
then A will be built without B as a dependency.


If you have a dependency on A *and* B, then B's optional dependency will 
kick in, and participate in the selection of it's version.


So for instance, you could depend on B version 1 or higher, and the 
optional dependency could be on v1.5 or higher, it will select the 
highest version of 1.5


dub.selections.json only applies to the primary project. So the decision 
on which versions of which dependencies to use is decided by the whole tree.


-Steve


dub.selections.json & optional dependencies: How's it work?

2023-02-24 Thread jmh530 via Digitalmars-d-learn
I'm looking at the dub package format [1] about optional 
dependencies and it says:


"With this set to true, the dependency will only be used if 
explicitly selected in dub.selections.json. If omitted, this 
attribute defaults to false."


And it occurs to me that I don't know anything about how 
dub.selections.json works.


I would think dub optional dependencies work such that if there 
are no functions being called/compiled that import an optional 
dependency, then the dependency wouldn't be included. How is it 
different from `dmd -i`?


The dub.selections.json in some of my projects look like a 
listing of the dependencies and their versions. Above should 
imply that the optional dependency would only get included there 
if the import is actually used somewhere in the project. Is that 
correct?


[1] https://dub.pm/package-format-json.html


Re: Template alias parameter: error: need 'this' for ...

2023-02-24 Thread Paul Backus via Digitalmars-d-learn

On Friday, 24 February 2023 at 14:22:17 UTC, user1234 wrote:
you can break using `goto`, restore `static` everywhere, and 
using local introspection determine whether the result exists.


```d
struct Bar
{
@("hello") int t;
}

static bool hasAttribute(alias F, T)()
{
static foreach (a; __traits(getAttributes, F))
{
static if (is(typeof(a) : T))
{
enum result = true;
goto L0;
}
}
L0:
static if (is(typeof(result)))
return result;
else
return false;
}

void main()
{
import std.stdio;

writeln(hasAttribute!(Bar.t, string));
}
```


Unfortunately there is a serious bug in this code. Take a look at 
what happens when you try it with this `struct Bar`:


```d
struct Bar
{
@("hello") @("goodbye") int t;
}
```


Re: Template alias parameter: error: need 'this' for ...

2023-02-24 Thread Steven Schveighoffer via Digitalmars-d-learn

On 2/24/23 7:00 AM, Elfstone wrote:


Seems like the same bug is still there after ten years.



`static` should not affect module-level functions, but also, this code 
should work without `static`.


Reported, not sure if there's a previous bug, it was hard to come up 
with a good description:


https://issues.dlang.org/show_bug.cgi?id=23738

-Steve


Re: Template alias parameter: error: need 'this' for ...

2023-02-24 Thread user1234 via Digitalmars-d-learn

On Friday, 24 February 2023 at 12:00:41 UTC, Elfstone wrote:

Seems like the same bug is still there after ten years.

```d
struct Bar
{
@("hello") int t;
}

static bool hasAttribute(alias F, T)()
{
bool result = false;
foreach (a; __traits(getAttributes, F))
{
static if (is(typeof(a) : T))
{
result = true; // couldn't simply return true, 'cause the 
compiler complains about "unreachable code".

}
}
return result;
}

void main()
{
import std.stdio;

writeln(hasAttribute!(Bar.t, string));
}
```


you can break using `goto`, restore `static` everywhere, and 
using local introspection determine whether the result exists.


```d
struct Bar
{
@("hello") int t;
}

static bool hasAttribute(alias F, T)()
{
static foreach (a; __traits(getAttributes, F))
{
static if (is(typeof(a) : T))
{
enum result = true;
goto L0;
}
}
L0:
static if (is(typeof(result)))
return result;
else
return false;
}

void main()
{
import std.stdio;

writeln(hasAttribute!(Bar.t, string));
}
```


Template alias parameter: error: need 'this' for ...

2023-02-24 Thread Elfstone via Digitalmars-d-learn

https://forum.dlang.org/post/imnannjdgtjnlzevh...@forum.dlang.org

On Saturday, 24 August 2013 at 11:47:43 UTC, Matej Nanut wrote:
On Friday, 23 August 2013 at 22:54:33 UTC, Jonathan M Davis 
wrote:
Because without static it's a member variable, which means 
that you have to
have a constructed object to access it (since it's part of the 
object). When
you declare a variable in a class or struct static, then 
there's only one for
the entire class or struct, so it can be accessed without an 
object. And when
you do StructName.var or ClassName.var your accessing the 
variable via the
struct or class rather than an object, so the variable must be 
static.


- Jonathan M Davis


But I declared the template static, not the variable.

Is there a better way to pass a ‘member get’ expression to a 
template?


I need this for calling ‘.offsetof’ on it, and for checking if 
the member's parent is a certain struct type.


Seems like the same bug is still there after ten years.


struct Bar
{
@("hello") int t;
}

static bool hasAttribute(alias F, T)()
{
bool result = false;
foreach (a; __traits(getAttributes, F))
{
static if (is(typeof(a) : T))
{
result = true; // couldn't simply return true, 'cause the 
compiler complains about "unreachable code".

}
}
return result;
}

void main()
{
import std.stdio;

writeln(hasAttribute!(Bar.t, string));
}


Re: dub creates unrunnable binary in "build" dir

2023-02-24 Thread tastyminerals--- via Digitalmars-d-learn
On Thursday, 23 February 2023 at 12:28:35 UTC, Richard (Rikki) 
Andrew Cattermole wrote:

On 24/02/2023 1:10 AM, tastyminer...@gmail.com wrote:

The symbol exists if I understood correctly.


-imports shows you the imports of the binary, not the exports. 
So no it does not exist (probably came from libc).


https://keith.github.io/xcode-man-pages/dyld_info.1.html

My guess is something changed some place else. Such as XCode or 
tcl.


Yes, you're correct. I managed to resolve it.
So "_memcmp" was missing and it is part of the libc library. I 
remember that MacPorts asked me to reclaim some space by removing 
the deps of inactive ports. When agreed, it removed almost 
complete port library including many libs used for compilation of 
other ports. I managed to restore most of them but looks like 
glibc2 was still missing. After installing it and libgcc with 
deps, the project compiled without issues.