Re: Variadic function template with one inferred template argument

2020-11-07 Thread starcanopy via Digitalmars-d-learn

On Saturday, 7 November 2020 at 20:43:04 UTC, Ben Jones wrote:
I'm trying to write a function template with 1 parameter whose 
type is inferred, but with the other parameters variadic.


Basically, I want to do this:

auto f(Ts..., Inferred)(Inferred inf){}

and call it with f!(X,Y,Z)(w) //inferred will be typeof(w), 
Ts... == (X, Y, Z)


which I can't do because the variadic template args have to 
come last.


Is there a way to change f so that the caller can use it like I 
want?  I tried this approach which didn't work.


template f(Ts...){
  auto f(Inferred)(Inferred inf){}
}

I don't see a way to specify a variadic set of template args 
but have one inferred.  I could wrap the variadic args in 
another template so f just takes 2 params, but I'd like to 
avoid that because it makes the calling code more complicated.


template f(Ts...) {
auto f(Inferred)(Inferred inf) {
pragma(msg, Ts);
import std.stdio : writeln;
inf.writeln;
}
}

void main() {
f!(int, float, char)("Hello, world!");
}

https://run.dlang.io/is/e8FGrF


Re: How to rebind the default tkd GUI keybinds?

2020-10-17 Thread starcanopy via Digitalmars-d-learn

On Saturday, 17 October 2020 at 09:33:04 UTC, tastyminerals wrote:

On Sunday, 11 October 2020 at 18:51:17 UTC, tastyminerals wrote:
Tk default keys are somewhat different from what we used to 
use for selecting, copying and pasting the text. So, any Tk 
based GUI app starts with writing the rebinding function for 
"ctrl+a", "ctrl+c", "ctrl+x" and "ctrl+v" keys, at least. I 
did it when writing TkInter based apps in Python. Today I am 
trying out tkd and want to do the same. However, it doesn't 
work :(


For example:

private void selectText(CommandArgs args) {
this._clientId.selectText;
}

this._loginFrame = new Frame(2, ReliefStyle.groove);
this._clientId = new Entry(loginFrame).grid(1, 0);
this._clientId.bind("", );

It works if I change "" to "" for 
example.

But how do I overwrite the actual "" key in tkd?


So, this is even tricky in Python TkInter but possible.
In tkd this is not possible unfortunately.


You could try directly calling 
[bindtags](https://www.tcl.tk/man/tcl8.4/TkCmd/bindtags.htm) with 
_tk.eval. Modifying and extending tkd is easy from my experience 
where I had added support for additional image formats. (After 
blundering about on how to get tcl/tk to work, lol.)


Re: Win32api: How to send a Struct in DialogBox?

2020-10-13 Thread starcanopy via Digitalmars-d-learn

On Wednesday, 14 October 2020 at 00:07:10 UTC, Marcone wrote:

Solved:

Teste * params = cast(Teste*) lParam;

writeln(params.nome);
writeln(params.idade);


But here, how can send struct?

DialogBoxParam(null, MAKEINTRESOURCE(IDD_DIALOG1), null, 
, cast(int) ); // Error, need "int" but I am 
sending Test*


Sorry, I was going to create an example for you, but something 
came up. Thankfully, it looks like you've solved it in your own 
way (You might want to cast  to LPARAM instead of int.), but 
if you have any more D/WinApi questions, you might want to check 
here: https://github.com/AndrejMitrovic/DWinProgramming.


Re: Win32api: How to send a Struct in DialogBox?

2020-10-13 Thread starcanopy via Digitalmars-d-learn

On Tuesday, 13 October 2020 at 22:26:35 UTC, Marcone wrote:

struct Teste {
string nome = "Paul";
int idade = 33;
}

extern(Windows):
BOOL DlgMain(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM 
lParam) nothrow

{
// I want to be able to use the struct object here.
// writeln(test.nome);
return false;
}

void chamaJanela(){
Test test; // How to send this object to the DlgMain 
function?
DialogBox(null, MAKEINTRESOURCE(IDD_DIALOG1), null, 
);

}


Instead of calling DialogBox, you might try DialogBoxParam[A|W].

Before displaying the dialog box, the function passes an 
application-defined
value to the dialog box procedure as the lParam parameter of the 
WM_INITDIALOG
message. An application can use this value to initialize dialog 
box controls.


- 
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-dialogboxparamw





Phobos Unittesting

2020-10-12 Thread starcanopy via Digitalmars-d-learn
I'm working on adding support for Windows' symlinks in std.file. 
std.file.symlink's augmentation is straightforward, but testing 
it is not as easy. The reason is because, normally, one must 
confer escalated privileges to the executable making the link via 
CreateSymbolicLink[A|W]. This may be obviated, in Windows 10 at 
least, by enabling "Developer mode" and passing a flag to the 
aforementioned function.


Thus, consider what I have right now:

auto flags = /* Default flags */;
version (StdUnittest)
{
flags |= SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE;
}

By doing this, running tests shouldn't require administrator's 
rights, assuming "Developer mode" is enabled. However, are the 
Windows CI machines set up for this? Should there be a special 
case at all?


The final concern relates to Phobos defining system_directory and 
system_file for Posix and Android. These two constants are used 
in testing some of std.file's functionality. For Windows, a 
testing directory could be %temp% and the testing file could be 
created in that directory. If my changes were approved, the file 
would only have to be created twice throughout std.file's tests. 
However, I'd like to know some alternatives and potential issues 
to/with this!


Re: Why is BOM required to use unicode in tokens?

2020-09-15 Thread starcanopy via Digitalmars-d-learn
On Tuesday, 15 September 2020 at 21:27:25 UTC, Ola Fosheim 
Grøstad wrote:
On Tuesday, 15 September 2020 at 01:49:13 UTC, James Blachly 
wrote:

I wish to write a function including ∂x and ∂y (these are


You can use the greek letter delta instead:

δ


Wouldn't that imply a normal differential?


Re: Initialize to None

2020-09-05 Thread starcanopy via Digitalmars-d-learn

On Sunday, 6 September 2020 at 03:42:36 UTC, N.S. wrote:
I'd like to check whether a variable is initialized or not. And 
I'd also like to uninitialize a variable that is already 
initialized. Thanks!


int x = void;

if (x == void)
{
writeln("x not initialized");
}
else
{
// OK, use x
}

// Uninitialize x
x = void;


You might consider Nullable from std.typecons; however, if you're 
avoiding implicit initialization for performance reasons, then 
this solution might not be applicable.


import std.stdio: writeln;
import std.typecons: Nullable;

Nullable!int x;

if (x.isNull)
{
writeln("x not 'initialized'");
}
else
{
// OK, use x
}

// 'Uninitialize' x
x.nullify();


Re: D binary io functions

2020-08-30 Thread starcanopy via Digitalmars-d-learn

On Sunday, 30 August 2020 at 06:00:20 UTC, Andy Balba wrote:
going nuts trying to figure out which D functions will 
read/write binary files


For starters:
https://dlang.org/phobos/std_stdio.html#.File.byChunk
https://dlang.org/phobos/std_stdio.html#.File.rawRead
https://dlang.org/phobos/std_stdio.html#.File.rawWrite
https://dlang.org/phobos/std_stdio.html#.File.lockingBinaryWriter
https://dlang.org/phobos/std_file.html#read
https://dlang.org/phobos/std_file.html#write
https://dlang.org/phobos/std_file.html#append


Rounding Functions in Phobos

2020-08-02 Thread starcanopy via Digitalmars-d-learn
Is there a reason why ceil, floor, round, and friends return 
floats instead of an integer? There are l' variants for some of 
these, but I'd imagine template implementations of these 
operations would be better. Too much bloat?


Naively, you'd have for ceil...

// Return type would be numeric but the concrete type will be 
whatever is smallest to fit the result.

auto ceil(Float)(Float x) if (isFloatingPoint!Float) { ... }

or...

Integer ceil(Float, Integer = long)(Float x)
if (isFloatingPoint!Float && isIntegral!Integer)
{ ... }

For reals that are too big for long, I'd guess (u)cent would need 
an implementation.