Re: Cannot deduce function types for argument

2018-02-25 Thread ARaspiK via Digitalmars-d-learn

On Sunday, 25 February 2018 at 18:39:31 UTC, ARaspiK wrote:
I'm making a calendar (basically improvements to 
https://wiki.dlang.org/Component_programming_with_ranges) and 
I'm getting a lot of `cannot deduce function from argument 
types` errors when using range-based mapping code.

Here's my current code: https://pastebin.com/TqAkggEw
My testing: `rdmd --eval='import calendar; dateList!(a => 
a.year > 2013)(2013).chunkBy!myMonth.chunks(3).map!(r => 
r.map!formatMonth.array().blockMonths(" 
").join("\n")).join("\n\n").writeln();'`


[...]


I figured it out. I had passed incorrect parameters, and it works 
now. Thanks for reading.


Re: Zip with range of ranges

2018-02-25 Thread ARaspiK via Digitalmars-d-learn

On Sunday, 25 February 2018 at 20:18:27 UTC, Paul Backus wrote:

On Sunday, 25 February 2018 at 16:22:19 UTC, ARaspiK wrote:
Instead of passing std.range.zip a set of ranges as different 
arguments, is it possible to hand the m a range of ranges, and 
get them to zip together each element of every subrange?


`std.range.transposed` does this, but it requires that the 
range of ranges has assignable elements, so it may not work in 
all cases. For example:


import std.range;
import std.algorithm.iteration;
import std.stdio;

auto rr1 = [[1, 2, 3], [4, 5, 6]];
rr1.transposed.each!writeln; // Works

auto rr2 = only(only(1, 2, 3), only(4, 5, 6));
rr2.transposed.each!writeln; // Doesn't work


Thank you so much. It works now. I was already receiving a 
forward range, so copying was easy.


Re: Help using lubeck on Windows

2018-02-25 Thread jmh530 via Digitalmars-d-learn

On Sunday, 25 February 2018 at 14:25:04 UTC, Arredondo wrote:

On Friday, 23 February 2018 at 16:56:13 UTC, jmh530 wrote:
I had given up and used WSL at this point rather than compile 
it myself with CMAKE. Less of a headache.


I don’t understand. Wouldn’t WSL produce Linux binaries? I need 
my project compiled as a Windows .exe, other parts of my 
development environment depend on that.


Usually what I need is to do some calculation and print the 
results in the console or write them to a file, so it's fine for 
me. If you need an exe, then I guess WSL wouldn't be for you.


Re: Game and GC

2018-02-25 Thread Leonardo via Digitalmars-d-learn
On Saturday, 24 February 2018 at 07:12:21 UTC, Guillaume Piolat 
wrote:

From my experience a combination of the following is necessary:
- not having the audio thread registered
- using pools aggressively for game entities


I'll read the resources you gave.
Thanks for the all answers. Great community here.


Re: iota to array

2018-02-25 Thread Harry via Digitalmars-d-learn
On Sunday, 25 February 2018 at 13:33:07 UTC, psychoticRabbit 
wrote:
On Sunday, 25 February 2018 at 12:13:31 UTC, Andrea Fontana 
wrote:
On Sunday, 25 February 2018 at 09:30:12 UTC, psychoticRabbit 
wrote:

I would have preffered it defaulted java style ;-)

System.out.println(1.0); // i.e. it prints 'what I told it to 
print'.


System.out.println(1.0); // print 1.0
System.out.println(1.0); // print 1.0

So it doesn't print "what you told it to print"

Andrea Fontana


can someone please design a language that does what I tell it!

please!!

is that so hard??

print 1.0 does not mean go and print 1 .. it means go and print 
1.0


languages are too much like people.. always thinking for 
themselves.


I fed up!

fed up I say!


Don't worry little rabbit 1 == 1.0 so it is OK.


Re: Forward references

2018-02-25 Thread Steven Schveighoffer via Digitalmars-d-learn

On 2/25/18 6:53 PM, Jiyan wrote:

On Sunday, 25 February 2018 at 22:20:13 UTC, Steven Schveighoffer wrote:

On 2/25/18 4:25 PM, Jiyan wrote:

[...]


Looks like this was fixed in 2.064.

What version of the compiler are you using?

-Steve


2.077.0

It is really strange, it works now but there still seems to be some 
strangeness about forward references.


There are frequently issues with forward references. They are supposed 
to always work, but it's not always the case.


-Steve


Re: Searching string for character in binary search

2018-02-25 Thread Joel via Digitalmars-d-learn

On Sunday, 25 February 2018 at 21:18:55 UTC, Joel wrote:

The number tests work, but not the string one.


Thanks guys. I worked it out, I thought my search code was right, 
since the first asserts worked.





Re: countUntil to print all the index of a given string.

2018-02-25 Thread Andrew via Digitalmars-d-learn

On Sunday, 25 February 2018 at 13:25:56 UTC, Vino wrote:
On Sunday, 25 February 2018 at 03:41:27 UTC, Jonathan M Davis 
wrote:
On Sunday, February 25, 2018 02:58:33 Seb via 
Digitalmars-d-learn wrote:

[...]


That will help eventually, but it requires a compiler flag, so 
it's really not going to help for code in general right now, 
and the fact that that DIP does nothing to solve the problem 
of how to create exception messages without allocating them on 
the GC heap means that exceptions in general are still 
frequently going to result in allocations unless you jump 
through several hoops to be able to create an exception 
message that's in a static array or malloc-ed or something. 
So, I don't know how much it's going to help in practice 
outside of code where the programmer is absolutely determined 
to have no GC allocations.



[...]


Yeah. There does tend to be a correlation between @nogc and 
whether a range is lazy, but it's not guaranteed, so I'm 
inclined to think that it's a poor idea to rely on it and that 
it's just ultimately better to look at the documentation or 
even the code.


- Jonathan M Davis


Hi All,

  Sorry, I am not able to see any correlation between the 
raised topic and the conversation that is happening in this 
forum, could any one please explain on of what is going on and 
how do you thing that this conversation is related to the topic 
raised, if not would suggest you to open a new topic.


From,
Vino.B


I think this will work:

import std.container;
import std.algorithm;
import std.range;
import std.stdio;

void main () {
auto a = Array!string("Test1", "Test2", "Test3", "Test1", 
"Test2");

auto b = Array!string("Test1", "Test2", "Test3");
foreach(i; b[])
  a[].enumerate.filter!(a => a[1] == i).map!(a => 
a[0]).SList!size_t[].writeln;


Re: Forward references

2018-02-25 Thread Jiyan via Digitalmars-d-learn
On Sunday, 25 February 2018 at 22:20:13 UTC, Steven Schveighoffer 
wrote:

On 2/25/18 4:25 PM, Jiyan wrote:

[...]


Looks like this was fixed in 2.064.

What version of the compiler are you using?

-Steve


2.077.0

It is really strange, it works now but there still seems to be 
some strangeness about forward references.


Thanks till now i guess :P


Re: Forward references

2018-02-25 Thread Steven Schveighoffer via Digitalmars-d-learn

On 2/25/18 4:25 PM, Jiyan wrote:

Hi,
is there any document or text describing forward references?
It is kinda strange, i implemented a list structure which is kinda like 
this:


struct list(T)
{
private:

struct node
{
T val;
node* next;
node* prev;
}

node* head;
node* last;
size_t size;

  .
}

The thing is when i implement following struct:

struct Tre
{
list!Tre a;
}

theoretically it should be constructable. But it gives me out a compiler 
error about Forward reference. Ok maybe the compiler at this point cant 
do that but ...


The strange thing is i somehow managed earlier without knowing to do 
exactly this in a much more complicated struct.

Can somebody enlighten me about this?


Looks like this was fixed in 2.064.

What version of the compiler are you using?

-Steve


Re: Searching string for character in binary search

2018-02-25 Thread Steven Schveighoffer via Digitalmars-d-learn

On 2/25/18 4:32 PM, Seb wrote:


Also note that Phobos comes with binary search built-in:

---
assert([1,2,3,4,5,6,7,8,9,10,11].assumeSorted.canFind(6));
---

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


canFind (and find) works even on non-sorted ranges, so it's not the 
greatest proof. But it's good to know that it does work and uses a 
binary search!


You can see that it only does a few comparisons with something like:

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

Also, strings are not doing what you think:

"abcd".find('c'); // OK, linear search
"abcd".assumeSorted.find('c'); // Error
"abcd".assumeSorted.find("c"); // OK, but does NOT do a binary search!
[1,2,3,4].assumeSorted.find([3]); // OK, but also does not do a binary 
search!


My knee-jerk reaction is to blame auto-decoding ;) But maybe it's just a 
bug.


If you want to guarantee a binary search (i.e. compiler error when it 
cannot do it), you need to use SortedRange.lowerBound.


-Steve


Re: Forward references

2018-02-25 Thread ketmar via Digitalmars-d-learn

works for me with 2.076.


Re: Destructor called twice.

2018-02-25 Thread ketmar via Digitalmars-d-learn

add postblit debug prints, and you will see.


Re: Searching string for character in binary search

2018-02-25 Thread Seb via Digitalmars-d-learn

On Sunday, 25 February 2018 at 21:18:55 UTC, Joel wrote:

The number tests work, but not the string one.

void main() {
assert([1,2,3,4,5,6,7,8,9,10,11].binarySearch(6));
assert(! [1,2,3,4,5,7,8,9,10,11].binarySearch(6));
assert("abcdefghijklmnopqrstuvwxyz".binarySearch('j')); // not 
work

import std.stdio;
writeln("Assert tests passed!");
}

bool binarySearch(T)(T[] arr, T n) {
while(arr.length) {
auto i = arr.length/2;
if (arr[i] == n)
return true;
else
if (arr[i]  > n)
arr = arr[i + 1 .. $];
else
arr = arr[0 .. i];
}
return false;
}




Your cases are wrong:

---
if (arr[i]  > n) // 'n' > 'j'
// The current element is higher than the needle -> you need to 
go to the left, not right

--


-> Swap them.


Also note that Phobos comes with binary search built-in:

---
assert([1,2,3,4,5,6,7,8,9,10,11].assumeSorted.canFind(6));
---

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


Forward references

2018-02-25 Thread Jiyan via Digitalmars-d-learn

Hi,
is there any document or text describing forward references?
It is kinda strange, i implemented a list structure which is 
kinda like this:


struct list(T)
{
private:

struct node
{
T val;
node* next;
node* prev;
}

node* head;
node* last;
size_t size;

 .
}

The thing is when i implement following struct:

struct Tre
{
list!Tre a;
}

theoretically it should be constructable. But it gives me out a 
compiler error about Forward reference. Ok maybe the compiler at 
this point cant do that but ...


The strange thing is i somehow managed earlier without knowing to 
do exactly this in a much more complicated struct.

Can somebody enlighten me about this?







Re: Searching string for character in binary search

2018-02-25 Thread ag0aep6g via Digitalmars-d-learn

On 02/25/2018 10:18 PM, Joel wrote:

     if (arr[i]  > n)
     arr = arr[i + 1 .. $];


When `arr[i]` is greater than `n`, then the values in `arr[i + 1 .. $]` 
will only be even greater. You're picking the wrong half of the array.


Searching string for character in binary search

2018-02-25 Thread Joel via Digitalmars-d-learn

The number tests work, but not the string one.

void main() {
assert([1,2,3,4,5,6,7,8,9,10,11].binarySearch(6));
assert(! [1,2,3,4,5,7,8,9,10,11].binarySearch(6));
assert("abcdefghijklmnopqrstuvwxyz".binarySearch('j')); // not 
work

import std.stdio;
writeln("Assert tests passed!");
}

bool binarySearch(T)(T[] arr, T n) {
while(arr.length) {
auto i = arr.length/2;
if (arr[i] == n)
return true;
else
if (arr[i]  > n)
arr = arr[i + 1 .. $];
else
arr = arr[0 .. i];
}
return false;
}


Destructor called twice.

2018-02-25 Thread TheFlyingFiddle via Digitalmars-d-learn
When writing some code to setup properties in a chain function 
manner I ran into some unexpected behavior with destructors.


Example:

struct S {
int a, b;

ref S foo(int b) {
this.b = b;
return this;
}

this(int ab) {
this.a = this.b = ab;
printf("ctor a=%d, b=%d\n", a, b);
}

~this() {
printf("dtor a=%d b=%d\n", a, b);
}


}

void main()
{
auto s0 = S(0).foo(1);
auto s1 = S(1).foo(2).foo(3).foo(4);
auto s2 = S(2);
s2.foo(5).foo(6).foo(7);
}

//Output is
ctor 0
dtor 0 1
ctor 1
dtor 1 4
ctor a=2, b=2
dtor a=2 b=7
dtor 1 4
dtor 0 1


For s0,s1 the destructor is called twice but s2 works as I would 
expect.


Taking a look with dmd -vcg-ast provided this:
void main()
{
S s0 = ((S __slS3 = S(, );) , __slS3).this(0).foo(1);
try
{
	S s1 = ((S __slS4 = S(, );) , 
__slS4).this(1).foo(2).foo(3).foo(4);

try
{
S s2 = s2 = S , s2.this(2);
try
{
s2.foo(5).foo(6).foo(7);
}
finally
s2.~this();
}
finally
s1.~this();
}
finally
s0.~this();
return 0;
}

The two extra dtor calls are not visible here but I guess they 
are caused by the temporary variables that are created and then 
go out of scope directly. Am I doing something wrong or is this a 
bug?






Re: Zip with range of ranges

2018-02-25 Thread Paul Backus via Digitalmars-d-learn

On Sunday, 25 February 2018 at 16:22:19 UTC, ARaspiK wrote:
Instead of passing std.range.zip a set of ranges as different 
arguments, is it possible to hand the m a range of ranges, and 
get them to zip together each element of every subrange?


`std.range.transposed` does this, but it requires that the range 
of ranges has assignable elements, so it may not work in all 
cases. For example:


import std.range;
import std.algorithm.iteration;
import std.stdio;

auto rr1 = [[1, 2, 3], [4, 5, 6]];
rr1.transposed.each!writeln; // Works

auto rr2 = only(only(1, 2, 3), only(4, 5, 6));
rr2.transposed.each!writeln; // Doesn't work


Cannot deduce function types for argument

2018-02-25 Thread ARaspiK via Digitalmars-d-learn
I'm making a calendar (basically improvements to 
https://wiki.dlang.org/Component_programming_with_ranges) and I'm 
getting a lot of `cannot deduce function from argument types` 
errors when using range-based mapping code.

Here's my current code: https://pastebin.com/TqAkggEw
My testing: `rdmd --eval='import calendar; dateList!(a => a.year 
> 2013)(2013).chunkBy!myMonth.chunks(3).map!(r => 
r.map!formatMonth.array().blockMonths(" 
").join("\n")).join("\n\n").writeln();'`


My errors:
```
template std.array.array cannot deduce function from argument 
types !()(MapResult!(formatMonth, Take!(ChunkByImpl!(myMonth, 
Until!(__lambda2, Recurrence!(__lambda2, Date, 1LU), void), 
candidates are:
std.array.array(Range)(Range r) if (isIterable!Range && 
!isNarrowString!Range && !isInfinite!Range)
std.array.array(Range)(Range r) if (isPointer!Range && 
isIterable!(PointerTarget!Range) && !isNarrowString!Range && 
!isInfinite!Range)
std.array.array(String)(scope String str) if 
(isNarrowString!String)
 instantiated from here: MapResult!(__lambda3, 
Chunks!(ChunkByImpl!(myMonth, Until!(__lambda2, 
Recurrence!(__lambda2, Date, 1LU), void
 instantiated from here: map!(Chunks!(ChunkByImpl!(myMonth, 
Until!(__lambda2, Recurrence!(__lambda2, Date, 1LU), void

```

Please, can you get this code to work?
The commented out function formatYear needs to work properly. The 
rdmd command-line simply emulates it.


Re: How to compile C++ and D code, and linking them together on Windows,I will use c++ function In D? Thanks.

2018-02-25 Thread FrankLike via Digitalmars-d-learn

On Sunday, 25 February 2018 at 15:38:31 UTC, FrankLike wrote:

Hi,everyone,

How to compile C++ and D code, and  linking them together  on 
Windows ? I will use c++ function In D.

I use vs2010 c++ on Windows, What should I do?
For example:

1. create 2 files: C++.cpp  D.d
2. I get the C++.obj fiel by vs2010.
3. I get the D.obj by dmd -c -m32mscoff

Then how to link? use Dmd's link or VC's link?
Now I use the VC's link,and dmd -c -m32mscoff.but get the 
error:phobos32mscoff.lib<...>:error LNK2001

Total 187 errors.

Thanks.


I've done it by myself.

Through ‘LINK’ each *.obj from D or C++,if there is no 
problem,linking them together,add 
parameters:/NODEFAULTLIB:libcmt.lib ,and not use /LTCG.


Ok.




Zip with range of ranges

2018-02-25 Thread ARaspiK via Digitalmars-d-learn
Instead of passing std.range.zip a set of ranges as different 
arguments, is it possible to hand the m a range of ranges, and 
get them to zip together each element of every subrange?


Re: Help using lubeck on Windows

2018-02-25 Thread FrankLike via Digitalmars-d-learn

On Sunday, 25 February 2018 at 14:26:24 UTC, Arredondo wrote:
On Friday, 23 February 2018 at 18:29:09 UTC, Ilya Yaroshenko 
wrote:



full days now. All the .lib/.a files I have tried for BLAS and

 to do:  dmd -L .\openblas.lib
 put the lib file in your code path.


Error 42: Symbol Undefined _cblas_dgemm
Error 42: Symbol Undefined _cblas_dger
Error: linker exited with status 2






Re: Vibe.d no more using static this() {}

2018-02-25 Thread aberba via Digitalmars-d-learn

On Sunday, 25 February 2018 at 01:15:06 UTC, Seb wrote:

On Friday, 23 February 2018 at 23:11:13 UTC, aberba wrote:
I recently noticed vibe.d now using main loop which call the 
vibe.d event loop.


"Recently"?
FWIW this has been phased out a long time ago ;-)
That's how I've been doing it 
http://aberba.com/2016/form-upload-in-vibe-d/


---

0.7.23 (2015)

Definition of either VibeCustomMain or VibeDefaultMain is now 
a hard requirement - this is the final deprecation phase for 
VibeCustomMain


https://github.com/vibe-d/vibe.d/blob/master/CHANGELOG.md#features-and-improvements-10

Added a compile time warning when neither VibeCustomMain, nor 
VibeDefaultMain versions are specified - starts the transition 
from VibeCustomMain to VibeDefaultMain


https://github.com/vibe-d/vibe.d/blob/master/CHANGELOG.md#features-and-improvements-14


0.7.30 (2016)

Added runApplication as a single API entry point to properly 
initialize and run a vibe.d application (this will serve as 
the basis for slowly phasing out the VibeDefaultMain 
convenience mechanism)


https://github.com/vibe-d/vibe.d/blob/master/CHANGELOG.md#features-and-improvements-4


I should take these changelogs seriously and read into details.


---



Why that change?


In short, because there are too many problems with starting the 
eventloop by default without stating so and requiring the user 
to know what's going on. I don't know all the reasons, but one 
example that comes to my mind is that if you use Vibe.d for a 
simple curl-like script, you might be wondering why it never 
exits.
Also you mention `static this` in your title, but usually 
`shared static this` should be used.

Oh. I've been using "static this". Noted.



There are also other concerns, e.g. the @safe-ty of the 
eventloop is never checked when you use the default main method.



Hence, in 2014 VibeDefaultMain was introduced to move away 
VibeCustomMain (which required the user to take explicit action 
when the eventloop shouldn't run).


Nowadays, a user neds to choose whether to use the default main 
loop (versions "VibeDefaultMain") or call 
runEventLoop/runApplication, but "VibeDefaultMain" with shared 
static this is deprecated.


static this seemed clean though :)



How to compile C++ and D code, and linking them together on Windows, I will use c++ function In D? Thanks.

2018-02-25 Thread FrankLike via Digitalmars-d-learn

Hi,everyone,

How to compile C++ and D code, and  linking them together  on 
Windows ? I will use c++ function In D.

I use vs2010 c++ on Windows, What should I do?
For example:

1. create 2 files: C++.cpp  D.d
2. I get the C++.obj fiel by vs2010.
3. I get the D.obj by dmd -c -m32mscoff

Then how to link? use Dmd's link or VC's link?
Now I use the VC's link,and dmd -c -m32mscoff.but get the 
error:phobos32mscoff.lib<...>:error LNK2001

Total 187 errors.

Thanks.




Re: iota to array

2018-02-25 Thread rumbu via Digitalmars-d-learn
On Sunday, 25 February 2018 at 13:33:07 UTC, psychoticRabbit 
wrote:

can someone please design a language that does what I tell it!

please!!

is that so hard??

print 1.0 does not mean go and print 1 .. it means go and print 
1.0


languages are too much like people.. always thinking for 
themselves.


I fed up!

fed up I say!


That's in fact a data representation problem not a language 
problem. In C#, if you are using a *decimal* data type, it prints 
as expected:


decimal one = 1m;   //internally represented as 10^^0
decimal one2 = 1.0m;//internally represented as 10^^-1
decimal one3 = 1.00m;   //internally represented as 100^^-2
//one == one2 == one3, but the output is different:
Console.WriteLine(one);  //outputs 1
Console.WriteLine(one2); //outputs 1.0
Console.WriteLine(one3); //outputs 1.00

Nor Java and nor D have any built-in decimal type, therefore the 
internal representation of floating point values is always double 
(or float, or real). Double has a unique representation for 1, 
1.0 or 1.00 and it's always 2^^0. How the writeln/println 
functions outputs 2^0, it's a design decision. Since D is 
inheriting C concepts (including printf), it will use the %g 
format as in C. I'm not a Java fan, therefore I don't know what 
was behind the decision of the language creators to output 
floating point values with at least one decimal digit.


Re: iota to array

2018-02-25 Thread Steven Schveighoffer via Digitalmars-d-learn

On 2/25/18 8:33 AM, psychoticRabbit wrote:

On Sunday, 25 February 2018 at 12:13:31 UTC, Andrea Fontana wrote:

On Sunday, 25 February 2018 at 09:30:12 UTC, psychoticRabbit wrote:

I would have preffered it defaulted java style ;-)

System.out.println(1.0); // i.e. it prints 'what I told it to print'.


System.out.println(1.0); // print 1.0
System.out.println(1.0); // print 1.0

So it doesn't print "what you told it to print"

Andrea Fontana


can someone please design a language that does what I tell it!

please!!

is that so hard??

print 1.0 does not mean go and print 1 .. it means go and print 1.0



1 == 1.0, no?

You are printing a value, which means it has to go through a conversion 
from the value to a string (i.e. printable). writefln has no idea what 
you wrote as a literal, it just sees the value 1 (as a double). I hope 
we never make a distinction here!


If you want to tell it EXACTLY what to print, print a string:

writeln("1.0");

-Steve


Re: Help using lubeck on Windows

2018-02-25 Thread Arredondo via Digitalmars-d-learn

On Friday, 23 February 2018 at 16:56:13 UTC, jmh530 wrote:
I had given up and used WSL at this point rather than compile 
it myself with CMAKE. Less of a headache.


I don’t understand. Wouldn’t WSL produce Linux binaries? I need 
my project compiled as a Windows .exe, other parts of my 
development environment depend on that.


Re: Help using lubeck on Windows

2018-02-25 Thread Arredondo via Digitalmars-d-learn
On Friday, 23 February 2018 at 18:29:09 UTC, Ilya Yaroshenko 
wrote:
openblas.net contains precompiled openblas library for Windows. 
It may not be optimised well for exactly your CPU but it is 
fast enought to start. Put the library files into your prodject 
and add openblas library to your project dub configuration. A 
.dll files are dinamic, you need also a .lib /.a to link with.


OpenBLAS contains both cblas and lapack api by default.

We defenetely need to add an example for Windows

Best
Ilya


It is not working my friend. I've been at this for nearly two 
full days now. All the .lib/.a files I have tried for BLAS and 
LAPACK just fail to link, including those from openblas.net.

rdmd insists on:

Error 42: Symbol Undefined _cblas_dgemm
Error 42: Symbol Undefined _cblas_dger
Error: linker exited with status 2

Am I missing something?
Thank you.



Re: iota to array

2018-02-25 Thread psychoticRabbit via Digitalmars-d-learn

On Sunday, 25 February 2018 at 12:13:31 UTC, Andrea Fontana wrote:
On Sunday, 25 February 2018 at 09:30:12 UTC, psychoticRabbit 
wrote:

I would have preffered it defaulted java style ;-)

System.out.println(1.0); // i.e. it prints 'what I told it to 
print'.


System.out.println(1.0); // print 1.0
System.out.println(1.0); // print 1.0

So it doesn't print "what you told it to print"

Andrea Fontana


can someone please design a language that does what I tell it!

please!!

is that so hard??

print 1.0 does not mean go and print 1 .. it means go and print 
1.0


languages are too much like people.. always thinking for 
themselves.


I fed up!

fed up I say!



Re: countUntil to print all the index of a given string.

2018-02-25 Thread Vino via Digitalmars-d-learn
On Sunday, 25 February 2018 at 03:41:27 UTC, Jonathan M Davis 
wrote:
On Sunday, February 25, 2018 02:58:33 Seb via 
Digitalmars-d-learn wrote:

[...]


That will help eventually, but it requires a compiler flag, so 
it's really not going to help for code in general right now, 
and the fact that that DIP does nothing to solve the problem of 
how to create exception messages without allocating them on the 
GC heap means that exceptions in general are still frequently 
going to result in allocations unless you jump through several 
hoops to be able to create an exception message that's in a 
static array or malloc-ed or something. So, I don't know how 
much it's going to help in practice outside of code where the 
programmer is absolutely determined to have no GC allocations.



[...]


Yeah. There does tend to be a correlation between @nogc and 
whether a range is lazy, but it's not guaranteed, so I'm 
inclined to think that it's a poor idea to rely on it and that 
it's just ultimately better to look at the documentation or 
even the code.


- Jonathan M Davis


Hi All,

  Sorry, I am not able to see any correlation between the raised 
topic and the conversation that is happening in this forum, could 
any one please explain on of what is going on and how do you 
thing that this conversation is related to the topic raised, if 
not would suggest you to open a new topic.


From,
Vino.B


Re: iota to array

2018-02-25 Thread Andrea Fontana via Digitalmars-d-learn
On Sunday, 25 February 2018 at 09:30:12 UTC, psychoticRabbit 
wrote:

I would have preffered it defaulted java style ;-)

System.out.println(1.0); // i.e. it prints 'what I told it to 
print'.


System.out.println(1.0); // print 1.0
System.out.println(1.0); // print 1.0

So it doesn't print "what you told it to print"

Andrea Fontana


Re: iota to array

2018-02-25 Thread psychoticRabbit via Digitalmars-d-learn

On Sunday, 25 February 2018 at 08:46:19 UTC, rumbu wrote:
On Sunday, 25 February 2018 at 08:08:30 UTC, psychoticRabbit 
wrote:



But umm what happended to the principle of least 
astonishment?


writeln(1.1); (prints 1.1)
whereas..
writeln(1.0); (prints 1)

I don't get it. Cause it's 'nicer'??



Because writeln(someFloat) is equivalent to writefln("%g", 
someFloat). And according to printf specification, "trailing 
zeros are removed from the fractional part of the result; a 
decimal point appears only if it is followed by at least one 
digit"


oh. that explains it.

I would have preffered it defaulted java style ;-)

System.out.println(1.0); // i.e. it prints 'what I told it to 
print'.




Re: iota to array

2018-02-25 Thread rumbu via Digitalmars-d-learn
On Sunday, 25 February 2018 at 08:08:30 UTC, psychoticRabbit 
wrote:



But umm what happended to the principle of least 
astonishment?


writeln(1.1); (prints 1.1)
whereas..
writeln(1.0); (prints 1)

I don't get it. Cause it's 'nicer'??



Because writeln(someFloat) is equivalent to writefln("%g", 
someFloat). And according to printf specification, "trailing 
zeros are removed from the fractional part of the result; a 
decimal point appears only if it is followed by at least one 
digit"




Re: iota to array

2018-02-25 Thread psychoticRabbit via Digitalmars-d-learn
On Sunday, 25 February 2018 at 06:35:07 UTC, Jonathan M Davis 
wrote:


It's not printing ints. It's printing doubles. It's just that 
all of the doubles have nothing to the right of the decimal 
point, so they don't get printed with a decimal point. If you 
did something like start with 1.1, then you'd see decimal 
points, because there would be data to the right of the decimal 
point. The same thing happens if you do


writeln(1.0);

as opposed to something like

writeln(1.3);



thanks.

But umm what happended to the principle of least astonishment?

writeln(1.1); (prints 1.1)
whereas..
writeln(1.0); (prints 1)

I don't get it. Cause it's 'nicer'??

I ended up having to work around this..like this:

---
void printArray(T)(const ref T[] a) if (isArray!(T[]))
{
if( isFloatingPoint!T)
foreach(t; a) writefln("%.1f", t);
else
foreach(t; a) writefln("%s", t);

}
---