How to get sqlite3.lib x64?

2016-10-23 Thread Andre Pany via Digitalmars-d-learn

Hi,

I try to get sqlite3.lib for 64 Bit windows os.

I tried implib with the def file and the 64 Bit dll:
implib sqlite3_implib.lib sqlite3.def /system
-> App crash (Windows 10)

With the dll file defined:
implib sqlite3_implib.lib sqlite3.dll /system
-> Error message: Error(10): Error: cannot read DLL input file

I have the MS Build tools installed, but the example from
the SQLite site only shows, how to build a X86 dll file from
the C source code but not how to build the X86_64 lib file
for windows:
cl sqlite3.c -link -dll -out:sqlite3.dll

I tried different combinations but without success.
Could you give me some hints?

Kind regards
André




Re: getting started with web server - vibe.d dub giving link error

2016-10-23 Thread aman via Digitalmars-d-learn

On Sunday, 23 October 2016 at 19:23:04 UTC, Karabuta wrote:

On Sunday, 23 October 2016 at 14:53:48 UTC, aman wrote:

On Saturday, 22 October 2016 at 17:23:58 UTC, Karabuta wrote:

[...]


This time i started out with a fresh Ubuntu server and 
followed instructions on the blog. Here's output. Please help:-


/usr/lib/gcc/x86_64-linux-gnu/5/include/d/core/atomic.d:1381:13: error: static assert  
"Invalid template type specified."
 static assert(0, "Invalid template type 
specified.");

 ^
../.dub/packages/vibe-d-0.7.29/source/vibe/http/server.d:1388:51: note: 
instantiated from here: atomicLoad!(cast(MemoryOrder)5, 
shared(HTTPServerContext)[])
else return 
cast(HTTPServerContext[])atomicLoad(g_contexts);

   ^
gdc failed with exit code 1.


I used DMD compiler for the tutorial, you are using GCC which 
might be the problem. GCC compiler seems too outdated. Try 
using DMD


Oh, I see. Actually it got installed auto-magically during dub 
installation I guess. Now I installed dmd with the script mention 
on the dlang download page.

curl -fsS https://dlang.org/install.sh | bash -s dmd

I ran dub again. Here's the error this time!
dub
Performing "debug" build using dmd for x86_64.
vibe-d:utils 0.7.29: target for configuration "library" is up to 
date.
vibe-d:data 0.7.29: target for configuration "library" is up to 
date.
vibe-d:core 0.7.29: target for configuration "libevent" is up to 
date.
vibe-d:http 0.7.29: target for configuration "library" is up to 
date.
vibe-d:diet 0.7.29: target for configuration "library" is up to 
date.
vibe-d:mail 0.7.29: target for configuration "library" is up to 
date.
vibe-d:mongodb 0.7.29: target for configuration "library" is up 
to date.
vibe-d:redis 0.7.29: target for configuration "library" is up to 
date.
vibe-d:web 0.7.29: target for configuration "library" is up to 
date.

vibe-d 0.7.29: target for configuration "libevent" is up to date.
testdub ~master: building configuration "application"...
Linking...
cc: No such file or directory
--- errorlevel 255
dmd failed with exit code 255




Re: If you do something dumb enough, the test runner won't print out your test failures

2016-10-23 Thread Nick Sabalausky via Digitalmars-d

On 10/23/2016 05:52 PM, Jonathan M Davis via Digitalmars-d wrote:


import core.sys.posix.unistd;

unittest
{
 close(2);
 assert("hello" == "7");
}



Ouch! I like the punchline here :)


However, it does highlight the fact that if you just look at the output of
running the unit tests and not the exit code, you might think that your
tests succeeded when they actually failed. But fortunately, that's not
terribly likely (much as I managed to do it), and if you're using dub, it
does check the exit code.



Honestly, it's gets worse than that IMO:

I've had a bunch of time over the course of using D, with any build tool 
from bud/xfbuild (remember those?), to rdmd, to dub, where a slip-up in 
my buildscript, project configuration, or a missing import, etc would 
result in one or all of my unittests *silently!* failing to run.


I even hit it again just this week - where most tests in mysql-native 
were running...except for one, because of a missing import. The only 
reason I caught it was because I had learned to be pedantic and 
temporarily tossed in a writeln "just to be ABSOLUTELY sure...". Good 
thing I did.


This example is not only easier to hit than yours, but it's also worse 
because even the exit code will report "A-ok!".


These are all examples of why I was always opposed from the beginning to 
D's default of "no output unless a test fails": Because it makes 
"success" indistinguishable from certain types of failures.


That's why I always tried to add some "Testing blah blah whatever..." 
output at the start of every test in most of my projects: so I *KNOW* 
that what merely looks like unittest success actually *IS* unittest success.


That's also one of the biggest things I like about unit-threaded: It 
does that automatically, AND (IIRC), it shows a count of how many tests 
were run - so when I have any project with more than 
like...five...tests, I can look at that number and *know* that I'm not 
overlooking a "Hey, wait, this list of tests run is missing 'Testing 
fizzbar'!!!"




Re: Pattern matching in D?

2016-10-23 Thread Nick Sabalausky via Digitalmars-d

On 10/23/2016 11:55 PM, Nick Sabalausky wrote:



// An equivalent std.variant.Algebraic would be clunky by comparison:
  variant RgbColor {
| Red
| Yellow
| Green
| Different {
red : float;
green : float;
blue : float;
  }
  }



Just to compare to equivalent D:


struct RgbColor_ // Don't clutter the namepsace
{
struct Red {}
struct Yellow {}
struct Green {}
struct Different {
float red;
float green;
float blue;
}
}
alias RgbColor = Algenraic!(
RgbColor_.Red,
RgbColor_.Yellow,
RgbColor_.Green,
RgbColor_.Different,
}


It's just...I mean, yea, it works, and you could probably DRY it up a 
little with a type contructing template ("alias RgbColor = 
DoMagic!RgbColor_"), but...meh...


And then the pattern matching end would be similarly "ehh...meh...":


RgbColor color = ...;
auto x = color.visit(
(RgbColor_.Red a) => "red",
(RgbColor_.Yellow a) => "yellow",
(RgbColor_.Green a) => "green",
(RgbColor_.Red a) =>
mixin(interpolateStr!`rgb(${a.red}, ${a.green}, ${a.blue})`),
);


Again, technically works, but...ehh, it's like doing slices or 
high-order funcs in C.




Re: Pattern matching in D?

2016-10-23 Thread Nick Sabalausky via Digitalmars-d

On 10/23/2016 03:38 PM, Chris M wrote:

On Friday, 21 October 2016 at 19:00:55 UTC, Nick Sabalausky wrote:

What I've been really wanting for a long time is the one-two combo of
Nemerle's variants and pattern matching:

https://github.com/rsdn/nemerle/wiki/Grok-Variants-and-matching


There is std.variant, though I haven't used it much myself and don't
know how well it compares. Seems like that library would provide a good
basis for providing pattern matching though.


This is one of those things where language support makes a big 
difference (like slices).


Algebraic is the *closest* thing in D that compared to Nemerle's 
variants...But honestly, saying std.variant compares to Nemerle's 
variants is like saying C can do high-order functions, OOP, and has a 
module system. Yea, *technically* you can, but it's so clunky by 
comparison that you're really not getting much of the real benefit.


One of the first examples on that page really highlights how it differs 
from D:



// An equivalent std.variant.Algebraic would be clunky by comparison:
 variant RgbColor {
   | Red
   | Yellow
   | Green
   | Different {
   red : float;
   green : float;
   blue : float;
 }
 }

string_of_color (color : RgbColor) : string
{
  match (color) {
| RgbColor.Red => "red"
| RgbColor.Yellow => "yellow"
| RgbColor.Green => "green"
| RgbColor.Different (r, g, b) => $"rgb($r, $g, $b)"
  }
}


D can get close, but it's just not so clean, wouldn't scale as well, and 
that really does make a difference (just like how many of D's features 
are argued by others to be "not that big a deal", but we know that it is 
because we use it and know that extra bit of polish D gives makes a big 
difference).


And, yea, yea, Manu has a far better color color lib in D, but of course 
this is just an illustration of the language construct. It's one of 
those things (of which D really does have many - just not this one), 
that once you have it available and start using it, it's very 
liberating, and loosing it feels like having your hands tied.


It's not my #1 missed feature in D, but it would be nice.



[Issue 16627] [Reg 2.072] non-static structs with postblit/dtor fields are now nested

2016-10-23 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=16627

Martin Nowak  changed:

   What|Removed |Added

Summary|[Reg 2.072] struct with |[Reg 2.072] non-static
   |disabled postblit field is  |structs with postblit/dtor
   |now nested  |fields are now nested

--


[Issue 16627] [Reg 2.072] struct with disabled postblit field is now nested

2016-10-23 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=16627

--- Comment #2 from Martin Nowak  ---
This happens because structs are converted to nested structs by the semantic
analysis of their member functions.
The idea behind this seems to be that struct without methods can't access the
outer frame, hence never need nesting. Could be reconsidered to be deprecated
in favor of explicit `static struct` or a proper detection of closure access.

With dlang/dmd#5500 the dependency of the generate postblits/dtors on a
finalized struct size was removed, now semantic just collects a list of fields
and finalizes the size later on. This resolves some problems w/ forward
references.

Previously __fieldPostblit and __fieldDtor were generated after finalizing the
size and didn't convert structs to a nested one due to a `if (sizeok ==
SIZEOKdone) return;` check in makeNested. Now semantic for those functions runs
before the finalization and does convert structs to nested.

This bug only affects structs w/o any other function (b/c those would be nested
already) and at least one field w/ dtor/postblit.

--


Re: [OT] fastest fibbonacci

2016-10-23 Thread Timon Gehr via Digitalmars-d

On 23.10.2016 21:59, Minas Mina wrote:

On Sunday, 23 October 2016 at 13:04:30 UTC, Stefam Koch wrote:

Hi Guys,

while brushing up on my C and algorithm skills, accidently created a
version of fibbonaci which I deem to be faster then the other ones
floating around.

It's also more concise

the code is :

int computeFib(int n)
{
int t = 1;
int result = 0;

while(n--)
{
result = t - result;
t = t + result;
}

   return result;
}


You can even calculate Fibonacci in O(1).


The closed form does not give you an O(1) procedure that computes the 
same as the above code (with the same wrap-around-behaviour).


If arbitrary precision is used, the result grows linearly, so the 
calculation cannot be better than linear. I don't think the closed form 
gives you a procedure that is faster than Θ(n·log n) in that case.


Re: [OT] fastest fibbonacci

2016-10-23 Thread Stefam Koch via Digitalmars-d

On Sunday, 23 October 2016 at 19:59:16 UTC, Minas Mina wrote:

On Sunday, 23 October 2016 at 13:04:30 UTC, Stefam Koch wrote:

Hi Guys,

while brushing up on my C and algorithm skills, accidently 
created a version of fibbonaci which I deem to be faster then 
the other ones floating around.


It's also more concise

the code is :

int computeFib(int n)
{
int t = 1;
int result = 0;

while(n--)
{
result = t - result;
t = t + result;
}

   return result;
}


You can even calculate Fibonacci in O(1).


An approximation of it.



[Issue 16626] [Reg 2.073] recent dmd nightly runs out of memory building Higgs

2016-10-23 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=16626

--- Comment #2 from Martin Nowak  ---
>From Dmitry https://github.com/dlang/phobos/pull/4286#issuecomment-255182046

> The new version is more demanding on memory during CTFE so yeah, most likely 
> it now fails for some patterns. Dunno what to do here would really love to 
> see the new engine sometime soon.

That might still take a while and in the meantime such simple ctRegex eat up
16GiB (kill my project tester https://ci.dawg.eu/ btw).
If we can't really support the NFA kickstarter in CTFE, then we should just
disable it for now.

--


Re: If you do something dumb enough, the test runner won't print out your test failures

2016-10-23 Thread Jonathan M Davis via Digitalmars-d
On Sunday, October 23, 2016 21:58:30 Vladimir Panteleev via Digitalmars-d 
wrote:
> You can change your shell prompt so it displays the exit code of
> the last command. It's something frequently seen in people's
> custom prompts. (Here's mine:
> https://github.com/CyberShadow/cyberzshadow)

Wow, that's fancy. I've been using zsh for the past couple of years, but I
don't have it doing anything like that. The fanciest I got was getting the
git branch in the command prompt, and the way I did that causes repaint
problems whenever a command wraps to the next line. I'll definitely have to
check out what you've got.

- Jonathan M Davis



Re: If you do something dumb enough, the test runner won't print out your test failures

2016-10-23 Thread Vladimir Panteleev via Digitalmars-d
On Sunday, 23 October 2016 at 21:52:26 UTC, Jonathan M Davis 
wrote:
LOL. This was too funny not to share. I had a unittest failure 
in a project that I'm working on, and dub ended up just 
printing out


Nice story, thanks for sharing :)

You can change your shell prompt so it displays the exit code of 
the last command. It's something frequently seen in people's 
custom prompts. (Here's mine: 
https://github.com/CyberShadow/cyberzshadow)


If you do something dumb enough, the test runner won't print out your test failures

2016-10-23 Thread Jonathan M Davis via Digitalmars-d
LOL. This was too funny not to share. I had a unittest failure in a project
that I'm working on, and dub ended up just printing out

Program exited with code 1

rather than printing out the actual failures, which was not exactly useful.
And I thought that dub must have a bug, so I started trying to see if anyone
else had seen a similar problem and which version of dub the problems
started in (since I was sure that I'd see proper test failure output from
dub previously), and finally I figured out that no, dub didn't have a bug.
Rather, it looked like dmd or druntime did, because the problem happened
even without dub (though without dub, _nothing_ was printed, since the
"Progam exited with code 1" is a dub thing, whereas normally; the D program
that failed the unit tests just exits with a code of 1 without printing
anything), and it turned out that whether or not I saw the AssertErrors from
a test failure depended on where in the file the failing test was, which
definitely made it sound like a dmd bug.

So, in order to report the bug, I used dustmite to reduce the code and
managed to reduce it quite a bit (though not as much as I might like), and
then I manually reduced it further. And ultimately, this is basically what I
ended up with

import core.sys.posix.unistd;

unittest
{
close(2);
assert("hello" == "7");
}

void main()
{
}

My faulty code had managed to close stderr, which made it impossible for
druntime to print out the assertion failure. :)

So, I get to feel like a bit of an idiot over the whole thing, but it
definitely made me laugh when I figured out what I'd managed to do.

However, it does highlight the fact that if you just look at the output of
running the unit tests and not the exit code, you might think that your
tests succeeded when they actually failed. But fortunately, that's not
terribly likely (much as I managed to do it), and if you're using dub, it
does check the exit code.

- Jonathan M Davis



Re: New to D

2016-10-23 Thread Daniel Kozak via Digitalmars-d-learn

Dne 22.10.2016 v 11:04 Mike Parker via Digitalmars-d-learn napsal(a):


On Saturday, 22 October 2016 at 08:05:12 UTC, Daniel Kozak wrote:


uint[string] dictionary;
should be
uint[size_t] dictionary;

because size_t is 32bit on x86 system and 64bit on x86_64
and you are trying to put array length to dictionary which is size_t


I believe you meant:

size_t[string];

Yes :)


Re: [OT] fastest fibbonacci

2016-10-23 Thread Minas Mina via Digitalmars-d

On Sunday, 23 October 2016 at 13:04:30 UTC, Stefam Koch wrote:

Hi Guys,

while brushing up on my C and algorithm skills, accidently 
created a version of fibbonaci which I deem to be faster then 
the other ones floating around.


It's also more concise

the code is :

int computeFib(int n)
{
int t = 1;
int result = 0;

while(n--)
{
result = t - result;
t = t + result;
}

   return result;
}


You can even calculate Fibonacci in O(1).


Re: [OT] fastest fibbonacci

2016-10-23 Thread safety0ff via Digitalmars-d

On Sunday, 23 October 2016 at 13:04:30 UTC, Stefam Koch wrote:


created a version of fibbonaci which I deem to be faster then 
the other ones floating around.


Rosettacode is a good place to check for "floating around" 
implementations of common practice exercises e.g.:


http://rosettacode.org/wiki/Fibonacci_sequence#Matrix_Exponentiation_Version


Re: Pattern matching in D?

2016-10-23 Thread Chris M via Digitalmars-d

On Friday, 21 October 2016 at 19:00:55 UTC, Nick Sabalausky wrote:

On 10/20/2016 10:16 PM, Chris M. wrote:
So I know you can do some pattern matching with templates in 
D, but has
there been any discussion about implementing it as a language 
feature,

maybe something similar to Rust's match keyword
(https://doc.rust-lang.org/stable/book/patterns.html)? What 
would your

guys' thoughts be?



What I've been really wanting for a long time is the one-two 
combo of Nemerle's variants and pattern matching:


https://github.com/rsdn/nemerle/wiki/Grok-Variants-and-matching


There is std.variant, though I haven't used it much myself and 
don't know how well it compares. Seems like that library would 
provide a good basis for providing pattern matching though.


Re: getting started with web server - vibe.d dub giving link error

2016-10-23 Thread Karabuta via Digitalmars-d-learn

On Sunday, 23 October 2016 at 14:53:48 UTC, aman wrote:

On Saturday, 22 October 2016 at 17:23:58 UTC, Karabuta wrote:

[...]


This time i started out with a fresh Ubuntu server and followed 
instructions on the blog. Here's output. Please help:-


/usr/lib/gcc/x86_64-linux-gnu/5/include/d/core/atomic.d:1381:13: error: static assert  
"Invalid template type specified."
 static assert(0, "Invalid template type 
specified.");

 ^
../.dub/packages/vibe-d-0.7.29/source/vibe/http/server.d:1388:51: note: 
instantiated from here: atomicLoad!(cast(MemoryOrder)5, 
shared(HTTPServerContext)[])
else return cast(HTTPServerContext[])atomicLoad(g_contexts);
   ^
gdc failed with exit code 1.


I used DMD compiler for the tutorial, you are using GCC which 
might be the problem. GCC compiler seems too outdated. Try using 
DMD


Re: No trace of cumulativeFold except in the source.

2016-10-23 Thread e-y-e via Digitalmars-d-learn
On Sunday, 23 October 2016 at 10:19:07 UTC, Jonathan M Davis 
wrote:
On Sunday, October 23, 2016 10:10:40 e-y-e via 
Digitalmars-d-learn wrote:

...


Per

http://dlang.org/changelog/2.071.0.html

2.071.0 came out at the beginning of April, and 2.072 has been 
slow in coming, so we've only had point releases since then, 
and a new function would not be added with a point release. But 
yes, per the current release scheme, normally, there would have 
been a new major release by now (it is finally in beta though).


- Jonathan M Davis


On this topic, do you think a 'cumulativeSum' specialisation 
based on the 'sum' specialisation be welcome in phobos? Here's a 
quick prototype, obviously not library standard but the basic 
logic is there: 
https://gist.github.com/anonymous/4fb79b4aba79b59348273288993740cb


[Issue 16635] Alias this for implicit conversion to "ref typeof(this)" causes dmd to run endlessly

2016-10-23 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=16635

Sprink  changed:

   What|Removed |Added

   Severity|enhancement |normal

--


[Issue 16635] New: Alias this for implicit conversion to "ref typeof(this)" causes dmd to run endlessly

2016-10-23 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=16635

  Issue ID: 16635
   Summary: Alias this for implicit conversion to "ref
typeof(this)" causes dmd to run endlessly
   Product: D
   Version: D2
  Hardware: x86_64
OS: Linux
Status: NEW
  Severity: enhancement
  Priority: P1
 Component: dmd
  Assignee: nob...@puremagic.com
  Reporter: sprink.nore...@gmail.com

This code causes it to hang indefinitely it seems. I've waited a while and it
still hasn't terminated execution. Some similar code

struct Vector2
{
float x;
float y;

alias byRef this;

ref const(Vector2) byRef() const
{
return this;
}

Vector2 opBinary(string op : "+")(ref const(Vector2) a) const
{
return Vector2(x + a.x, y + a.y);
}

}


void main()
{
Vector2 a = Vector2(1, 2);
Vector2 b = Vector2(3, 4);

Vector2 c = a + b; // this line causes application to run infinitely

Vector2 d = a + Vector2(5, 6); // this line seg faults without the
above line

}

--


[Issue 16634] New: std.math exposes yl2x and yl2xp1 publicly

2016-10-23 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=16634

  Issue ID: 16634
   Summary: std.math exposes yl2x and yl2xp1 publicly
   Product: D
   Version: D2
  Hardware: All
OS: All
Status: NEW
  Severity: normal
  Priority: P1
 Component: phobos
  Assignee: nob...@puremagic.com
  Reporter: safety0ff.b...@gmail.com

import core.math;
import std.math;

void main()
{
  yl2x(1.0,1.0);
  yl2xp1(1.0,1.0);
}

Error: std.math.yl2x at /opt/compilers/dmd2/include/std/math.d(6982) conflicts
with core.math.yl2x at /opt/compilers/dmd2/include/core/math.d(149)
Error: std.math.yl2xp1 at /opt/compilers/dmd2/include/std/math.d(6983)
conflicts with core.math.yl2xp1 at /opt/compilers/dmd2/include/core/math.d(150)

There's no documentation that these functions exist in std.math, only
core.math.

--


[Issue 15862] Functions that return types with mutable indirections should be weakly pure, not strongly pure

2016-10-23 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=15862

github-bugzi...@puremagic.com changed:

   What|Removed |Added

 Status|REOPENED|RESOLVED
 Resolution|--- |FIXED

--


[Issue 15862] Functions that return types with mutable indirections should be weakly pure, not strongly pure

2016-10-23 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=15862

--- Comment #14 from github-bugzi...@puremagic.com ---
Commits pushed to master at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/4dfc9e9252220ef724412a74b3a8caf862d0a95e
fix Issue 15862 - allocating storage in pure functions should not result in
caching return values of them

https://github.com/dlang/dmd/commit/ab9d712ad6b6a2f59e1e4427bf1627968fc65c8c
Merge pull request #6197 from WalterBright/fix15862

fix Issue 15862 - allocating storage in pure functions should not res…

--


Re: [OT] fastest fibbonacci

2016-10-23 Thread Andrei Alexandrescu via Digitalmars-d

On 10/23/16 12:32 PM, Timon Gehr wrote:

It uses a general technique to speed up computation of linear recurrences


Would be awesome to factor this out of the particular algorithm. I 
recall SICP famously does that with a convergence accelerating technique 
for series. -- Andrei


[Issue 16517] topN performance very poor on certain data sets

2016-10-23 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=16517

Andrei Alexandrescu  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |FIXED

--- Comment #6 from Andrei Alexandrescu  ---
Fixed by https://github.com/dlang/phobos/pull/4815

--


Re: [OT] fastest fibbonacci

2016-10-23 Thread Timon Gehr via Digitalmars-d

On 23.10.2016 17:42, Stefam Koch wrote:

On Sunday, 23 October 2016 at 15:12:37 UTC, Timon Gehr wrote:

On 23.10.2016 15:04, Stefam Koch wrote:

Hi Guys,

while brushing up on my C and algorithm skills, accidently created a
version of fibbonaci which I deem to be faster then the other ones
floating around.

It's also more concise

the code is :

int computeFib(int n)
{
int t = 1;
int result = 0;

while(n--)
{
result = t - result;
t = t + result;
}

   return result;
}



int computeFib(int n){
int[2] a=[0,1],b=[1,2],c=[1,-1];
for(;n;n>>=1){
foreach(i;1-n&1..2){
auto d=a[i]*a[1];
a[i]=a[i]*b[1]+c[i]*a[1];
b[i]=b[i]*b[1]-d;
c[i]=c[i]*c[1]-d;
}
}
return a[0];
}

(Also: you might want to use BigInt.)


Wow, that looks intresting.
Can you explain how it computes fibbonacci ?


It uses a general technique to speed up computation of linear 
recurrences, with a few additional optimizations. One iteration of your 
while loop multiplies the vector (result,t) by a matrix. I exponentiate 
this matrix using a logarithmic instead of a linear number of operations.


Re: [OT] fastest fibbonacci

2016-10-23 Thread Stefam Koch via Digitalmars-d

On Sunday, 23 October 2016 at 15:12:37 UTC, Timon Gehr wrote:

On 23.10.2016 15:04, Stefam Koch wrote:

Hi Guys,

while brushing up on my C and algorithm skills, accidently 
created a
version of fibbonaci which I deem to be faster then the other 
ones

floating around.

It's also more concise

the code is :

int computeFib(int n)
{
int t = 1;
int result = 0;

while(n--)
{
result = t - result;
t = t + result;
}

   return result;
}



int computeFib(int n){
int[2] a=[0,1],b=[1,2],c=[1,-1];
for(;n;n>>=1){
foreach(i;1-n&1..2){
auto d=a[i]*a[1];
a[i]=a[i]*b[1]+c[i]*a[1];
b[i]=b[i]*b[1]-d;
c[i]=c[i]*c[1]-d;
}
}
return a[0];
}

(Also: you might want to use BigInt.)


Wow, that looks intresting.
Can you explain how it computes fibbonacci ?


Re: [OT] fastest fibbonacci

2016-10-23 Thread Timon Gehr via Digitalmars-d

On 23.10.2016 15:04, Stefam Koch wrote:

Hi Guys,

while brushing up on my C and algorithm skills, accidently created a
version of fibbonaci which I deem to be faster then the other ones
floating around.

It's also more concise

the code is :

int computeFib(int n)
{
int t = 1;
int result = 0;

while(n--)
{
result = t - result;
t = t + result;
}

   return result;
}



int computeFib(int n){
int[2] a=[0,1],b=[1,2],c=[1,-1];
for(;n;n>>=1){
foreach(i;1-n&1..2){
auto d=a[i]*a[1];
a[i]=a[i]*b[1]+c[i]*a[1];
b[i]=b[i]*b[1]-d;
c[i]=c[i]*c[1]-d;
}
}
return a[0];
}

(Also: you might want to use BigInt.)


[Issue 16625] [Reg 2.072] new and previously undeprecated switch case fallthrough error

2016-10-23 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=16625

--- Comment #2 from github-bugzi...@puremagic.com ---
Commits pushed to stable at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/d8075dc0581ae1da6e27762689a2d902f4c0947e
fix Issue 16625 - undeprecated switch fallthrough error

https://github.com/dlang/dmd/commit/2ef22724b26c36e10df6771f80ba7d16e4380fe0
Merge pull request #6206 from MartinNowak/fix16625

fix Issue 16625 - undeprecated switch fallthrough error

--


Using a specific version of DMD in Travic CI fails

2016-10-23 Thread Jacob Carlborg via Digitalmars-d

Posting here as well to get some more eyes on the issue.

https://github.com/travis-ci/travis-ci/issues/6770

--
/Jacob Carlborg


Re: getting started with web server - vibe.d dub giving link error

2016-10-23 Thread aman via Digitalmars-d-learn

On Saturday, 22 October 2016 at 17:23:58 UTC, Karabuta wrote:

On Saturday, 22 October 2016 at 17:21:45 UTC, Karabuta wrote:

On Saturday, 22 October 2016 at 14:50:14 UTC, aman wrote:


I just started on vibe.d on fedora and the experience is not 
pretty getting hello-world running. Please help. Below are 
the details.


[...]


I wrote a blog post at https://aberba.gtihub.io which has 
Fedora users covered. But somehow GitHub pages is not working 
so you can find it here too 
https://github.com/aberba/aberba.github.io/blob/master/_posts/2016-08-20-hello-world-app-with-the-vibe.d-web-framework.md


Sorry for the typo, blog link is rather 
https://aberba.github.io/#blog


This time i started out with a fresh Ubuntu server and followed 
instructions on the blog. Here's output. Please help:-


/usr/lib/gcc/x86_64-linux-gnu/5/include/d/core/atomic.d:1381:13: 
error: static assert  "Invalid template type specified."

 static assert(0, "Invalid template type specified.");
 ^
../.dub/packages/vibe-d-0.7.29/source/vibe/http/server.d:1388:51: 
note: instantiated from here: atomicLoad!(cast(MemoryOrder)5, 
shared(HTTPServerContext)[])

else return cast(HTTPServerContext[])atomicLoad(g_contexts);
   ^
gdc failed with exit code 1.



[OT] fastest fibbonacci

2016-10-23 Thread Stefam Koch via Digitalmars-d

Hi Guys,

while brushing up on my C and algorithm skills, accidently 
created a version of fibbonaci which I deem to be faster then the 
other ones floating around.


It's also more concise

the code is :

int computeFib(int n)
{
int t = 1;
int result = 0;

while(n--)
{
result = t - result;
t = t + result;
}

   return result;
}



Re: "for" statement issue

2016-10-23 Thread Nick Treleaven via Digitalmars-d

On Saturday, 22 October 2016 at 17:11:26 UTC, ag0aep6g wrote:
How is it guaranteed that `a` doesn't have side effects? May be 
a function call, since empty parentheses can be omitted in 
calls.


I missed that case. (Insert grumble about non-UFCS parenthesis 
omission being allowed).



The lambda itself is a value, no?


int a() { import std.stdio; writeln("a"); return 1; }

void main()
{
int delegate(int) dg = (a, b => a + b);
}


OK. Though AIUI from 2.072 a() must return void for the comma 
expression to compile (then a+b wouldn't compile either).


Re: why std.stdio.File is a struct?

2016-10-23 Thread Namespace via Digitalmars-d
On Sunday, 23 October 2016 at 06:36:21 UTC, Jonathan M Davis 
wrote:
You can mark a parameter as ref, and you get something similar 
to C++'s &, except that it only works on parameters, return 
types, and the variable for the current element in a foreach 
loop (you can't declare local variables that are ref), and ref 
parameters only ever accept lvalues, even if they're const. e.g.


void foo(ref int i) {...}

ref int bar() { return _i; }

foreach(i, ref e; arr) {...}

I think that most D code just passes structs around without 
worrying about the cost of copying unless the struct is 
particularly large or profiling has shown that copying it is 
too expensive. For a lot of stuff, it simply isn't a problem. 
And when it is, there's ref, or the struct can be put on the 
heap and passed around by pointer. But because we don't have an 
equivalent for const& that accepts rvalues, using ref simply to 
avoid copying can get annoying. So, it doesn't make much sense 
to do it unless it's actually necessary (whereas a lot of C++ 
code does it just in case it matters).


There is talk of possibly adding a way to pass rvalues by ref 
in D, in which case, you would get something similar to C++ 
const&, but there are problems caused by C++'s approach that we 
don't want in D, and D's const is enough more restrictive than 
C++ const that whatever we do can't be tied to const.


- Jonathan M Davis


There is still the way to use an universal rvalue => lvalue 
conversion function.


Re: No trace of cumulativeFold except in the source.

2016-10-23 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, October 23, 2016 10:10:40 e-y-e via Digitalmars-d-learn wrote:
> On Sunday, 23 October 2016 at 09:11:08 UTC, Jonathan M Davis
>
> wrote:
> > On Sunday, October 23, 2016 07:46:19 e-y-e via
> >
> > Digitalmars-d-learn wrote:
> >> ...
> >
> > It's not a bug. It's just too new. You looked at the master
> > branch on github, whereas what you're probably using on your
> > computer is 2.071.2, which does not have cumulativeFold,
> > because it was added at some point after 2.071.2.
> >
> > - Jonathan M Davis
>
> Ok, that checks out. I looked at the commit and it was in April
> so I just assumed it would be in the release by now.

Per

http://dlang.org/changelog/2.071.0.html

2.071.0 came out at the beginning of April, and 2.072 has been slow in
coming, so we've only had point releases since then, and a new function
would not be added with a point release. But yes, per the current release
scheme, normally, there would have been a new major release by now (it is
finally in beta though).

- Jonathan M Davis



Re: No trace of cumulativeFold except in the source.

2016-10-23 Thread e-y-e via Digitalmars-d-learn
On Sunday, 23 October 2016 at 09:11:08 UTC, Jonathan M Davis 
wrote:
On Sunday, October 23, 2016 07:46:19 e-y-e via 
Digitalmars-d-learn wrote:

...


It's not a bug. It's just too new. You looked at the master 
branch on github, whereas what you're probably using on your 
computer is 2.071.2, which does not have cumulativeFold, 
because it was added at some point after 2.071.2.


- Jonathan M Davis


Ok, that checks out. I looked at the commit and it was in April 
so I just assumed it would be in the release by now.


Re: No trace of cumulativeFold except in the source.

2016-10-23 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, October 23, 2016 07:46:19 e-y-e via Digitalmars-d-learn wrote:
> Recently I needed to use a cumulative sum function, so I looked
> in phobos' documentation for 'cumulative' but found nothing
> useful. Then I looked in the forums for it and found nothing
> useful. But when I searched phobos for it I found cumulativeFold
> in std.algorithm.iteration:
> https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d#L312
> 7. So I tried this:
>
> auto cumulativeSum(Range)(Range r)
> {
>  import std.algorithm.iteration : cumulativeFold;
>
>  return r.cumulativeFold!((a, b) => a +b);
> }
>
> but when I run it I get 'Error: module std.algorithm.iteration
> import 'cumulativeFold' not found'. Anyone can reproduce this?
> looking at the source I can't see how it could possibly occur but
> it is certainly a bug right?

It's not a bug. It's just too new. You looked at the master branch on
github, whereas what you're probably using on your computer is 2.071.2,
which does not have cumulativeFold, because it was added at some point after
2.071.2.

- Jonathan M Davis



get regex string pattern from regex object

2016-10-23 Thread aman via Digitalmars-d

How can I get the string regex pattern from a regex object?
I tried this and obviously didn't work.

my expected output would be "hello hi".i.e. the string used to 
create the regex in the first place.


static rx = ctRegex!`hello hi`;
void main()
{
writeln(to!(string)(rx));
}


Re: getting started with web server - vibe.d dub giving link error

2016-10-23 Thread aman via Digitalmars-d-learn

On Saturday, 22 October 2016 at 17:23:58 UTC, Karabuta wrote:

On Saturday, 22 October 2016 at 17:21:45 UTC, Karabuta wrote:

On Saturday, 22 October 2016 at 14:50:14 UTC, aman wrote:


I just started on vibe.d on fedora and the experience is not 
pretty getting hello-world running. Please help. Below are 
the details.


[...]


I wrote a blog post at https://aberba.gtihub.io which has 
Fedora users covered. But somehow GitHub pages is not working 
so you can find it here too 
https://github.com/aberba/aberba.github.io/blob/master/_posts/2016-08-20-hello-world-app-with-the-vibe.d-web-framework.md


Sorry for the typo, blog link is rather 
https://aberba.github.io/#blog


Hi, still no progress. It seems to be accessing some sha module 
and then not finding symbols.
I also tried cgi.d and that also wont work ia a "hello world" 
friendly way.


No trace of cumulativeFold except in the source.

2016-10-23 Thread e-y-e via Digitalmars-d-learn
Recently I needed to use a cumulative sum function, so I looked 
in phobos' documentation for 'cumulative' but found nothing 
useful. Then I looked in the forums for it and found nothing 
useful. But when I searched phobos for it I found cumulativeFold 
in std.algorithm.iteration: 
https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d#L3127. So I tried this:


auto cumulativeSum(Range)(Range r)
{
import std.algorithm.iteration : cumulativeFold;

return r.cumulativeFold!((a, b) => a +b);
}

but when I run it I get 'Error: module std.algorithm.iteration 
import 'cumulativeFold' not found'. Anyone can reproduce this? 
looking at the source I can't see how it could possibly occur but 
it is certainly a bug right?


Re: why std.stdio.File is a struct?

2016-10-23 Thread Jonathan M Davis via Digitalmars-d
On Sunday, October 23, 2016 06:13:29 lumpyzhu via Digitalmars-d wrote:
> thanks..
> but structs are copy by value,
> In C++, I can use reference to avoid value-copy,
>
> --
> class MyClass {};
> void myFunc(const MyClass& a, MyClass& b) {...};
>
> {
>MyClass object;
>myFunc(object);
>// f will destroyed here.
> }
> --
> in c++, I know where the object is destroyed..
> but how to convert this c++ code to d?

You can mark a parameter as ref, and you get something similar to C++'s &,
except that it only works on parameters, return types, and the variable for
the current element in a foreach loop (you can't declare local variables
that are ref), and ref parameters only ever accept lvalues, even if they're
const. e.g.

void foo(ref int i) {...}

ref int bar() { return _i; }

foreach(i, ref e; arr) {...}

I think that most D code just passes structs around without worrying about
the cost of copying unless the struct is particularly large or profiling has
shown that copying it is too expensive. For a lot of stuff, it simply isn't
a problem. And when it is, there's ref, or the struct can be put on the heap
and passed around by pointer. But because we don't have an equivalent for
const& that accepts rvalues, using ref simply to avoid copying can get
annoying. So, it doesn't make much sense to do it unless it's actually
necessary (whereas a lot of C++ code does it just in case it matters).

There is talk of possibly adding a way to pass rvalues by ref in D, in which
case, you would get something similar to C++ const&, but there are problems
caused by C++'s approach that we don't want in D, and D's const is enough
more restrictive than C++ const that whatever we do can't be tied to const.

- Jonathan M Davis



Re: why std.stdio.File is a struct?

2016-10-23 Thread lumpyzhu via Digitalmars-d
On Thursday, 20 October 2016 at 07:40:05 UTC, Jonathan M Davis 
wrote:
On Thursday, October 20, 2016 06:59:12 lumpyzhu via 
Digitalmars-d wrote:

std.stdio.File has reference counter inside,
why not std.stdio.File is class?


By using a struct with a reference count, you get deterministic 
destruction, and the file will be closed as soon as the 
reference count hits zero. If it were a class, then it would 
only be closed when the GC happened to collect the memory, and 
there's no guarantee that it will _ever_ collect the memory 
(e.g. the GC normally only runs when you call new, so if you 
never allocate memory again after allocating the File, then the 
GC will never collect it even if nothing refers to it anymore).


User-defined types that manage system resources are pretty much 
always better off as structs so that they can have 
deterministic destruction. Java and C# have a terrible time 
with stuff like closing files, essentially requiring you to do 
it manually, because there's no guarantee that the finalizers 
for their file classes will ever run, and you risk the resource 
never being released until the program terminates, which can be 
a big problem. We'd have the same problem if we used a class 
for std.stdio.File, whereas using a struct works great.


In general, in D, if you don't need inheritance and 
polymorphism, you probably shouldn't be using a class.


- Jonathan M Davis



thanks..
but structs are copy by value,
In C++, I can use reference to avoid value-copy,

--
class MyClass {};
void myFunc(const MyClass& a, MyClass& b) {...};

{
  MyClass object;
  myFunc(object);
  // f will destroyed here.
}
--
in c++, I know where the object is destroyed..
but how to convert this c++ code to d?