Re: A new instance of a variable?

2015-11-13 Thread anonymous via Digitalmars-d-learn
On 13.11.2015 18:44, Ish wrote: immutable int* j = new immutable int(i); gives error: locks1.d:27: error: no constructor for immutable(int); Looks like your D version is rather old. I had to go back to dmd 2.065 to see that error. 2.065 is from February 2014. We're at 2.069 now. I'd

Bug? Bad file name?

2015-11-13 Thread Anonymous via Digitalmars-d-learn
I was playing with some code someone posted on the forum that involved opDispatch and compile time parameters. I pasted it in a file named templOpDispatch.d, ran it, and got an error. Then I noticed if I renamed the file it worked. The source didn't matter; same thing happens with an empty

Re: I can't believe this !!

2015-11-13 Thread anonymous via Digitalmars-d-learn
On 14.11.2015 07:30, MesmerizedInTheMorning wrote: https://issues.dlang.org/show_bug.cgi?id=15331 but it's true ! There's **nothing** to check the availability of a Key. At least I would expect opIndex[string key] to return a JSONValue with .type == JSON_TYPE.NULL, but no... Also If it was

Re: Compiler doesn't complain with multiple definitions

2015-11-12 Thread anonymous via Digitalmars-d-learn
On 12.11.2015 06:27, ric maicle wrote: I was playing with __traits and tried the code below. Shouldn't the compiler emit a warning that I'm defining isPOD multiple times and/or I'm defining something that is built-in like isPOD? // DMD64 D Compiler v2.069 import std.stdio; struct isPOD { bool

Re: opCmp with structs

2015-11-10 Thread anonymous via Digitalmars-d-learn
On 07.11.2015 16:59, anonymous wrote: Wat. It even compiles with @safe. That's not good. Filed an issue: https://issues.dlang.org/show_bug.cgi?id=15315

Re: Error not callable with argument types but types matches

2015-11-08 Thread anonymous via Digitalmars-d-learn
On 08.11.2015 08:17, Sliya wrote: I am on Mac OS, but I still don't get it. If the import was not case-sensitive, I would not have any error since the good file would have been loaded... Here I have no error saying file not found yet the file is not loaded. I'd love to know what really happens.

Re: opCmp with structs

2015-11-07 Thread anonymous via Digitalmars-d-learn
On 07.11.2015 15:36, Mike Parker wrote: It's actually possible to use move one instance into another, though: void main() { import std.algorithm : move; ku k1 = ku(1); ku k2 = ku(2); k2.move(k1); assert(k1.id == 2); } Wat. It even compiles with @safe. That's not good.

Re: struct constructor co nfusion

2015-11-06 Thread anonymous via Digitalmars-d-learn
On 06.11.2015 20:05, Spacen Jasset wrote: Also, I had to add a dummy private constructor to make my structs 'createable', or is there another way? e.g. struct Texture { @disable this(); static Texture create() { return Texture(0); } ... private: this(int) {

Re: parallel

2015-11-05 Thread anonymous via Digitalmars-d-learn
On 05.11.2015 21:30, Handyman wrote: Seems that 4 cores go all out on first 4 dishes, then 1 core deals with the last dish. With 4 cores I expect diner is ready after 5/4 = 1.25 secs though. What did I do wrong? You describe the situation correctly. The unit of work is a dish. That is, the

Re: parallel

2015-11-05 Thread anonymous via Digitalmars-d-learn
On 05.11.2015 21:43, Handyman wrote: foreach (i; 0..50) Thread.sleep(20.msecs); But then my program still says: '2 secs'. Please enlighten me. Let's look at the line that does the `parallel` call: foreach (dish; parallel(dishes, 1)) dish.prepare(); This means that `dishes` is

Re: parallel

2015-11-05 Thread anonymous via Digitalmars-d-learn
On 05.11.2015 21:52, Handyman wrote: On Thursday, 5 November 2015 at 20:45:25 UTC, Ali Çehreli wrote: That's still 1 second per task. The function prepare() cannot be executed by more than one core. Thanks. OK. So 'prepare' is atomic? Then let's turn it around: how can I make the cores

Re: Capturing __FILE__ and __LINE in a variadic templated function

2015-11-01 Thread anonymous via Digitalmars-d-learn
On 01.11.2015 23:49, Adam D. Ruppe wrote: Yeah, just make the other args normal runtime instead of template: Or make it two nested templates: template show(T ...) { void show(string file = __FILE__, uint line = __LINE__, string fun = __FUNCTION__)() { ... } }

Re: Static constructors in structs.

2015-10-30 Thread anonymous via Digitalmars-d-learn
On 30.10.2015 21:23, TheFlyingFiddle wrote: Is this intended to work? struct A { __gshared static this() { //Add some reflection info to some global stuff. addReflectionInfo!(typeof(this)); } } I just noticed this works in 2.069, is this intended? static

Re: Merging two named Tuples

2015-10-29 Thread anonymous via Digitalmars-d-learn
On 29.10.2015 19:59, Edwin van Leeuwen wrote: On Saturday, 24 October 2015 at 11:04:14 UTC, Edwin van Leeuwen wrote: I am trying to write a function to merge two named structs, but am completely stuck on how to do that and was wondering if anyone good provide any help. I know I can access the

Re: `clear`ing a dynamic array

2015-10-25 Thread anonymous via Digitalmars-d-learn
On Sunday, 25 October 2015 at 11:45:53 UTC, Shriramana Sharma wrote: http://dlang.org/arrays.html#resize says: """Also, you may wish to utilize the phobos reserve function to pre-allocate array data to use with the append operator.""" I presume this means

Re: `clear`ing a dynamic array

2015-10-24 Thread anonymous via Digitalmars-d-learn
On 24.10.2015 15:18, Shriramana Sharma wrote: int a[] = [1,2,3,4,5]; Aside: `int[] a;` is the preferred style for array declarations. How to make it so that after clearing `a`, `b` will also point to the same empty array? IOW the desired output is: [1, 2, 3, 4, 5] [1, 2, 3, 4, 5] [] []

Re: Converting Unicode Escape Sequences to UTF-8

2015-10-22 Thread anonymous via Digitalmars-d-learn
On Thursday, October 22, 2015 08:10 PM, Nordlöw wrote: > How do I convert a `string` containing Unicode escape sequences > such as "\u" into UTF-8? Ali explained that "\u" is already UTF-8. But if you actually want to interpret such escape sequences from user input or some such, then

Re: Converting Unicode Escape Sequences to UTF-8

2015-10-22 Thread anonymous via Digitalmars-d-learn
On 22.10.2015 21:13, Nordlöw wrote: Hmm, why isn't this already in Phobos? I think parsing only Unicode escape sequences is not a common task. You usually need to parse some larger language of which escape sequences are only a part. For example, parsing JSON or XML are common tasks, and we

Re: Overloading an imported function

2015-10-22 Thread anonymous via Digitalmars-d-learn
On 22.10.2015 06:14, Shriramana Sharma wrote: anonymous wrote: Huh. I can't find any specification on this, but apparently the local overload set shadows any imported overload sets completely. Should I file a bug on this then? I'm not sure. Maybe make a thread on the main group first. It's

Re: can't zip a char[5], string[5], real[5]

2015-10-21 Thread anonymous via Digitalmars-d-learn
On Wednesday, 21 October 2015 at 14:06:54 UTC, Shriramana Sharma wrote: import std.stdio, std.range; void mywrite(char [5] chars, real[5] vals) { static string [5] fmts = ["%9.4f, ", "%9.4f; ", "%3d, ", "%3d, ", "%3d\n"]; foreach (e; zip(chars, fmts, vals)) write(e[0], " = ",

Re: Overloading an imported function

2015-10-21 Thread anonymous via Digitalmars-d-learn
On Wednesday, October 21, 2015 08:28 PM, Shriramana Sharma wrote: > Kagamin wrote: > >> http://dlang.org/hijack.html > > Thanks people, but even as per the rules: > > 1. Perform overload resolution independently on each overload set > 2. If there is no match in any overload set, then error >

Re: Implicit conversion rules

2015-10-21 Thread anonymous via Digitalmars-d-learn
On Wednesday, October 21, 2015 07:53 PM, Sigg wrote: > void func() { > int a = -10; > ulong b = 0; > ulong c = a + b; > writefln("%s", c); > } > > out: 18446744073709551574 > > But shouldn't declaring c as auto force compiler to go extra step >

Re: Enough introspection to report variable name of calling argument

2015-10-19 Thread anonymous via Digitalmars-d-learn
On Monday, October 19, 2015 04:14 PM, Handyman wrote: > Is the following possible in D? To call a (unary) function f > with variable a, and let f print: > >> Called with argument named 'a'. > > I am of course asking for a generic solution, independent of the > actual variable name (in this

Re: Check Instance of Template for Parameter Type/Value

2015-10-19 Thread anonymous via Digitalmars-d-learn
On Monday, October 19, 2015 04:51 PM, Stewart Moth wrote: > struct Vector(type, int dimension_){ ... } > > Where type is going to be an int/float/etc and dimension_ is > 2/3/4. > > I could write a bunch of functions for each case, but I'd rather > not... I'd like to use something like the

Re: what is wrong with this code??

2015-10-17 Thread anonymous via Digitalmars-d-learn
On Saturday, October 17, 2015 04:17 PM, steven kladitis wrote: > // it thows a range exception On which line?

Re: what is wrong with this code??

2015-10-17 Thread anonymous via Digitalmars-d-learn
On Saturday, October 17, 2015 04:50 PM, steven kladitis wrote: > core.exception.RangeError@sokuban.d(84): Range violation Line 84 being this: sDataBuild ~= sMap[ch]; Where sMap is: /*static*/ immutable sMap = [' ':' ', '.':'.', '@':' ', '#':'#', '$':' '];

Re: Compiling a .d file both as library and executable

2015-10-17 Thread anonymous via Digitalmars-d-learn
On Saturday, October 17, 2015 05:36 PM, Shriramana Sharma wrote: > In Python there is: > > if __name__ == "__main__": > > to allow the same source file to be treated as both an importable library > and as an executable script. In D is there any such mechanism to make a > main() compiled

Re: Idiomatic adjacent_difference

2015-10-16 Thread anonymous via Digitalmars-d-learn
On Friday, October 16, 2015 02:03 PM, Per Nordlöw wrote: > zip(r, r.dropOne).map!((t) => t[1]-t[0]); You should r.save one or both of those. The dropOne may affect both instances if you don't .save. By the way, what's the point of `dropOne` over `drop(1)`? It's not shorter. Does it do

Re: Why can't function expecting immutable arg take mutable input?

2015-10-16 Thread anonymous via Digitalmars-d-learn
On Friday, October 16, 2015 12:35 PM, Shriramana Sharma wrote: > Why can't a function that takes an immutable argument be called with a > mutable input at the call site? > > IOW, why isn't mutable implicitly convertible to immutable? immutable says that the data won't ever change. If references

Re: Builtin array and AA efficiency questions

2015-10-15 Thread anonymous via Digitalmars-d-learn
On Thursday, October 15, 2015 11:48 PM, Random D user wrote: > Should array have clear() as well? > Basically wrap array.length = 0; array.assumeSafeAppend(); > At least it would then be symmetric (and more intuitive) with > built-in containers. No. "clear" is too harmless a name for it to

Re: Regarding std.array.Appender

2015-10-13 Thread anonymous via Digitalmars-d-learn
On Tuesday 13 October 2015 15:47, Suliman wrote: > something like: auto content = file.byLine.map!("start " ~ a=>a ~ > " end"); That's not how it works at all. Maybe stick to the examples of whatever resource you're learning from, for now.

Re: Regarding std.array.Appender

2015-10-13 Thread anonymous via Digitalmars-d-learn
On Tuesday 13 October 2015 15:42, Suliman wrote: > map!(a=> a~=" +") work fine, but how to add before > at same time? Use ~ instead of ~=, like so: map!(a => "+" ~ a ~ "+")

Re: Struct toString works but not std.conv.to!string

2015-10-13 Thread anonymous via Digitalmars-d-learn
On Tuesday, 13 October 2015 at 22:21:43 UTC, Ali Çehreli wrote: Reduced with a workaround: struct UTCOffset { import std.conv : to;// Move to module scope to compile This introduces UTCOffset.to as an alias to std.conv.to. string toString() const { return "hello";

Re: DMD Compiler 'switches'

2015-10-12 Thread anonymous via Digitalmars-d-learn
On Monday 12 October 2015 17:38, ric maicle wrote: > I'm wondering if this small irregularity should be made consistent or > maybe I misunderstood something. As far as I know, the difference just happened, and there is point to it. The style without "=" is older and wasn't followed when new

Re: Ternary if and ~ does not work quite well

2015-10-12 Thread anonymous via Digitalmars-d-learn
On Monday 12 October 2015 17:39, TheFlyingFiddle wrote: > "foo" ~ true > > How does this compile? All i can see is a user trying to append a > boolean to a string which is obvously a type error. Or are they > converted to ints and then ~ would be a complement operator? In > that case..

Re: DMD Compiler 'switches'

2015-10-12 Thread anonymous via Digitalmars-d-learn
On Monday 12 October 2015 19:46, anonymous wrote: > and there is point to it Ugh, should have been: and there is *no* point to it.

Re: Class, constructor and inherance.

2015-10-11 Thread anonymous via Digitalmars-d-learn
On Monday 12 October 2015 07:28, Ali Çehreli wrote: > For example, you cannot get current time at run time. I think you mean compile time here.

Re: Ternary if and ~ does not work quite well

2015-10-11 Thread anonymous via Digitalmars-d-learn
On Monday 12 October 2015 07:23, Rikki Cattermole wrote: > On 12/10/15 6:19 PM, Andre wrote: [...] >> // assert("foo "~ true ? "bar" : "baz" == "foo bar"); does not compile [...] > I read it as: > > assert("foo "~ (true ? ("bar") : ("baz" == "foo bar"))); > > Oh hey look: >

Re: Comparing arrays of floats?

2015-10-09 Thread anonymous via Digitalmars-d-learn
On Saturday 10 October 2015 00:14, Straivers wrote: > Is it a bit-by-bit comparison, no > is the std.math.approxEqual function get called for > each element, no > or is it byte-by-byte across the entire array? no After comparing the lengths, the elements are checked for equality one by

Re: Varargs and default arguments

2015-10-07 Thread anonymous via Digitalmars-d-learn
On Wednesday 07 October 2015 02:22, Steven Schveighoffer wrote: > On 10/6/15 4:27 PM, anonymous wrote: [...] >> void foo(T...)(string str=null, T args = T.init) { [...] > I find it quite fascinating that in anonymous' solution, the T.init > doesn't ever actually get used! It's not used with

Re: What is the postfix for min long value?

2015-10-06 Thread anonymous via Digitalmars-d-learn
On Tuesday 06 October 2015 17:39, Ali Çehreli wrote: > I would expect the following to work: > > writeln( -9_223_372_036_854_775_808L); > > But it doesn't compile: > >Error: signed integer overflow > > It looks like a compiler bug to me. If so, a very embarrassing one. :)

Re: Bug? 0 is less than -10

2015-10-06 Thread anonymous via Digitalmars-d-learn
On Tuesday, 6 October 2015 at 14:46:56 UTC, tcak wrote: Maybe I am just too stressed out to see the problem. [code] import std.stdio; void main(){ size_t dec = 0; writeln( dec, " ", (dec <= -10), " ", (dec >= 10), " ", ((dec <= -10) || (dec >= 10)) ); } [/code] [output] 0 true

Re: Varargs and default arguments

2015-10-06 Thread anonymous via Digitalmars-d-learn
On Tuesday 06 October 2015 22:01, Nick Sabalausky wrote: > Ok, D-style varargs can accept a parameter length of zero: > > --- > void foo(T...)(T args) { > //... > } > foo(); > foo(t1, t2); > --- Terminology fun: The spec uses the term "D-style variadic function"

Re: Range of variables

2015-09-30 Thread anonymous via Digitalmars-d-learn
On Wednesday, 30 September 2015 at 20:11:56 UTC, Freddy wrote: Is there a way to make a range of a variables lazily? --- int var1; int var2; void func() { int var3; auto range = /*range of var1,var2,var3*/ ; } --- There's std.range.only which gives you a range over the arguments you

Re: Interval Arithmetic

2015-09-29 Thread anonymous via Digitalmars-d-learn
On Tuesday, 29 September 2015 at 21:04:06 UTC, Wulfrick wrote: Is there an interval arithmetic library in D? I couldn’t find one. None I am aware of. In case I had to write my own, I understand that the IEEE standard floating point arithmetic provides operations for rounding up or down

Re: Move Semantics

2015-09-29 Thread anonymous via Digitalmars-d-learn
On Tuesday 29 September 2015 16:38, Alex wrote: > Another question on move semantics from the cheap seats... > > See my code here: http://dpaste.dzfl.pl/995c5af59dd6 [...] > The first (minor) question is: > I have to initialize some dummy inner objects, before I can apply > the move action. Is

Re: Server side command execution.

2015-09-28 Thread anonymous via Digitalmars-d-learn
On Monday 28 September 2015 12:40, anonymous wrote: > The client probably sends a newline; i.e. buffer[0 .. received] is > "exit\n". Or more likely it's "exit\r\n".

Re: Server side command execution.

2015-09-28 Thread anonymous via Digitalmars-d-learn
On Monday 28 September 2015 11:59, holo wrote: > I changed my condition to: > > if(to!string(buffer[0..received]) == "exit") > { > > break; > } > > > But it still dint help. The client probably sends a newline; i.e. buffer[0 .. received] is "exit\n".

Re: Parallel processing and further use of output

2015-09-26 Thread anonymous via Digitalmars-d-learn
On Saturday 26 September 2015 14:18, Zoidberg wrote: > I've run into an issue, which I guess could be resolved easily, > if I knew how... > > [CODE] > ulong i = 0; > foreach (f; parallel(iota(1, 100+1))) > { > i += f; > } > thread_joinAll(); >

Re: Parallel processing and further use of output

2015-09-26 Thread anonymous via Digitalmars-d-learn
On Saturday, 26 September 2015 at 13:09:54 UTC, Meta wrote: On Saturday, 26 September 2015 at 12:33:45 UTC, anonymous wrote: foreach (f; parallel(iota(1, 100+1))) { synchronized i += f; } Is this valid syntax? I've never seen synchronized used like this before. I'm

Re: Why are static arrays not ranges?

2015-09-21 Thread anonymous via Digitalmars-d-learn
On Monday 21 September 2015 22:33, Jack Stouffer wrote: > import std.range; > > void main() { > int[6] a = [1, 2, 3, 4, 5, 6]; > > pragma(msg, isInputRange!(typeof(a))); > pragma(msg, isForwardRange!(typeof(a))); > pragma(msg, isRandomAccessRange!(typeof(a))); > } > > $ dmd

Re: OS minimum version

2015-09-21 Thread anonymous via Digitalmars-d-learn
On Monday 21 September 2015 14:47, ponce wrote: > 1. What is the minimum Windows version required by programs > created with DMD? http://dlang.org/dmd-windows.html says: "Windows XP or later, 32 or 64 bit".

Re: Question about Object.destroy

2015-09-20 Thread anonymous via Digitalmars-d-learn
On Sunday 20 September 2015 20:34, Lambert Duijst wrote: > On Sunday, 20 September 2015 at 18:21:52 UTC, Adam D. Ruppe wrote: [...] >> So after calling destroy(s), s is null, so it segfaults when >> you try to use it. [...] > Also when I print the address of s it gives me some hex number, > but

Re: Simple template constraint question

2015-09-19 Thread anonymous via Digitalmars-d-learn
On Saturday 19 September 2015 19:09, WhatMeWorry wrote: > And a more open ended question. Is there a more elegant solution > for the > below function? Maybe a one-liner? I have a knack for making > simple solutions > complex :) > > > > // Calculate the number of components for openGL

Re: Tried release build got ICE, does anyone have a clue what might cause this?

2015-09-19 Thread anonymous via Digitalmars-d-learn
On Sunday 20 September 2015 00:09, Random D user wrote: > class Gui > { > enum MouseButton { Left = 0, Right }; > > private: > > struct ClickPair > { > MouseButton button = MouseButton.Left; > }; > > struct ClickPair // Second struct ClickPair with the enum

Re: Passing Arguments on in Variadic Functions

2015-09-17 Thread anonymous via Digitalmars-d-learn
On Thursday 17 September 2015 23:27, jmh530 wrote: > I think I could figure out how to look through the arguments for > a bool, but wouldn't that make me give up the default value for > the bool? If you don't find a bool, you use the default value.

Re: Final templated interface method not found

2015-09-15 Thread anonymous via Digitalmars-d-learn
On Wednesday 16 September 2015 06:14, Andre wrote: > Hi, > > following coding shoud work, or? > It doesn't compile with v2.068.0. > > Kind regards > André > > interface IfStatement > { > void execute(); > > final void execute(T...)(T t) > { > execute(); >

Re: Initalizing complex array types or some other problem ;/

2015-09-15 Thread anonymous via Digitalmars-d-learn
On Wednesday 16 September 2015 03:46, Prudence wrote: > In any case, Maybe you are not as smart as you think you are if > you can't understand it? kthxbye

Re: Initalizing complex array types or some other problem ;/

2015-09-15 Thread anonymous via Digitalmars-d-learn
On Tuesday 15 September 2015 22:09, Prudence wrote: > The code below doesn't work. Please be more specific in how it doesn't work. Mention the error message if there is one, or say how the code behaves differently from what you'd expect. Trying to compile the code (after kicking getch out), I

Re: chaining chain Result and underlying object of chain

2015-09-14 Thread anonymous via Digitalmars-d-learn
On Monday 14 September 2015 16:17, Laeeth Isharc wrote: > chain doesn't seem to compile if I try and chain a chain of two > strings and another string. > > what should I use instead? Please show code, always. A simple test works for me: import std.algorithm: equal; import std.range:

Re: chaining chain Result and underlying object of chain

2015-09-14 Thread anonymous via Digitalmars-d-learn
On Monday 14 September 2015 17:01, Laeeth Isharc wrote: >auto chain1 = chain("foo", "bar"); >chain1 = chain(chain1, "baz"); > > Realized that in this case it was much simpler just to use the > delegate version of toString and sink (which I had forgotten > about). But I

Re: Passing Arguments on in Variadic Functions

2015-09-14 Thread anonymous via Digitalmars-d-learn
On Monday 14 September 2015 21:59, jmh530 wrote: > This approach gives the correct result, but dmd won't deduce the > type of the template. So for instance, the second to the last > line of the unit test requires explicitly stating the types. I > may as well use the alternate version that

Re: [D Cookbook]about "Communicating with external processes" part.

2015-09-13 Thread anonymous via Digitalmars-d-learn
On Sunday 13 September 2015 15:32, xky wrote: > [ pipe.d ]: > == > import std.process; > import std.stdio; > > void main(){ > auto info = pipeProcess("child.exe"); > scope(exit) wait(info.pid); > >

Re: alias for regular expressions

2015-09-13 Thread anonymous via Digitalmars-d-learn
On Sunday 13 September 2015 21:47, Thunderbird wrote: > Some special interest thingamabob: > > I've tried to redefine "else if" as "elif" using "alias elif = > else if;". No matter what to no avail. > > I know this is probably useless fancy stuff, but is there any way > to get this done

Re: I guess this is a bug?

2015-09-12 Thread anonymous via Digitalmars-d-learn
On Saturday 12 September 2015 20:28, Random D user wrote: > prints (with option B): > bar: 0.00, 0.00 // BUG?? > baz: 1.00, 2.00 Looks like a bug to me. Please file an issue at https://issues.dlang.org/

Re: Mixin templates accessing mixed out scope

2015-09-12 Thread anonymous via Digitalmars-d-learn
On Saturday 12 September 2015 16:30, Ali Çehreli wrote: > Reduced: [...] > Error: type SingleStore is not an expression Reduced further: class MyStore { class SingleStore { static void New() // Removing 'static' compiles { new SingleStore(); }

Re: Mixin templates accessing mixed out scope

2015-09-12 Thread anonymous via Digitalmars-d-learn
On Saturday 12 September 2015 19:36, Prudence wrote: > On Saturday, 12 September 2015 at 17:11:04 UTC, anonymous wrote: [...] >> class MyStore >> { >> class SingleStore >> { >> static void New() // Removing 'static' compiles >> { >> new SingleStore(); >>

Re: Is this a bug?

2015-09-11 Thread anonymous via Digitalmars-d-learn
On Friday 11 September 2015 12:33, Rene Zwanenburg wrote: > The following fails to compile with an 'cannot deduce function > from argument types' error. When using an array of something > other than TypeInfo_Class everything works as expected. > > void main() > { > import

Re: Sum and other algorithm functions

2015-09-10 Thread anonymous via Digitalmars-d-learn
On Thursday 10 September 2015 15:48, Namal wrote: > Hello, > > how can I define the range for the sum function which I want to > sum up? For instance how do I sum up the first 3 elements of an > array > > int[] a = [1,2,3,4,5,6,7,8,9]; > > or the last 3? First you slice the first/last 3,

Re: ref parameter qualifier and static arrays

2015-09-09 Thread anonymous via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 20:18:57 UTC, Paul wrote: Is it possible to call a function like this... void foo(ref int[] anArray) ...with slices of static arrays? I thought I might be able to use [0..$-1] but to no avail - I get an error like this (which is confusing!): Note that the

Re: ref parameter qualifier and static arrays

2015-09-09 Thread anonymous via Digitalmars-d-learn
On Wednesday 09 September 2015 22:18, Paul wrote: > > Is it possible to call a function like this... > > void foo(ref int[] anArray) > > ...with slices of static arrays? I thought I might be able to use > [0..$-1] but to no avail - I get an error like this (which is > confusing!): > > (ref

Re: What are (dis)advantages of using pure and immutable by default?

2015-09-07 Thread anonymous via Digitalmars-d-learn
On Monday 07 September 2015 13:12, Bahman Movaqar wrote: > I was under the impression that when a variable, that is declared > as `immutable`, is passed to a function, a copy of the value is > passed. > > However based on "marks" I can imagine that since the data is > marked as `immutable`

Re: Better unittest failure output

2015-09-07 Thread anonymous via Digitalmars-d-learn
On Monday 07 September 2015 13:57, Bahman Movaqar wrote: > I am working on a simple project created with DUB[1]. > When unit tests the output reads really cryptic to me; for > example: > > $ dub test [...] > core.exception.AssertError@source/e002.d(111): unittest > failure [...] > >

Re: What are (dis)advantages of using pure and immutable by default?

2015-09-07 Thread anonymous via Digitalmars-d-learn
On Monday 07 September 2015 12:40, Bahman Movaqar wrote: > It seems to me a good practice to mark all functions that I write > as `pure` and define all the variables as `immutable`, unless > there is a reason not to. I agree. > I can see some serious advantages of this, most notable of which

Re: function argument restrictions for templated struct

2015-09-07 Thread anonymous via Digitalmars-d-learn
On Monday 07 September 2015 17:51, Laeeth Isharc wrote: > Is there a more elegant way to write the template arg > restrictions for display? [...] > void display(T)(T a) > if (__traits(isSame, TemplateOf!(T), Bar)) > { > writefln("%s",a); > } if (isInstanceOf!(Bar, T))

Re: Better unittest failure output

2015-09-07 Thread anonymous via Digitalmars-d-learn
On Monday 07 September 2015 14:12, Bahman Movaqar wrote: > Thanks. This is indeed helpful. OT but where can I view the > documentation for `unittest` and `assert`? unittest: http://dlang.org/unittest.html assert: http://dlang.org/expression.html#AssertExpression (I don't know why it's

Re: Windows Header consts

2015-09-07 Thread anonymous via Digitalmars-d-learn
On Monday 07 September 2015 21:06, Prudence wrote: > If you think mentally changing a . to a _ is a hassle then your > in trouble! An apple a day simply won't help! [...] > Oh well, some people > just don't like progress! Do you want to go back to using wooden > wheels too? [...] > Get out of

Re: reading file byLine

2015-09-06 Thread anonymous via Digitalmars-d-learn
On Sunday, 6 September 2015 at 15:41:34 UTC, Namal wrote: is there any function that removes double elements in a sorted array? std.algorithm.iteration.uniq http://dlang.org/phobos/std_algorithm_iteration.html#uniq

Re: reading file byLine

2015-09-06 Thread anonymous via Digitalmars-d-learn
On Sunday, 6 September 2015 at 16:17:29 UTC, Namal wrote: Error: module comparison is in file 'std/algorithm/comparison.d' which cannot be read import path[0] = /usr/include/dmd/phobos import path[1] = /usr/include/dmd/druntime/import when I try to load the headers like in the example Are

Re: Abstractioning away main/winMain

2015-09-05 Thread anonymous via Digitalmars-d-learn
On Saturday 05 September 2015 07:52, anonymous wrote: > This doesn't work because delegates and static initialization don't go > together. You can use a static constructor: > > > const Application MyApp; > static this() > { > Application.New({import std.stdio; std.stdio.writeln("MY APP

Re: Superfluous code in switch statement

2015-09-04 Thread anonymous via Digitalmars-d-learn
On Friday 04 September 2015 23:04, Timon Gehr wrote: > DMD never warns about dead code. It warns here: import std.stdio; void main() { return; writeln("hi"); /* Warning: statement is not reachable */ }

Re: Abstractioning away main/winMain

2015-09-04 Thread anonymous via Digitalmars-d-learn
On Saturday 05 September 2015 03:43, Prudence wrote: > Standard and Win32 apps are so old school! > > I'd like to hide WinMain by wrapping it in an application > class(more or less). > > Essentially I have an Application class > > class Application > { > public static Application New(void

Re: Problem with using struct ranges with @disabled this(this) with some range functions

2015-09-02 Thread anonymous via Digitalmars-d-learn
On Wednesday 02 September 2015 09:52, Uranuz wrote: > I want to understand if we have *save* method in Forward Range > then why or in which cases we should use plain struct copying > instead. Should we assume that these two ways are equal or not? No, don't assume that they're the same. > Also

Re: new static array

2015-09-02 Thread anonymous via Digitalmars-d-learn
On Wednesday, 2 September 2015 at 06:04:40 UTC, Ali Çehreli wrote: > with int[4] it compiles and runs. int[][4] fails. Is this a bug? I think so. https://issues.dlang.org/show_bug.cgi?id=15004 may related to https://issues.dlang.org/show_bug.cgi?id=10740

new static array

2015-09-01 Thread anonymous via Digitalmars-d-learn
Hello, I tried to send a string[4] with std.concurrency: import std.concurrency; import std.stdio; void fun() { receive((string[4] data) { writeln(data);}); } void main() { string[4] data; auto tid = spawn(); send(tid, data); } I got (dmd 2.068)

Re: observation: D getting a bit complex

2015-08-30 Thread anonymous via Digitalmars-d-learn
On Sunday 30 August 2015 04:42, Spacen Jasset wrote: immutable(ElementEncodingType!(ElementType!Range))[] buildPath(Range)(Range segments) if (isInputRange!Range isSomeString!(ElementType!Range)); pure nothrow @safe immutable(C)[] buildPath(C)(const(C)[][] paths...) if (isSomeChar!C);

Re: Reading and converting binary file 2 bits at a time

2015-08-29 Thread anonymous via Digitalmars-d-learn
On Saturday, 29 August 2015 at 23:34:47 UTC, Gary Willoughby wrote: But it might not be safe: http://forum.dlang.org/thread/ztefzijqhwrouzlag...@forum.dlang.org That link just takes me to this thread here again.

Re: Arrays of structs

2015-08-27 Thread anonymous via Digitalmars-d-learn
On Thursday 27 August 2015 14:35, BBasile wrote: Anyway. I cheat a bit with attributes but as long as it's only for me...I know this kinds of functions are not phobos-level. Sure, as long as you're cautious and regard those functions as unsafe, you may be fine. You still risk accidentally

Re: What is this function call operator?

2015-08-27 Thread anonymous via Digitalmars-d-learn
On Thursday 27 August 2015 17:18, Gary Willoughby wrote: What is this function call operator? (...) Where can i learn more about it? http://dlang.org/operatoroverloading.html#function-call http://ddili.org/ders/d.en/operator_overloading.html#ix_operator_overloading.opCall

Re: Arrays of structs

2015-08-27 Thread anonymous via Digitalmars-d-learn
On Thursday 27 August 2015 13:15, BBasile wrote: https://github.com/BBasile/iz/blob/master/import/iz/types.d#L125 https://github.com/BBasile/iz/blob/master/import/iz/types.d#L150 https://github.com/BBasile/iz/blob/master/import/iz/types.d#L191 Your use of @trusted is wrong and dangerous.

Re: multiline string literal with CRLF

2015-08-26 Thread anonymous via Digitalmars-d-learn
On Wednesday 26 August 2015 20:28, Marek Janukowicz wrote: Is there any way to input such a literal? Both `...` and qEOS...EOS do not allow escape sequences. I'm on Linux, but I need precisely CRLF, not just \n. I'm probably missing the point, but: Hello\r\nworld Or if you want to include

Re: Casting pointers

2015-08-26 Thread anonymous via Digitalmars-d-learn
On Wednesday 26 August 2015 14:14, John Burton wrote: This would be undefined behavior in c++ due to aliasing rules on pointers. It appears to work reliably in D when I try it, but that's obviously no guarantee that it's correct or will continue to do so. Is this correct code in D? And if

Re: NYT data article based on work of EMSI, who I think are a D shop

2015-08-25 Thread anonymous via Digitalmars-d-learn
On Tuesday 25 August 2015 06:55, Laeeth Isharc wrote: http://www.nytimes.com/2015/08/23/magazine/the-creative-apocalypse-that-wasnt.html Interesting article as it corrects misconceptions of a few years back by looking at the data. This is based on tools from EMSI, who are a D shop.

Re: C++/STL interop

2015-08-25 Thread anonymous via Digitalmars-d-learn
On Monday 24 August 2015 17:37, anonymous wrote: I saw https://issues.dlang.org/show_bug.cgi?id=14956 . questions: - is std.basic_string released into the wild? - where do I find std.basic_string? - does std.vector exist? That would allow me to get rid of some C++ clue code (build an

Re: NYT data article based on work of EMSI, who I think are a D shop

2015-08-25 Thread anonymous via Digitalmars-d-learn
On Wednesday 26 August 2015 00:22, Laeeth Isharc wrote: I'm open to being corrected about where the right place should be, but it wasn't an accidental decision to post here. I think you might find more interest over in General. Learn tends to be a question/answer kind of thing. So people

C++/STL interop

2015-08-24 Thread anonymous via Digitalmars-d-learn
I saw https://issues.dlang.org/show_bug.cgi?id=14956 . questions: - is std.basic_string released into the wild? - where do I find std.basic_string? - does std.vector exist? That would allow me to get rid of some C++ clue code (build an C-like interface, copy data etc)... Putting extern(C++)

Re: How to use ranges?

2015-08-23 Thread anonymous via Digitalmars-d-learn
On Sunday 23 August 2015 19:58, Doolan wrote: You can use typeof to get the type of a range expression when typing it out is impractical/impossible. What if I want to save a range in a struct? Or is a range more of a verb than a noun..? Can still use typeof then: struct S { import

Re: Trying to compile weather program

2015-08-23 Thread anonymous via Digitalmars-d-learn
On Sunday 23 August 2015 11:54, Tony wrote: weather_report.d(32): Error: undefined identifier centerJustifier `centerJustifier` is new in 2.068. You're probably using an older version of D. You can replace `centerJustifier` with `center` here.

Re: How to use ranges?

2015-08-23 Thread anonymous via Digitalmars-d-learn
On Sunday 23 August 2015 12:17, Doolan wrote: And the use of auto everywhere makes it really hard to tell what types I should be using for anything. My compiler talks about RangeT!(whatever) but you try to use RangeT!(whatever) and you find out RangeT is private... You can use typeof to get

Re: Why does not my program is not running?

2015-08-20 Thread anonymous via Digitalmars-d-learn
On Thursday 20 August 2015 22:31, Unknow wrote: I'm writed a program for calculating the e number. I can compile the source code but when i try run the program, system gives 'program stopped working' error. Source code; // main.d module main; import std.file; import std.conv;

<    1   2   3   4   5   6   >