Re: Struct List Human

2017-09-24 Thread dark777 via Digitalmars-d-learn

On Sunday, 24 September 2017 at 15:51:01 UTC, dark777 wrote:

On Sunday, 24 September 2017 at 15:22:30 UTC, Suliman wrote:

On Sunday, 24 September 2017 at 14:32:14 UTC, dark777 wrote:

I have the following code:
https://pastebin.com/PWuaXJNp
but typing my name does not go to the next line as soon as I 
press enter

how to solve this?


use writeln instead write


nothing to see hand

when you execute and call
Name:

I type my name:
Name: dark777 + [enter]

and he does not jump to the next line to get the age
This is what I want to know how to solve.


nothing to see hand

when you execute and call
Name:

I type my name:
Name: dark777 + [enter]

and he does not jump to the next line to get the age
This is what I want to know how to solve.


Re: Is it possible to avoid call to destructor for structs?

2017-09-24 Thread bitwise via Digitalmars-d-learn

On Sunday, 24 September 2017 at 17:11:26 UTC, Haridas wrote:
In the following code, Bar is an element of struct Foo. Is 
there a way to avoid a call to ~Bar when ~Foo is getting 
executed?




Don't construct it to begin with.

struct Bar {
import std.stdio : writeln;
int a = 123;
void boink() { writeln(a); }
~this(){ writeln("bar dtor"); }
}

struct Foo
{
ubyte[Bar.sizeof] barBuffer;
Bar* _bar = null;

ref Bar bar()
{
import std.conv : emplace;

if(!_bar) {
_bar = cast(Bar*)barBuffer.ptr;
emplace(_bar);
}

return *_bar;
}
}

int main(string[] argv)
{
Foo foo;
foo.bar.boink();
return 0;
}



asm.dlang.org needs newer DMD versions

2017-09-24 Thread Johan Engelen via Digitalmars-d
http://asm.dlang.org/ does not have DMD 2.072, 2.073, 2.074, 
2.075, nor 2.076.

Thanks for updating the site.

Cheers,
  Johan



Is it possible to avoid call to destructor for structs?

2017-09-24 Thread Haridas via Digitalmars-d-learn
In the following code, Bar is an element of struct Foo. Is there 
a way to avoid a call to ~Bar when ~Foo is getting executed?


// >>

import std.stdio;

struct Foo {
  Bar bar;
  ~this() {
writeln("~Foo");
// some code that disables call to ~Bar
  }
}

struct Bar {
  ~this() {
writeln("~Bar");
  }
}

void main() {
  Foo foo;
}



Re: Struct List Human

2017-09-24 Thread Adam D. Ruppe via Digitalmars-d-learn
I think readf("%s") reads everything available. readf(" %s\n") 
might help but personally, I say avoid readf.


Just use readln and to!int instead


auto line = readln();
if(line.length == 0)
   writeln("please enter a number");

age = to!int(line);


to is from import std.conv


Re: 100,000th thread on the NG

2017-09-24 Thread bitwise via Digitalmars-d

On Sunday, 24 September 2017 at 04:24:55 UTC, user1234 wrote:

This is the 100,000th Thread.


https://m.popkey.co/61642c/WxA4D.gif


Re: Is it possible to avoid call to destructor for structs?

2017-09-24 Thread Adam D. Ruppe via Digitalmars-d-learn

On Sunday, 24 September 2017 at 17:11:26 UTC, Haridas wrote:
In the following code, Bar is an element of struct Foo. Is 
there a way to avoid a call to ~Bar when ~Foo is getting 
executed?


No, but you could just set a flag in Bar that the destructor 
checks and skips running if it is set.


In fact, the destructor should do nothing if bar is in its 
initial state, so that's how you could check it. For example


~this() {
   if(this.member is null) return;
   // finalize this.member
}




Re: Struct List Human

2017-09-24 Thread dark777 via Digitalmars-d-learn
On Sunday, 24 September 2017 at 17:05:11 UTC, Neia Neutuladh 
wrote:

On Sunday, 24 September 2017 at 16:13:30 UTC, dark777 wrote:

when you execute and call
Name:

I type my name:
Name: dark777 + [enter]

and he does not jump to the next line to get the age
This is what I want to know how to solve.


Add a `writeln();` after reading input, maybe?


I changed the write by writeln and it still did not work, I added 
it after receiving the first entry and it did not work ...


Re: Struct List Human

2017-09-24 Thread dark777 via Digitalmars-d-learn

On Sunday, 24 September 2017 at 15:22:30 UTC, Suliman wrote:

On Sunday, 24 September 2017 at 14:32:14 UTC, dark777 wrote:

I have the following code:
https://pastebin.com/PWuaXJNp
but typing my name does not go to the next line as soon as I 
press enter

how to solve this?


use writeln instead write


nothing to see hand

when you execute and call
Name:

I type my name:
Name: dark777 + [enter]

and he does not jump to the next line to get the age
This is what I want to know how to solve.


Re: Struct List Human

2017-09-24 Thread Neia Neutuladh via Digitalmars-d-learn

On Sunday, 24 September 2017 at 16:13:30 UTC, dark777 wrote:

when you execute and call
Name:

I type my name:
Name: dark777 + [enter]

and he does not jump to the next line to get the age
This is what I want to know how to solve.


Add a `writeln();` after reading input, maybe?


Re: Simple web server benchmark - vibe.d is slower than node.js and Go?

2017-09-24 Thread Vadim Lopatin via Digitalmars-d

On Friday, 22 September 2017 at 09:40:00 UTC, Sönke Ludwig wrote:
What's was the last status? Could you observe any meaningful 
thread scaling?

It works for me - multithreading improves performance on my PC.


So far, test results on 
https://github.com/nuald/simple-web-benchmark
show that D is 2-3 times slower than any other language including 
node.js


nuald reverted change which enables multithreading since it's 
"unfair".


Re: Is it possible to avoid call to destructor for structs?

2017-09-24 Thread Haridas via Digitalmars-d-learn
Also consider the following code. Please let me know if I am 
doing the right thing for dynamic arrays. My hack seems to have 
the desired effect on shutting down the destructor. Is this hack 
legal use of D? Can you please guide me if/how it can be achieved 
for std.container.Array?


// 
import std.stdio;

struct Bar {
  ~this() {
writeln("~Bar");
  }
}

void main() {
  { // dynamic array
Bar[] bars;
bars.length = 4;
void* tmp = bars.ptr;
delete(tmp);
bars.length = 0;
  }
  { // std.container.Array
import std.container: Array;
Array!Bar bars;
bars.length = 6;
// does not seem to work
void* tmp = &(bars[0]);
delete(tmp);
bars.length = 0;
  }
}



Re: Struct List Human

2017-09-24 Thread dark777 via Digitalmars-d-learn

On Sunday, 24 September 2017 at 18:00:32 UTC, Adam D. Ruppe wrote:
I think readf("%s") reads everything available. readf(" %s\n") 
might help but personally, I say avoid readf.


Just use readln and to!int instead


auto line = readln();
if(line.length == 0)
   writeln("please enter a number");

age = to!int(line);


to is from import std.conv


I added \n and it worked.

I created a float variable and wanted to know how to read or 
print the same?


reading?

write ("Weight:");
   readf (" %ld\n", );

and

writefln ("Weight:% ld", human.peso);

but he returned me errors


Re: Is it possible to avoid call to destructor for structs?

2017-09-24 Thread Biotronic via Digitalmars-d-learn

On Sunday, 24 September 2017 at 18:46:15 UTC, Haridas wrote:
Also consider the following code. Please let me know if I am 
doing the right thing for dynamic arrays. My hack seems to have 
the desired effect on shutting down the destructor. Is this 
hack legal use of D? Can you please guide me if/how it can be 
achieved for std.container.Array?


// 
import std.stdio;

struct Bar {
  ~this() {
writeln("~Bar");
  }
}

void main() {
  { // dynamic array
Bar[] bars;
bars.length = 4;
void* tmp = bars.ptr;
delete(tmp);
bars.length = 0;
  }
  { // std.container.Array
import std.container: Array;
Array!Bar bars;
bars.length = 6;
// does not seem to work
void* tmp = &(bars[0]);
delete(tmp);
bars.length = 0;
  }
}


Since you're deleting the memory the dynamic array is pointing 
to, what you're doing is potentially unsafe - if anyone touches 
that memory after it's been deleted, nasal demons may follow.


What you want is something like this:

import std.stdio;

struct Bar
{
this(int n) {}

~this()
{
writeln("~Bar");
}
}

struct SuppressGC(T)
{
// Disguise T as a humble array.
private ubyte[T.sizeof] _payload;

// Create from instance of T.
this(T arg) {
_payload = *cast(ubyte[T.sizeof]*)
}

// Or forward constructor arguments to T's constructor.
static if (__traits(hasMember, T, "__ctor"))
{
this(Args...)(Args args)
if (__traits(compiles, (Args e){__traits(getMember, 
T.init, "__ctor")(e);}))

{
__traits(getMember, get, "__ctor")(args);
}
}

// Pretend to be a T.
@property
ref T get()
{
return *cast(T*)_payload.ptr;
}

alias get this;
}

void useBar(ref Bar b) {}

unittest
{
// Construct from instance.
//This creates a temporary on the stack, and its destructor 
will be called.

SuppressGC!Bar a = Bar(3);

// Or by forwarding constructor arguments.
// This constructs in-place inside SuppressGC, and no 
destructor will be called.

auto b = SuppressGC!Bar(3);

SuppressGC!Bar[] arr;
arr.length = 3;

// Another stack temporary. Destructor will be called.
arr[0] = Bar(5);

// No temp
arr[1] = SuppressGC!Bar(5);

// It even pretends to be the wrapped struct:
useBar(b);
}

In general, of course, this is a bad idea - there's probably a 
reason that destructor does the thing it's doing. If you're sure 
skipping it is what you want, go ahead.


--
  Biotronic


Re: Simple web server benchmark - vibe.d is slower than node.js and Go?

2017-09-24 Thread bitwise via Digitalmars-d
On Sunday, 24 September 2017 at 08:08:35 UTC, Petar Kirov 
[ZombineDev] wrote:

On Saturday, 23 September 2017 at 22:07:58 UTC, bitwise wrote:


[...]


Can you give a bit more details? What kind of architectures do 
you mean (hardware, software, ..)?
What was your use case? IO-multiplexing, coarse-grained 
high-level cooperative multi-tasking, or range-like data 
processing state-machines?


Probably not without embarrassing myself ;)
Even now, server tech isn't really my domain, and it was a long 
time ago.


The effort was mainly a learning experience to better understand 
what's going on under the hood when working on multiplayer games, 
web-apps, etc..


All of my implementations were built around the same code though, 
except request scheduling, where I first tried some kind of state 
machine, and then switched to fibers afterward, which totally 
destroyed it's already mediocre performance.


Very interesting, I would like to hear more about your 
approach. I have kind of the opposite experience with C# v7.1. 
When writing synchronous pull-style code I constantly miss the 
power of D's ranges


I'm not talking about using IEnumerators as generators. I mean 
using them for user-level threads. So basically, an IEnumerator 
method being "ticked" regularly by a scheduler/engine could 
return a scalar or predicate that specified when execution should 
resume, or it could return another IEnumerator method that the 
scheduler would run to completion before returning to the first 
one.


Simplified pseudo-example:

`
IEnumerator Attack(enemy) {
// attack until enemy dead or escaped
// maybe the enemy parameter should be 'scope' XD
}

IEnumerator Idle() {
enemy = null;

while(true) {
position += wanderOffset();

if(enemy = getEnemiesInRange()) {
yield Attack(enemy);
enemy = null;
yield 2.seconds;
}

yield;
}
}

engine.runCoroutine(Idle());

while(true) { // 60 FPS+
engine.tickCoroutines();
// ...
engine.draw();
}
`

I think it's easy to imagine how using fibers would be much more 
expensive in the above example as it scales in number of AI 
characters and complexity of behavior.


About push-style asynchronous code, I find async/await unusable 
for anything more than the absolute basic stuff. For 95% of my 
code in this area I use RX.NET (http://reactivex.io/). I'm sure 
they probably use async/await somewhere down in their 
implementation, but I just find that it scales very poorly when 
complexity increases.
My time "lost" by going from Task to IObservable (yes, 
even for single items) is immediately regained by using a few 
powerful operators like Buffer, CombineLatest and Switch.


I'm not sure I understand exactly what you're talking about here, 
but I know that basic applications get A LOT easier with 
async/await. For GUI-based applications with network 
connectivity, the whole concept of threading basically 
disappears. No need for locks, no need to dispatch UI updates to 
the main thread. Just code naturally and expect functions that 
make network calls to just take as long as they need without ever 
blocking the UI thread.


As far as using async/await at scale, I would blame C# and it's 
standard library before than the underlying concept itself. I 
don't think there's anything inherently slow about an async/await 
type framework, but if you look at microsoft's reference source 
for C# online, you can see that it's designed with productivity 
in mind, and that performance takes a back seat. I'm sure the 
situation in C++ will be very different if stackless resumables 
are accepted.




Re: Is it possible to avoid call to destructor for structs?

2017-09-24 Thread Haridas via Digitalmars-d-learn

Thanks Adam

Actually Bar's API and implementation is not in my control. 
Consider the scenario where it is implemented in a library. Or a 
scenario where I have millions of instances of Bar (not 
necessarily as a component of Foo) and I do not want to add to 
runtime memory footprint.


Ok, consider the following code. Now I am (seemingly) avoiding a 
call to Bar's destructor by way of using pointers. But I have 
doubts if delete on void pointer would reclaim the memory that 
has been allocated while still not calling the destructor?


// 
import std.stdio;

struct Foo {
  Bar* bar;
  this(size_t l) {
bar = cast(Bar*) new Bar[l];
  }
  ~this() {
writeln("~Foo");
void *tmp = cast(void*) bar;
// would this reclaim memory
// allocated to Bar*
delete(tmp);
  }
}

struct Bar {
  ~this() {
writeln("~Bar");
  }
}

void main() {
  Foo foo = 4;
}



Re: Should we add `a * b` for vectors?

2017-09-24 Thread Mark via Digitalmars-d
On Friday, 22 September 2017 at 17:11:56 UTC, Ilya Yaroshenko 
wrote:

Should we add `a * b` to ndslice for 1d vectors?
Discussion at https://github.com/libmir/mir-algorithm/issues/91


Generally I expect that a binary operation denoted by + or * 
would produce an element from the original domain, e.g. 
multiplying two matrices yields a matrix, concatenating two 
strings yields a string, etc. So personally I don't like this 
notation.


Note that in the case of 3-dimensional vectors, people might 
confuse this for the cross product. I would go with dot(a,b) and 
cross(a,b) (if you support it).


Re: Struct alignment

2017-09-24 Thread EntangledQuanta via Digitalmars-d

On Sunday, 24 September 2017 at 21:01:06 UTC, Johan Engelen wrote:

DMD <= 2.074  and DMD >= 2.075 disagree on struct alignment.

```
struct UInt {
align(1):
uint a;
}

struct Bug {
ubyte one;
UInt two;
}

static assert(Bug.two.offsetof == 4); // Error DMD>=2.075, 1 == 
4 is false
static assert(Bug.sizeof == 8); // Error DMD>=2.075, 5 == 8 is 
false


align(1)
struct Align1UInt {
align(1):
uint a;
}

struct BugAlign1 {
ubyte one;
Align1UInt two;
}

static assert(BugAlign1.two.offsetof == 1);
static assert(BugAlign1.sizeof == 5); // Error DMD<=2.074, 8 == 
5 is false

```

So... what's correct? :-)

Cheers,
  Johan


Don't worry, this isn't a bug! It's a feature! It will just make 
your programs run faster! It won't get fixed! Don't want to break 
backwards compatibility, do we?




Struct alignment

2017-09-24 Thread Johan Engelen via Digitalmars-d

DMD <= 2.074  and DMD >= 2.075 disagree on struct alignment.

```
struct UInt {
align(1):
uint a;
}

struct Bug {
ubyte one;
UInt two;
}

static assert(Bug.two.offsetof == 4); // Error DMD>=2.075, 1 == 4 
is false
static assert(Bug.sizeof == 8); // Error DMD>=2.075, 5 == 8 is 
false


align(1)
struct Align1UInt {
align(1):
uint a;
}

struct BugAlign1 {
ubyte one;
Align1UInt two;
}

static assert(BugAlign1.two.offsetof == 1);
static assert(BugAlign1.sizeof == 5); // Error DMD<=2.074, 8 == 5 
is false

```

So... what's correct? :-)

Cheers,
  Johan



Re: Is it possible to avoid call to destructor for structs?

2017-09-24 Thread bitwise via Digitalmars-d-learn

On Monday, 25 September 2017 at 01:46:15 UTC, Haridas wrote:

[...]

It all works well so far. But as soon as I create an instance 
of Bar inside a Dlang class (say Foo) or as part of a Dlang 
dynamic array, hell follows. At some point, Dlang's GC kicks in 
and Bar's destructor gets called from within Dlang's GC. Now 
since Dlang executes GC on a different thread, the destructor 
gets confused and segfaults.


I actually wrote a C# style Dispatcher for exactly this reason. I 
have D classes that own non thread-safe resources. So in the 
destructor of the D class, I add a call that queues the 
destruction to the main thread's dispatcher.


In your case, the postblit of Bar is still going to run and add a 
ref to it's count when you place it in Foo, right? That means 
that if you don't destroy it, it will leak memory or resources.


Unfortunately, my dispatcher is not production-ready yet, but you 
can get around this with a simpler approach. Just keep a shared 
container of your ref counted object type somewhere. When a 
destructor of a GC class runs, move the ref counted object into 
the trash container. Then, next time you want to create an 
instance of the ref counted object, you can empty the trash 
container at the same time. You should protect the container with 
a Mutex of some kind. Also, be sure that the container doesn't 
allocate using the GC since it will be called from class 
destructors. IIRC std.container.Array uses malloc, not GC, so you 
may be able to use that.









Re: Struct alignment

2017-09-24 Thread Johan Engelen via Digitalmars-d

On Sunday, 24 September 2017 at 21:21:27 UTC, kinke wrote:
On Sunday, 24 September 2017 at 21:01:06 UTC, Johan Engelen 
wrote:

So... what's correct? :-)


2.075+. ;)
See https://github.com/dlang/dmd/pull/6754.


Thanks kinke.
(now on to fix LDC's codegen ;-)


Re: asm.dlang.org needs newer DMD versions

2017-09-24 Thread Iain Buclaw via Digitalmars-d
On 24 September 2017 at 22:10, Johan Engelen via Digitalmars-d
 wrote:
> http://asm.dlang.org/ does not have DMD 2.072, 2.073, 2.074, 2.075, nor
> 2.076.
> Thanks for updating the site.
>
> Cheers,
>   Johan
>

I'll have a look at it possibly tomorrow.

Iain.


Re: Struct alignment

2017-09-24 Thread kinke via Digitalmars-d

On Sunday, 24 September 2017 at 21:01:06 UTC, Johan Engelen wrote:

So... what's correct? :-)


2.075+. ;)
See https://github.com/dlang/dmd/pull/6754.


Re: Should we add `a * b` for vectors?

2017-09-24 Thread Nicholas Wilson via Digitalmars-d

On Sunday, 24 September 2017 at 23:59:59 UTC, jmh530 wrote:

On Sunday, 24 September 2017 at 22:33:48 UTC, H. S. Teoh wrote:


With UFCS, you have the slightly nicer notation a.dot(b) and 
a.cross(b).



T


Below is a link to the operators in Matlab and associated 
functions. mir can include all of those functions, but not all 
of them can be implemented as operators (because D doesn't have 
things like .*). I think it would be annoying to constantly 
have to write plus or mtimes in writing formulas for a linear 
algebra library.


https://www.mathworks.com/help/matlab/matlab_prog/matlab-operators-and-special-characters.html


There's nothing stopping someone writing a DIP to include `@` 
(and possibly `#`) as overloadable binary operators. All other 
characters on the standard keyboard are used I think.


Re: Is it possible to avoid call to destructor for structs?

2017-09-24 Thread Haridas via Digitalmars-d-learn
In general, of course, this is a bad idea - there's probably a 
reason that destructor does the thing it's doing. If you're 
sure skipping it is what you want, go ahead.


@Biotronic, the code you have provided may be exactly what I am 
looking for. Let me explain my situation.


I have a library that has been ported from a C/C++ code. A struct 
Bar that is part of the library implements its own refcounted GC. 
The refcounted GC of course works via constructor and destructor. 
But this refcounted GC also uses some thread local variables 
since there is a need to implement parallelism.


It all works well so far. But as soon as I create an instance of 
Bar inside a Dlang class (say Foo) or as part of a Dlang dynamic 
array, hell follows. At some point, Dlang's GC kicks in and Bar's 
destructor gets called from within Dlang's GC. Now since Dlang 
executes GC on a different thread, the destructor gets confused 
and segfaults. Fortunately for me, it would be fine if the call 
to destructor is completely avoided within the realm of Dlang's 
GC since I do not need the Bar instances thereafter. All I need 
to do is to dismantle Bar completely from the memory to avoid 
leaks. So long as I can avoid calls to Bar's destructor from 
within Dlang's GC, I am fine.


I also have some limitations. Since we need to run all this on an 
embedded system with limited RAM (and given that I have millions 
of instances of Bar which is only 32-bit wide), I do not want to 
add a flag or other stuff to Bar. And that is the reason we are 
using thread local storage in the refcounted GC.


So there. I will try your way. Let me see if I can make it to 
work in my situation. Thanks for sharing.


Re: Simple web server benchmark - vibe.d is slower than node.js and Go?

2017-09-24 Thread Arun Chandrasekaran via Digitalmars-d

On Sunday, 24 September 2017 at 18:36:50 UTC, Vadim Lopatin wrote:
On Friday, 22 September 2017 at 09:40:00 UTC, Sönke Ludwig 
wrote:
What's was the last status? Could you observe any meaningful 
thread scaling?

It works for me - multithreading improves performance on my PC.


So far, test results on 
https://github.com/nuald/simple-web-benchmark
show that D is 2-3 times slower than any other language 
including node.js


nuald reverted change which enables multithreading since it's 
"unfair".


Just cloned the repo and tried. With ldc 1.4.0 (release mode) I 
get Illegal instruction (core dumped). Debug mode works fine. 
Works fine with dmd v2.075.1 release mode.


```
24-09-2017 15:08:37 vaalaham ~/code/d/simple-web-benchmark/d
$ bin/vibedtest
Illegal instruction (core dumped)
24-09-2017 15:08:40 vaalaham ~/code/d/simple-web-benchmark/d
$
```


Re: Should we add `a * b` for vectors?

2017-09-24 Thread H. S. Teoh via Digitalmars-d
On Sun, Sep 24, 2017 at 06:18:38PM +, Mark via Digitalmars-d wrote:
> On Friday, 22 September 2017 at 17:11:56 UTC, Ilya Yaroshenko wrote:
> > Should we add `a * b` to ndslice for 1d vectors?
> > Discussion at https://github.com/libmir/mir-algorithm/issues/91
> 
> Generally I expect that a binary operation denoted by + or * would produce
> an element from the original domain, e.g. multiplying two matrices yields a
> matrix, concatenating two strings yields a string, etc. So personally I
> don't like this notation.
> 
> Note that in the case of 3-dimensional vectors, people might confuse this
> for the cross product. I would go with dot(a,b) and cross(a,b) (if you
> support it).

With UFCS, you have the slightly nicer notation a.dot(b) and a.cross(b).


T

-- 
Claiming that your operating system is the best in the world because more 
people use it is like saying McDonalds makes the best food in the world. -- 
Carl B. Constantine


Re: Should we add `a * b` for vectors?

2017-09-24 Thread jmh530 via Digitalmars-d

On Sunday, 24 September 2017 at 18:18:38 UTC, Mark wrote:


Generally I expect that a binary operation denoted by + or * 
would produce an element from the original domain, e.g. 
multiplying two matrices yields a matrix, concatenating two 
strings yields a string, etc. So personally I don't like this 
notation.


This is true of element-wise operators. + works, - works, but * 
(and by implication /) only has that property for Hadamard/Schur 
products. It also would work for inverse. Even matrix 
multiplication could have A*B produce a matrix, but if A is 1XN 
and B is MX1, then you may as well return the scalar.




Note that in the case of 3-dimensional vectors, people might 
confuse this for the cross product. I would go with dot(a,b) 
and cross(a,b) (if you support it).


I assure you, no one would confuse dot for cross. No language or 
linear algebra library does this. The typical option is matrix 
multiplication for *, but languages like Python and Matlab can't 
do things like have a special version that is dot for vectors and 
matrix multiplication for matrices.


Re: Should we add `a * b` for vectors?

2017-09-24 Thread jmh530 via Digitalmars-d

On Sunday, 24 September 2017 at 22:33:48 UTC, H. S. Teoh wrote:


With UFCS, you have the slightly nicer notation a.dot(b) and 
a.cross(b).



T


Below is a link to the operators in Matlab and associated 
functions. mir can include all of those functions, but not all of 
them can be implemented as operators (because D doesn't have 
things like .*). I think it would be annoying to constantly have 
to write plus or mtimes in writing formulas for a linear algebra 
library.


https://www.mathworks.com/help/matlab/matlab_prog/matlab-operators-and-special-characters.html


Re: GDC in Slackware and a bit about GDC development

2017-09-24 Thread Iain Buclaw via Digitalmars-d-announce
On 23 September 2017 at 22:55, Eugene Wissner via
Digitalmars-d-announce  wrote:
> On Saturday, 23 September 2017 at 20:34:51 UTC, Iain Buclaw wrote:
>>
>> On 23 September 2017 at 21:45, Eugene Wissner via Digitalmars-d-announce
>>  wrote:
>>>
>>> GDC looks pretty nice. I had only one problem: I got a linking error if I
>>> use core.stdc.stdarg; not sure if it is my failure or a bug. But I could
>>> build my library and run tests. Pretty nice.
>>>
>>
>> What's the linker error?
>
>
> Here is the code, test.d:
>
> import core.stdc.stdarg;
>
> void format(char[] buf, ...)
> {
> va_list va;
> va_start(va, buf);
> va_end(va);
>  }
>
> void main()
> {
> }
>
>
> $ gdc test.d
> /tmp/ccwm5f8o.o: In function `_D4test6formatFAaYv':
> test.d:(.text+0x114): undefined reference to
> `_D4core4stdc6stdarg6va_endFNbPS4core4stdc6stdarg13__va_list_tagZv'
> collect2: ld returned 1 exit status
>
>

That would almost certainly only happen if you were using a different
druntime.  Check where your import modules are coming from, they
probably aren't gdc's.


>> Looks good.  A simpler GCC frontend would be
>> https://github.com/giuseppe/gccbrainfuck
>>
> But without the great explanations :)

True, it's more a skeleton front-end, which shows you only the most
important files and hooks to be aware of in order to get started.


Re: GC operates in LIFO sequence?

2017-09-24 Thread Joseph5 via Digitalmars-d

Hmmm. Find some useful information here.


Re: Should we add `a * b` for vectors?

2017-09-24 Thread Z via Digitalmars-d

On Sunday, 24 September 2017 at 05:24:57 UTC, Manu wrote:
On 23 September 2017 at 03:11, Ilya Yaroshenko via 
Digitalmars-d < digitalmars-d@puremagic.com> wrote:



Should we add `a * b` to ndslice for 1d vectors?
Discussion at https://github.com/libmir/mir-algorithm/issues/91



I often ponder this sort of question... and while the nerdy bit 
of my would
love to see this, I can never get past the fact that 
`is(typeof(a) !=
typeof(a * b))`... I feel that's a big enough reason to put a 
bullet in the
idea. D has array operations, which look just like 1d ndslices, 
also SIMD
vectors usually implement operators, but they do element-wise 
operation, so

now there's a confusion.
Consider, a generic function receives some T; if T is a slice 
or simd, it
does element-wise stuff, if T is an ndslice, it behaves 
differently. That

doesn't seem right.


Python has a dedicated matrix multiplication operator, that is 
not used by the standard library, but is implemented for e.g. 
numpy arrays.


https://www.python.org/dev/peps/pep-0465/


[Issue 17855] New: Forum draft, error accessing 5-month-old draft, can't dismiss banner

2017-09-24 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=17855

  Issue ID: 17855
   Summary: Forum draft, error accessing 5-month-old draft, can't
dismiss banner
   Product: D
   Version: D2
  Hardware: x86_64
OS: Linux
Status: NEW
  Severity: enhancement
  Priority: P1
 Component: dlang.org
  Assignee: nob...@puremagic.com
  Reporter: eiderd...@gmail.com

My Dlang forum account is SimonN.

When I click "reply" on any post or click "create thread", I land on the page
with the normal text input boxes, and at the top a yellow banner: "You have an
unsent draft message from May 02."

The banner links to "http://forum.dlang.org/posting/xgwdtmcwvydwdwjefvze;. I
click on that address, I get an error: "Expected n, got {".

This doesn't discard the draft.

Expected instead: No error. And some way to discard the draft, dismissing the
yellow banner for this particular draft.

--


[Issue 17855] Forum draft, error accessing 5-month-old draft, can't dismiss banner

2017-09-24 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=17855

b2.t...@gmx.com changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 CC||b2.t...@gmx.com
 Resolution|--- |INVALID

--- Comment #1 from b2.t...@gmx.com ---
report here https://github.com/CyberShadow/DFeed

The bugzilla category dlang.org is for the all the static content (DMD manual,
language specs, etc).

--


Struct List Human

2017-09-24 Thread dark777 via Digitalmars-d-learn

I have the following code:
https://pastebin.com/PWuaXJNp
but typing my name does not go to the next line as soon as I 
press enter

how to solve this?


Re: Struct List Human

2017-09-24 Thread Suliman via Digitalmars-d-learn

On Sunday, 24 September 2017 at 14:32:14 UTC, dark777 wrote:

I have the following code:
https://pastebin.com/PWuaXJNp
but typing my name does not go to the next line as soon as I 
press enter

how to solve this?


use writeln instead write


[Issue 17855] Forum draft, error accessing 5-month-old draft, can't dismiss banner

2017-09-24 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=17855

Simon Na.  changed:

   What|Removed |Added

   Severity|enhancement |normal

--


Re: Simple web server benchmark - vibe.d is slower than node.js and Go?

2017-09-24 Thread Petar via Digitalmars-d

On Saturday, 23 September 2017 at 22:07:58 UTC, bitwise wrote:


Of the few different architectures I tried, the fiber based 
approach was much slower. It's possible that my implementation 
did too many unnecessary context switches.


Can you give a bit more details? What kind of architectures do 
you mean (hardware, software, ..)?
What was your use case? IO-multiplexing, coarse-grained 
high-level cooperative multi-tasking, or range-like data 
processing state-machines?




I suppose this is off topic, but for games, or any realtime 
application where things need to run intermittently, but at 
high frequency, and in high numbers, stackless resumable 
functions are a big win. A lot of AI I've been writing lately 
(including some flocking behaviors) have been built on top of 
C# IEnumerators.


Very interesting, I would like to hear more about your approach. 
I have kind of the opposite experience with C# v7.1. When writing 
synchronous pull-style code I constantly miss the power of D's 
ranges, templates and DbI, when I'm forced to work with C#'s 
IEnumerable extension methods, expression trees and run-time 
reflection.
About push-style asynchronous code, I find async/await unusable 
for anything more than the absolute basic stuff. For 95% of my 
code in this area I use RX.NET (http://reactivex.io/). I'm sure 
they probably use async/await somewhere down in their 
implementation, but I just find that it scales very poorly when 
complexity increases.
My time "lost" by going from Task to IObservable (yes, even 
for single items) is immediately regained by using a few powerful 
operators like Buffer, CombineLatest and Switch.


Re: Real beginner traits question

2017-09-24 Thread rikki cattermole via Digitalmars-d-learn

On 25/09/2017 6:28 AM, WhatMeForget wrote:


This is taken exactly from the traits documentation.



25 Traits

25.21 identifier

Takes one argument, a symbol. Returns the identifier for that symbol as 
a string literal.





There are no examples. My naive brain keeps thinking that a symbol and 
an identifier are the same things.  Can someone give me good definitions 
of "symbol" and "identifier".   And maybe an example if it is not too 
much trouble.


```D
void main() {}

pragma(msg, __traits(identifier, main));
pragma(msg, __traits(identifier, Foo));
pragma(msg, __traits(identifier, Foo.func));

struct Foo {
void func();
}
```

```
main
Foo
func
```


Re: Simple web server benchmark - vibe.d is slower than node.js and Go?

2017-09-24 Thread Sönke Ludwig via Digitalmars-d

Am 24.09.2017 um 20:36 schrieb Vadim Lopatin:

On Friday, 22 September 2017 at 09:40:00 UTC, Sönke Ludwig wrote:
What's was the last status? Could you observe any meaningful thread 
scaling?

It works for me - multithreading improves performance on my PC.


So far, test results on https://github.com/nuald/simple-web-benchmark
show that D is 2-3 times slower than any other language including node.js


The response times look very strange for the kind of load that appears 
to be generated. Unfortunately the testing methodology is so simple that 
it's difficult so judge anything without running it again locally.


Having said that, the Windows implementation does have performance 
issues and needs to be looked at. It has rather low priority for me 
though, because I neither run any servers with Windows, nor did I hear 
that from anyone else who uses vibe.d.




nuald reverted change which enables multithreading since it's "unfair".


How on earth can that be unfair when the Go, node.js and Scala versions 
appear to use multi-threading, too?


Re: 100,000th thread on the NG

2017-09-24 Thread user1234 via Digitalmars-d

On Sunday, 24 September 2017 at 04:24:55 UTC, user1234 wrote:

This is the 100,000th Thread.


A few hours ago, i was letting my mind flying. What if i were a 
professor. What would i tell about D...


"
We reach the end of this short course. Next time we'll see us 
you'll be tested.
This test has a low coefficient but here are few things i want 
you to keep in mind.


1/ A small part of you will become decision makers.
2/ Another small part of you will teach.
3/ Most of you won't be in the 2 first parts and will probably 
only work up to 10 years in IT.


I hope that the two first categories won't forget this course.
"


Re: Should we add `a * b` for vectors?

2017-09-24 Thread jmh530 via Digitalmars-d
On Monday, 25 September 2017 at 01:08:35 UTC, Nicholas Wilson 
wrote:


There's nothing stopping someone writing a DIP to include `@` 
(and possibly `#`) as overloadable binary operators.


I actually like * for dot product and matrix multiplication...

The issue is that if you use * for these, then you can't use it 
for element-wise multiplication. Numpy arrays (but not matrices) 
use * and / for element-wise multiplication and division. To do 
matrix multiplication with Numpy arrays, you used to have to use 
the dot function. This is they decided to introduce @ to the 
language, b/c users didn't want to write dot all over the place.


A very popular language with a wide range of uses had to 
introduce a new operator to the language because of design 
choices of its most popular linear algebra library. So it makes 
sense to think about these issues a bit.



All other characters on the standard keyboard are used I think.


What about forward slash '\' (for inverse)? That is currently 
used for string literals, but I can't think of a binary use right 
now.






Re: Is it possible to avoid call to destructor for structs?

2017-09-24 Thread Haridas via Digitalmars-d-learn
In your case, the postblit of Bar is still going to run and add 
a ref to it's count when you place it in Foo, right? That means 
that if you don't destroy it, it will leak memory or resources.




Actually no. Since when Foo (class that instantiates Bar) gets 
GCed, that is the point that I need to destroy the whole 
infrastructure around Bar, including its recounted GC. So I am Ok 
if destructor of Bar does not get called this one time since I am 
just going to delete the whole block of memory that I have 
allocated for placing the refcounted instances of Bar.


Re: Should we add `a * b` for vectors?

2017-09-24 Thread user1234 via Digitalmars-d
On Monday, 25 September 2017 at 01:08:35 UTC, Nicholas Wilson 
wrote:
There's nothing stopping someone writing a DIP to include `@` 
(and possibly `#`) as overloadable binary operators. All other 
characters on the standard keyboard are used I think.


̣̣§


Real beginner traits question

2017-09-24 Thread WhatMeForget via Digitalmars-d-learn


This is taken exactly from the traits documentation.



25 Traits

25.21 identifier

Takes one argument, a symbol. Returns the identifier for that 
symbol as a string literal.





There are no examples. My naive brain keeps thinking that a 
symbol and an identifier are the same things.  Can someone give 
me good definitions of "symbol" and "identifier".   And maybe an 
example if it is not too much trouble.


Re: Should we add `a * b` for vectors?

2017-09-24 Thread Nicholas Wilson via Digitalmars-d

On Monday, 25 September 2017 at 03:22:01 UTC, user1234 wrote:
On Monday, 25 September 2017 at 01:08:35 UTC, Nicholas Wilson 
wrote:
There's nothing stopping someone writing a DIP to include `@` 
(and possibly `#`) as overloadable binary operators. All other 
characters on the standard keyboard are used I think.


̣̣§


That is not on mine.