Re: javascript or typescript

2018-11-04 Thread Adam D. Ruppe via Digitalmars-d-learn

On Monday, 5 November 2018 at 02:51:19 UTC, Fred wrote:

i'd like to give d a try.


Why do you need to convert it to javascript? D can serve up web 
stuff by itself too.


Re: Putting dmd error through grep for dustmite

2018-11-04 Thread Vladimir Panteleev via Digitalmars-d-learn

On Monday, 5 November 2018 at 03:01:43 UTC, Dennis wrote:
Does anybody know what the problem is? I'm using Windows 10 and 
Git Bash.


Sounds like the problem comes from the differences in shell 
syntax (quoting style) for the two shells here. When you run the 
command in Git Bash, the syntax used is Bash's. However, Dustmite 
will call shellExecute, which will pass the command to cmd.exe.


cmd.exe will interpret \` verbatim (i.e. as \`), so, try not 
quoting the ` characters (or just replace them with . if you want 
the command to work in both shells).




Putting dmd error through grep for dustmite

2018-11-04 Thread Dennis via Digitalmars-d-learn
I am debugging a case where operator overloading seems to break 
when I define the opBinary templates in a mixin template. On my 
own simple test-case it worked fine, so I'm trying to reduce my 
current code with dustmite.


The file tree is simply:

myproject/
  q16.d

And the command I run is:
```
$ dustmite myproject 'dmd -color=off -unittest q16.d 2>&1 | grep 
"Error: template \`util.q16.Q16_16.opBinary\` does not match any 
template declaration"' --no-redirect

```

It complains that the 'Initial test fails'. However, when I 'cd 
myproject' and run the command myself I get:

```
q16.d(167): Error: template `util.q16.Q16_16.opBinary` does not 
match any template declaration


$ echo $?
0
```

So for me it works. When I reduce the grep string to 
"util.q16.Q16_16.opBinary" it works on dustmite too, but it 
reduces too much since that condition is not precise enough. It 
seems that the backticks of `util.q16.Q16_16.opBinary` are the 
problem. I noticed that the back-ticks aren't there when the 
output is colorised, but adding -color=off didn't seem to make a 
difference. Removing them from the search or double-escaping them 
(like \\\`) also don't work.


Does anybody know what the problem is? I'm using Windows 10 and 
Git Bash.


javascript or typescript

2018-11-04 Thread Fred via Digitalmars-d-learn

hi,
my javascript skill is bad.
but i want to host some nodejs app

i am aware that there is converter to js like dtojs. but it is 
out of date.


i'd like to give d a try. is there any other converter available. 
a decent one.


Re: Accessing LPARAM param from SendMessage acts weird.

2018-11-04 Thread John Chapman via Digitalmars-d-learn

On Sunday, 4 November 2018 at 19:06:22 UTC, Mark Moorhen wrote:

Another Windows challenge:

I'm trying to get the title of the active window even if it is 
from an external application. This is what I've come up with so 
far:



import std.stdio;
import core.sys.windows.windows;

extern (Windows)

void main()
{
HWND foreground = GetForegroundWindow();
const(wchar) title;

int length = SendMessage(foreground, WM_GETTEXTLENGTH, 0, 0);
	SendMessage(foreground, WM_GETTEXT, length, 
LPARAM(title));			//LPARAM is a Long Pointer


writeln(length);
writeln(title);

}


Outputs :

27
  ´┐┐

So the lengt of the foreground windows title should be 27 chars 
long, but the title is only 3 chars (and kinda funny ones too:-(


Anyone ideas?


You need to allocate some memory to receive the string from 
WM_GETTEXT.


  auto length = SendMessage(foreground, WM_GETTEXTLENGTH, 0, 0);
  auto buffer = new wchar[length + 1]; // +1 for the trailing 
null character
  SendMessage(foreground, WM_GETTEXT, buffer.length, 
cast(LPARAM)buffer.ptr);

  auto title = cast(wstring)buffer[0 .. length];
  writeln(title);


Re: d word counting approach performs well but has higher mem usage

2018-11-04 Thread Jon Degenhardt via Digitalmars-d-learn

On Saturday, 3 November 2018 at 14:26:02 UTC, dwdv wrote:

Hi there,

the task is simple: count word occurrences from stdin (around 
150mb in this case) and print sorted results to stdout in a 
somewhat idiomatic fashion.


Now, d is quite elegant while maintaining high performance 
compared to both c and c++, but I, as a complete beginner, 
can't identify where the 10x memory usage (~300mb, see results 
below) is coming from.


Unicode overhead? Internal buffer? Is something slurping the 
whole file? Assoc array allocations? Couldn't find huge allocs 
with dmd -vgc and -profile=gc either. What did I do wrong?


Not exactly the same problem, but there is relevant discussion in 
the blog post I wrote a while ago:  
https://dlang.org/blog/2017/05/24/faster-command-line-tools-in-d/


See in particular the section on Associate Array lookup 
optimization. This takes advantage of the fact that it's only 
necessary to create the immutable string the first time a key is 
entered into the hash. Subsequent occurrences do not need to take 
this step. As creating allocates new memory, even if only used 
temporarily, this is a meaningful savings.


There have been additional APIs added to the AA interface since I 
wrote the blog post, I believe it is now possible to accomplish 
the same thing with more succinct code.


Other optimization possibilities:
* Avoid auto-decode: Not sure if your code is hitting this, but 
if so it's a significant performance hit. Unfortunately, it's not 
always obvious when this is happening. The task your are 
performing doesn't need auto-decode because it is splitting on 
single-byte utf-8 char boundaries (newline and space).


* LTO on druntime/phobos: This is easy and will have a material 
speedup. Simply add

'-defaultlib=phobos2-ldc-lto,druntime-ldc-lto'
to the 'ldc2' build line, after the '-flto=full' entry. This will 
be a win because it will enable a number of optimizations in the 
internal loop.


* Reading the whole file vs line by line - 'byLine' is really 
fast. It's also nice and general, as it allows reading arbitrary 
size files or standard input without changes to the code. 
However, it's not as fast as reading the file in a single shot.


* std.algorithm.joiner - Has improved dramatically, but is still 
slower than a foreach loop. See: 
https://github.com/dlang/phobos/pull/6492


--Jon




Accessing LPARAM param from SendMessage acts weird.

2018-11-04 Thread Mark Moorhen via Digitalmars-d-learn

Another Windows challenge:

I'm trying to get the title of the active window even if it is 
from an external application. This is what I've come up with so 
far:



import std.stdio;
import core.sys.windows.windows;

extern (Windows)

void main()
{
HWND foreground = GetForegroundWindow();
const(wchar) title;

int length = SendMessage(foreground, WM_GETTEXTLENGTH, 0, 0);
	SendMessage(foreground, WM_GETTEXT, length, 
LPARAM(title));			//LPARAM is a Long Pointer


writeln(length);
writeln(title);

}


Outputs :

27
  ´┐┐


So the lengt of the foreground windows title should be 27 chars 
long, but the title is only 3 chars (and kinda funny ones too:-(


Anyone ideas?



Re: d word counting approach performs well but has higher mem usage

2018-11-04 Thread dwdv via Digitalmars-d-learn

Assoc array allocations?


Yup. AAs do keep their memory around (supposedly for reuse). [...] 
Why it consumes so much is a question to the implementation.

[...] I guess built-in AAs just love to hoard.


What a darn shame. This way I'm missing out on all those slick internet 
benchmark points. :)


Guess I have to find a workaround then, since it's swapping memory like 
crazy on larger real-world inputs on my fairly low-end machine.



What did I do wrong?


Well, you didn't actually put the keys into the AA ;) I'm guessing you 
didn't look closely at the output, otherwise you would've noticed that 
something was wrong.

[...]
```
Error: associative arrays can only be assigned values with immutable 
keys, not char[]

```
[...]
But when you iterate later, pretty much every key is in fact a reference 
to some older memory, which is still somewhere on the GC heap; you don't 
get a segfault, but neither do you get correct "words".




You are absolutely right, I dismissed the aforementioned error without a 
second thought as soon as the compiler stopped complaining by throwing a 
const declaration at it. Oh well, should have read the assoc array spec 
page more thoroughly since it contains this very snippet here:


```
auto word = line[wordStart .. wordEnd];
++dictionary[word.idup];   // increment count for word
```

And yes, using more irregular log files as input instead of the 
concatenated uniform dict reveals quite a bit of nonsense that is being 
printed to stdout.


Thank you, Stanislav, for taking the time to explain all this.


Re: Overriding behaviour of `is` for small-sized-optimized strings

2018-11-04 Thread Per Nordlöw via Digitalmars-d-learn

On Sunday, 4 November 2018 at 13:19:45 UTC, Jacob Carlborg wrote:
You cannot overload the the "is" operator. Use "==" if you want 
to overload it.


Ok, thanks.


Re: Overriding behaviour of `is` for small-sized-optimized strings

2018-11-04 Thread Jacob Carlborg via Digitalmars-d-learn

On 2018-11-04 12:49, Per Nordlöw wrote:

At

https://github.com/nordlow/phobos-next/blob/master/src/sso_string.d

I would like to override the behaviour of

     `x is y`

for `x` and `y` being instances of `SSOString`.

to always mean

     `x[] is y[]`

How do I do this?

Is this the recommended behaviour in D for small-size-optimized strings?


You cannot overload the the "is" operator. Use "==" if you want to 
overload it.


--
/Jacob Carlborg


Overriding behaviour of `is` for small-sized-optimized strings

2018-11-04 Thread Per Nordlöw via Digitalmars-d-learn

At

https://github.com/nordlow/phobos-next/blob/master/src/sso_string.d

I would like to override the behaviour of

`x is y`

for `x` and `y` being instances of `SSOString`.

to always mean

`x[] is y[]`

How do I do this?

Is this the recommended behaviour in D for small-size-optimized 
strings?


Re: Need help with calling a list of functions

2018-11-04 Thread Sebastiaan Koppe via Digitalmars-d-learn

On Sunday, 4 November 2018 at 01:17:01 UTC, Luigi wrote:
I need to call a function that can create a function from an 
array of functions and calls them in reverse order.  I am 
learning D any help would be


That sounds a lot like std.functional.compose