Stack traces with DMD on OSX

2018-05-31 Thread pineapple via Digitalmars-d-learn
When I run code on OSX and it produces a stack trace, the output uses mangled symbols and is missing line numbers, like so - how can I change these stack traces to be more readable? 0 objectpool 0x000104e9a3bc _D4core7runtime18runModuleUnitTestsUZ19unittestSegvHa

Running tests for a large library on Windows

2018-09-24 Thread pineapple via Digitalmars-d-learn
I do mach.d - https://github.com/pineapplemachine/mach.d I've been setting up CI tests and OSX and Linux tests are good to go thanks to Travis. I'm having a little more difficulty with testing on Windows via AppVeyor, since DMD is too memory-hungry to `dub test` without a fatal error when DMD

Re: Running tests for a large library on Windows

2018-09-24 Thread pineapple via Digitalmars-d-learn
Speaking of which, is there any AppVeyor config or script laying around somewhere for how to install 64-bit DMD? Since I would ideally like to automate testing with both 32-bit and 64-bit DMD

Where is there documentation on how to write inline asm?

2018-11-15 Thread pineapple via Digitalmars-d-learn
I've managed to get a few functions working before mostly by copying whatever Phobos was doing for a similar purpose, but now that I'm trying to do something different I am really hitting a wall. My issue is that I can't figure out how to access a function's arguments from within inline asm o

Re: Where is there documentation on how to write inline asm?

2018-11-15 Thread pineapple via Digitalmars-d-learn
On Thursday, 15 November 2018 at 21:00:10 UTC, Adam D. Ruppe wrote: It would be part of the abi: https://dlang.org/spec/abi.html#function_calling_conventions though it references C so you might need to look that up too. That's helpful, thank you! For other sized structs and static arrays, the

Re: Where is there documentation on how to write inline asm?

2018-11-15 Thread pineapple via Digitalmars-d-learn
On Thursday, 15 November 2018 at 21:12:39 UTC, Adam D. Ruppe wrote: On Thursday, 15 November 2018 at 21:07:51 UTC, pineapple wrote: Is there a way to access this pointer? It is passed as.. I think the final argument to the function. (unless it is the first, do a quick test to find out). Als

Re: Where is there documentation on how to write inline asm?

2018-11-15 Thread pineapple via Digitalmars-d-learn
On Thursday, 15 November 2018 at 21:48:46 UTC, kinke wrote: The MS docs are complete IIRC. The pointer to the pre-allocated result of your 16-bytes struct is passed in RCX. If unsure, just reverse-engineer what you need: type it down in normal D and analyze the generated assembly. You can even d

Re: Where is there documentation on how to write inline asm?

2018-11-15 Thread pineapple via Digitalmars-d-learn
Ah, I've got something working! It's not exactly what I wanted, but it's good enough for now. Instead of using an invisible output pointer, the output pointer is passed in explicitly. struct Result { ulong low; ulong high; } void retTest(Result* result) { v

Re: Where is there documentation on how to write inline asm?

2018-11-15 Thread pineapple via Digitalmars-d-learn
Well, for anyone who is tangling with similar mysteries, I finally got something to work the way I wanted it to. Thank you for the help, Adam and kinke! The first "x" argument was stored in R8. The second "y" argument was stored in RDX. The invisible return value pointer was stored in RCX.

Re: map on char[] converts to dchar?

2017-07-24 Thread pineapple via Digitalmars-d-learn
It is worth noting too that mach's map function will not behave this way; UTF encoding and decoding is instructed explicitly and is not done implicitly like in phobos. https://github.com/pineapplemachine/mach.d import mach.range : map, asarray; import mach.text.ascii : toupper; vo

Re: Best syntax for a diagonal and vertical slice

2017-07-24 Thread pineapple via Digitalmars-d-learn
On Saturday, 22 July 2017 at 20:55:06 UTC, kerdemdemir wrote: And what if I want to go diagonal like 1,5,9 or 3,5,7 in the example above. Is there a good solution in std without using for loops? I suggest using an actual matrix type for tasks like this. I don't know about diagonal slicing, bu

Allowing arbitrary types for a function's argument and return type

2015-10-22 Thread pineapple via Digitalmars-d-learn
I'm just starting to hammer D's very pleasant syntax into my head. After "Hello world", the first thing I do when learning any language is to write a simple program which generates and outputs the Collatz sequence for an arbitrary number. (I also like to golf it.) This is what I wrote in D: i

Re: Allowing arbitrary types for a function's argument and return type

2015-10-22 Thread pineapple via Digitalmars-d-learn
On Thursday, 22 October 2015 at 13:58:56 UTC, Adam D. Ruppe wrote: D's templates are easy (you actually used one in there, the Generator is one!) Try this: import std.concurrency; Generator!T sequence(T)(T i){ return new Generator!T({ yield(i); while(i > 1){ yie

Re: Allowing arbitrary types for a function's argument and return type

2015-10-22 Thread pineapple via Digitalmars-d-learn
On Thursday, 22 October 2015 at 14:36:52 UTC, John Colvin wrote: Using ranges instead of threads or fibers, slightly over-engineered to show off features: What does if(isIntegral!T) do? It looks like it would verify that the template type is a discrete number? If I were to create my own class

Using C's fread/fwrite with File objects

2015-10-22 Thread pineapple via Digitalmars-d-learn
I'd like to use fread and fwrite in place of File.rawRead and File.rawWrite which force the creation of an array where I'd rather specify a buffer location and length. I'd like to do this using a File object but the handle for the C stream is a private member and I can't find any way to access

Re: Using C's fread/fwrite with File objects

2015-10-22 Thread pineapple via Digitalmars-d-learn
Answered my own question: Turns out File.getFP() does exactly what I needed

Re: Using C's fread/fwrite with File objects

2015-10-22 Thread pineapple via Digitalmars-d-learn
On Thursday, 22 October 2015 at 18:28:50 UTC, Ali Çehreli wrote: If you already have a piece of memory, it is trivial to convert it to a slice in D: auto slice = existing_pointer[0 .. number_of_elements]; http://ddili.org/ders/d.en/pointers.html#ix_pointers.slice%20from%20pointer The opera

Default method implementations in interfaces?

2015-10-23 Thread pineapple via Digitalmars-d-learn
Is it possible to have default method implementations in interfaces à la Java in D? Or some equivalent that allows multiple inheritance without a bunch of identical copypasted method bodies?

Re: Default method implementations in interfaces?

2015-10-23 Thread pineapple via Digitalmars-d-learn
On Friday, 23 October 2015 at 15:07:05 UTC, Alex Parrill wrote: Use template mixins: http://dlang.org/template-mixin.html On Friday, 23 October 2015 at 15:08:30 UTC, Adam D. Ruppe wrote: Use a mixin template together with your interface. Awesome, thanks! No way, though, to unite declaration

I'm getting an unhelpful linker error, what've I got wrong?

2015-10-28 Thread pineapple via Digitalmars-d-learn
When I attempt to compile my code I get the same linker error with both dmd and ldc2. I know where the problematic code is, as I don't get the error when I comment out lines 102 through 107, but I don't understand why it's bad. I must have some misconceptions about how templates work? Is there

Re: I'm getting an unhelpful linker error, what've I got wrong?

2015-10-28 Thread pineapple via Digitalmars-d-learn
On Wednesday, 28 October 2015 at 11:40:14 UTC, tcak wrote: The "writebuffer" is defined to take an array as parameter. Yet, you are passing a pointer and a length to it. Instead, pass the parameter "str" to it directly. Also, you do not have to put "!char" to there. Compiler will solve it out b

Re: I'm getting an unhelpful linker error, what've I got wrong?

2015-10-28 Thread pineapple via Digitalmars-d-learn
On Wednesday, 28 October 2015 at 12:06:14 UTC, Kagamin wrote: On Wednesday, 28 October 2015 at 11:48:27 UTC, pineapple wrote: There's also a writebuffer method in the interface with this signature, though: streamint writebuffer(T)(in T* buffer, in streamint count); Interface can't have t

Function accepting variadic arguments

2016-01-20 Thread pineapple via Digitalmars-d-learn
I'd like to make a constructor which takes a variable list of arguments, of a short list of possible types, with different handling depending on the type. I haven't been able to find any documentation or examples that did quite what I'm trying to. Help? A fun pseudocode example of what I'm try

Re: Function accepting variadic arguments

2016-01-20 Thread pineapple via Digitalmars-d-learn
On Wednesday, 20 January 2016 at 12:56:51 UTC, Ali Çehreli wrote: And there is another example here: http://ddili.org/ders/d.en/templates_more.html#ix_templates_more.tuple%20template%20parameter Ali Thank you! What's the purpose of "is" in the type checks? Also, how would I utilize isNumer

Error using templates: "cannot use template to add field to aggregate ''"

2016-01-25 Thread pineapple via Digitalmars-d-learn
I'm getting several of these since I'm trying to do the same thing in a few places. Here's a complete error: path\to\file.d(55): Error: variable units.unitvalue.opmethod!("sum(in unitvalue value)", "add(value)").methodtemplate cannot use template to add field to aggregate 'unitvalue'

Re: Error using templates: "cannot use template to add field to aggregate ''"

2016-01-25 Thread pineapple via Digitalmars-d-learn
Thanks so much for the help! I'm still getting used to D's compile-time code.

Not getting expected behavior from compile-time conditional

2016-01-26 Thread pineapple via Digitalmars-d-learn
Here's a simple programming showing where I'm tripping up - void test(T)(in T value){ import std.traits; static if(is(T == char)){ writeln("char"); }else static if(is(isNumeric!(T))){ writeln("number"); } writeln("hi"); } public void main(){ test('g');

Re: Not getting expected behavior from compile-time conditional

2016-01-26 Thread pineapple via Digitalmars-d-learn
On Wednesday, 27 January 2016 at 00:17:18 UTC, Ali Çehreli wrote: Remove the extra is: :) Huh, I swear I tried that. Thanks!

Non-English characters in code - "character 0x2212 is not a valid token"

2016-01-28 Thread pineapple via Digitalmars-d-learn
I experimented with using the character 'ħ' in a variable name, and wasn't terribly surprised when the compiler didn't like it. What did surprise me is that I still got a compile error even when the character was in a comment. Is there any way to make dmd not get fussy about unicode?

Re: Non-English characters in code - "character 0x2212 is not a valid token"

2016-01-28 Thread pineapple via Digitalmars-d-learn
On Thursday, 28 January 2016 at 13:18:55 UTC, pineapple wrote: I experimented with using the character 'ħ' in a variable name, and wasn't terribly surprised when the compiler didn't like it. What did surprise me is that I still got a compile error even when the character was in a comment. Is th

Can't run unit tests on Win7 64-bit?

2016-01-28 Thread pineapple via Digitalmars-d-learn
I have a super simple D file that looks like this: unittest{ import std.stdio; writeln("hello"); } On OSX Mavericks I run "rdmd --main -unittest test.d" and I get a nice "hello" and everything is well. On Win7 64-bit I run "> rdmd --main -unittest test.d" and rdmd seems to hang. It n

Overriding opEquals in classes, for comparison with things that aren't Objects

2016-01-29 Thread pineapple via Digitalmars-d-learn
With this bit of code, the first method seems to work fine - things go as expected. But I get a compile error with the second method, and I'm not sure how else to write this. override bool opEquals(Object value) const{ return this.equals(cast(typeof(this)) value); } override

Re: Overriding opEquals in classes, for comparison with things that aren't Objects

2016-01-29 Thread pineapple via Digitalmars-d-learn
It also occurred to me to do something like this, but it isn't accepted either. override bool opEquals(T)(T value){ return this.equals(value); }

Re: Overriding opEquals in classes, for comparison with things that aren't Objects

2016-01-29 Thread pineapple via Digitalmars-d-learn
On Friday, 29 January 2016 at 15:13:45 UTC, Mike Parker wrote: The first implementation is fine because you're overriding the implementation in the base class (Object). However, the second one fails because it's a template. Templates are non-virtual and cannot override anything. Even if you cou

String joining an array of structs or class instances implementing toString?

2016-02-11 Thread pineapple via Digitalmars-d-learn
It feels like there should be an out-of-the box way to do this but I haven't been able to find it? Help? This is the thing that I want to do: struct example{ const string str; //this(string str){ this.str = str; } string toString(){ return this.str; } } public void main

Re: String joining an array of structs or class instances implementing toString?

2016-02-11 Thread pineapple via Digitalmars-d-learn
Oh pardon the constructor I was playing with as a learning experience and forgot to get rid of.

Re: String joining an array of structs or class instances implementing toString?

2016-02-11 Thread pineapple via Digitalmars-d-learn
On Thursday, 11 February 2016 at 12:53:20 UTC, Edwin van Leeuwen wrote: I'd do it like this: import std.algorithm : map; pars.map!((part) => part.toString) // Turn them to strings .join(" ").writeln; // Join them. Thanks! Does the map function iterate without constructing an extra list in-me

Using a macro for a function signature

2016-04-05 Thread pineapple via Digitalmars-d-learn
If I have a common function signature I'm using throughout my code, and I feel like there should be a way to condense it using a macro. The intuitive method isn't working, but this seems like something D would be able to do. What've I got wrong in this example? alias somelongsignature = int

Re: Using a macro for a function signature

2016-04-05 Thread pineapple via Digitalmars-d-learn
Ah, aside from the mismatched "examplefunc" numbers - please disregard Can't post example code without stupid typos for the life of me

Re: Using a macro for a function signature

2016-04-05 Thread pineapple via Digitalmars-d-learn
On Tuesday, 5 April 2016 at 13:17:38 UTC, Anonymouse wrote: You can't get rid of the signature completely as the functions still need a parameter list with x declared. You will get "Error: undefined identifier 'x'" otherwise. You can largely omit the *type* of x if it can be inferred from the s

Re: overriding methods

2016-04-05 Thread pineapple via Digitalmars-d-learn
On Tuesday, 5 April 2016 at 18:54:39 UTC, stunaep wrote: I had no error on the examples I posted, only when using @Override previously. It just says to use override attribute instead of @Override Unlike in Java, D's override indicator doesn't look like an annotation, it's just a keyword place

Putting things in an enum's scope

2016-04-06 Thread pineapple via Digitalmars-d-learn
Is there any way in D to define static methods or members within an enum's scope, as one might do in Java? It can sometimes help with code organization. For example, this is something that coming from Java I'd have expected to be valid but isn't: enum SomeEnum{ NORTH, SOUTH, EAST, WEST;

Practical difference between a struct with const members and with mutable members?

2016-04-09 Thread pineapple via Digitalmars-d-learn
I'm mainly coming from languages that haven't got structs, let alone the kind of differentiation D offers between mutable/immutable/const/etc variables, so I'm still trying to work out just when to use each - What's different between these two examples, practically speaking? When would you use

Why do my stack traces look like this? How can I get more informative ones?

2016-04-09 Thread pineapple via Digitalmars-d-learn
I'm getting a RangeError and the stack trace is being spectacularly unhelpful in debugging the problem, because it looks like this: core.exception.RangeError@E:\Dropbox\Projects\d\lib\wip_ansi_2.d(78): Range violation 0x0040A240 0x00402E37 0x00402B5E 0x00402985 0x00402F29 0x0

Re: Why do my stack traces look like this? How can I get more informative ones?

2016-04-09 Thread pineapple via Digitalmars-d-learn
On Sunday, 10 April 2016 at 00:48:23 UTC, pineapple wrote: How can I fix this, and get something human-readable? Oh, answered my own question. Appending the -g flag to dmd options makes the stack trace much prettier.

How to run unit tests on Windows?

2016-04-14 Thread pineapple via Digitalmars-d-learn
I've had success running unit tests on OSX by running `rdmd --main -unittest [file]` but have had no such luck on Windows. The aforementioned command fails, and `dmd [file] -main -unittest` seems to run the program without actually executing the unit tests. Help?

Re: How to run unit tests on Windows?

2016-04-14 Thread pineapple via Digitalmars-d-learn
On Thursday, 14 April 2016 at 10:50:00 UTC, ag0aep6g wrote: Invoked like that, dmd doesn't run the program at all. It just makes an .exe file of it. To run the program simply type its name into the command prompt. So if your source file is foo.d, `dmd foo.d -main -unittest` creates foo.exe, and

Accessing __FILE__ and __LINE__ of caller in combination with varargs?

2016-04-15 Thread pineapple via Digitalmars-d-learn
I've written a very handy assertf method whose signature looks like this: void assertf(Args...)(lazy bool condition, in string message, Args args) But I'd also like to access the caller's file and line to use them in constructing a thrown AssertError, and I'm stumbling on how I can get that

Re: Accessing __FILE__ and __LINE__ of caller in combination with varargs?

2016-04-15 Thread pineapple via Digitalmars-d-learn
On Friday, 15 April 2016 at 20:52:42 UTC, WebFreak001 wrote: void assertf(string file = __FILE__, size_t line = __LINE__, Args...)(lazy bool condition, in string message, Args args) { Aha, you are the best. Thanks!

Method doesn't compile when defined in a mixin, but is fine without?

2016-05-01 Thread pineapple via Digitalmars-d-learn
I'm working on an SDL wrapper based on the derelict sdl2 and opengl3 bindings and so I've got a method like this I wrote: @property Vector2!int minsize(){ int x, y; SDL_GetWindowMinimumSize(this.window, &x, &y); return Vector2!int(x, y); } I've got several almost identical methods f

Re: Method doesn't compile when defined in a mixin, but is fine without?

2016-05-01 Thread pineapple via Digitalmars-d-learn
Strangely, though I'm getting this error when wrapping SDL_GetWindowMinimumSize and SDL_GetWindowMaximumSize, I don't get any compilation errors wrapping the identically-signatured SDL_GetWindowSize and SDL_GetWindowPosition using the same mixin.

Re: Method doesn't compile when defined in a mixin, but is fine without?

2016-05-01 Thread pineapple via Digitalmars-d-learn
On Sunday, 1 May 2016 at 13:46:14 UTC, ag0aep6g wrote: On 01.05.2016 15:32, pineapple wrote: static string vectorpropertymixin(string name, string SDL_getter, string SDL_setter){ [...] mixin(vectorpropertymixin( "minsize", "SDL_GetWindowMinimumSize", "SDL_GetWindowMinimumSize" )); Sh

Re: what's the right way to get char* from string?

2016-05-05 Thread pineapple via Digitalmars-d-learn
On Thursday, 5 May 2016 at 07:49:46 UTC, aki wrote: Hello, When I need to call C function, often need to have char* pointer from string. This might help: import std.traits : isSomeString; import std.string : toStringz; extern (C) int strcmp(char* string1, char* string2); int strcmpD0(S)(in

Compiler silently ignores some method overloads

2016-05-08 Thread pineapple via Digitalmars-d-learn
In my struct I have some methods with these signatures: void opIndexAssign(T)(in GLColor!T color, in int x, in int y) void opIndexAssign(T1, T2)(in GLColor!T1 color, in Vector2!T2 vector) void opIndexAssign(in uint value, in int x, in int y) And when I try to do this: thing[2,

Re: Compiler silently ignores some method overloads

2016-05-09 Thread pineapple via Digitalmars-d-learn
On Monday, 9 May 2016 at 00:27:17 UTC, Peter Häggman wrote: Can you show your GLColor struct ? Maybe it contains an alias this or something else that mess the overload resolution. My GLColor struct: http://pastebin.com/mUcA6G85

Re: Compiler silently ignores some method overloads

2016-05-10 Thread pineapple via Digitalmars-d-learn
On Monday, 9 May 2016 at 18:56:15 UTC, Peter Häggman wrote: No problem here (tested with everything in a single module). I can't help more. Front end version ? Well, this is the full struct that has those malfeasant overrides: http://pastebin.com/9h2s028J

Re: Compiler silently ignores some method overloads

2016-05-10 Thread pineapple via Digitalmars-d-learn
On Tuesday, 10 May 2016 at 09:57:11 UTC, pineapple wrote: On Monday, 9 May 2016 at 18:56:15 UTC, Peter Häggman wrote: No problem here (tested with everything in a single module). I can't help more. Front end version ? Well, this is the full struct that has those malfeasant overrides: http://

Confusion with anonymous functions and method overloads

2016-05-21 Thread pineapple via Digitalmars-d-learn
I wrote a pair of methods that looked like this: void clean(in void delegate(in T value) func){ this.clean((in T values[]) => { foreach(value; values) func(value); }); } void clean(in void delegate(in T values[]) func){ ... } I was getting a co

What's wrong with my usage of std.algorithm.map in this code example?

2016-05-24 Thread pineapple via Digitalmars-d-learn
I would've expected this to work, but instead I get a compile error. Is my syntax wrong? Is this just not a case that map can handle, and I should be doing something else? import std.algorithm : map; import std.conv : to; import std.stdio : writeln; import std.string : join;

Re: What's wrong with my usage of std.algorithm.map in this code example?

2016-05-25 Thread pineapple via Digitalmars-d-learn
On Tuesday, 24 May 2016 at 20:18:34 UTC, Steven Schveighoffer wrote: Slice assignment from range to array is not supported. In your example, I'm curious why the efforts to specify the type? I think it would work with just saying auto itemstrings = ... -Steve I still get an error if I use a

I wrote a function that accepts input ranges, and I get compile errors when passing an array

2016-05-27 Thread pineapple via Digitalmars-d-learn
I'm writing my own map function modeled after the one in phobos. (because I feel like it, that's why. good learning experience.) I've encountered one remarkable difference: The phobos function accepts arrays and mine does not. I understand why - I'm calling methods that arrays don't have - but

Re: I wrote a function that accepts input ranges, and I get compile errors when passing an array

2016-05-28 Thread pineapple via Digitalmars-d-learn
On Saturday, 28 May 2016 at 16:25:02 UTC, Seb wrote: If you are interested how it works under the hood - it's pretty simple & elegant: I checked up on the phobos implementation and found that arrays are mutated when iterated over as ranges, which didn't rest well with me. Nor did the idea of

Keeping a mutable reference to a struct with immutable members

2016-05-29 Thread pineapple via Digitalmars-d-learn
I found another post on this subject and the advice there was "don't put const members in your structs" - http://forum.dlang.org/thread/m87ln2$idv$1...@digitalmars.com This doesn't work out so well when the templated struct is referring to what happens to be a const array. I thought I could

Re: Keeping a mutable reference to a struct with immutable members

2016-05-29 Thread pineapple via Digitalmars-d-learn
On Sunday, 29 May 2016 at 18:52:36 UTC, pineapple wrote: What's the best way to handle something like this? Well I did get something to work but it's ugly and I refuse to believe there isn't a better way to handle this. Where `Range` is an alias to a struct with an immutable member, and `th

Re: Keeping a mutable reference to a struct with immutable members

2016-05-29 Thread pineapple via Digitalmars-d-learn
On Sunday, 29 May 2016 at 19:52:37 UTC, Basile B. wrote: Do yo have a simple, concise runnable example to show ? This is the example I was using to test solutions, it's similar to where I encountered the problem in the first place import core.stdc.stdlib : malloc, free; import std.st

Re: Why aren't overloaded nested functions allowed?

2016-05-30 Thread pineapple via Digitalmars-d-learn
On Monday, 30 May 2016 at 16:22:26 UTC, Max Samukha wrote: From the spec (https://dlang.org/spec/function.html#nested): "Nested functions cannot be overloaded." Anybody knows what's the rationale? I'm guessing it's related to - Unlike module level declarations, declarations within function

Re: Operator overloading through UFCS doesn't work

2016-05-30 Thread pineapple via Digitalmars-d-learn
Here's one more vote for extending UFCS to operator overloading. Elie wrote that it's "a restriction that seems pointless and arbitrary"... which summarizes my own thoughts rather well, too. There are certainly concerning scenarios that can arise from making this change, but the correct way to

Getting the parameters and other attributes belonging to the function overload with the greatest number of arguments

2016-05-31 Thread pineapple via Digitalmars-d-learn
I'd like to find the overload of some function with the most parameters and (in this specific case) to get their identifiers using e.g. ParameterIdentifierTuple. There have also been cases where I'd have liked to iterate over the result of Parameters!func for each overload of that function. Can

Re: Getting the parameters and other attributes belonging to the function overload with the greatest number of arguments

2016-05-31 Thread pineapple via Digitalmars-d-learn
On Tuesday, 31 May 2016 at 20:46:37 UTC, Basile B. wrote: Yes this can be done, you must use the getOverload trait: https://dlang.org/spec/traits.html#getOverloads The result of this trait is the function itself so it's not hard to use, e.g the result can be passed directly to 'Parameters', '

Unittests run without error when done individually, but when unittesting the package some fail

2016-06-01 Thread pineapple via Digitalmars-d-learn
How this could possibly be happening is confounding me and I have no idea if it's something I missed or some contrived compiler bug. This is the package.d that previously I've compiled with unittest every so often as a way of doing regression testing - https://github.com/pineapplemachine/mach.

Is it possible to use a template to choose between foreach and foreach_reverse?

2016-06-04 Thread pineapple via Digitalmars-d-learn
It would be fantastic if I could write this - static if(forward){ foreach(item; items) dostuff(); }else{ foreach_reverse(item; items) dostuff(); } as something like this - foreach!forward(item; items) dostuff(); Is there any way to accomplish this?

Re: Is it possible to use a template to choose between foreach and foreach_reverse?

2016-06-04 Thread pineapple via Digitalmars-d-learn
On Saturday, 4 June 2016 at 15:43:01 UTC, Mihail K wrote: As far as I recall, foreach_reverse is deprecated in favour of range operations. ie. import std.algorithm, std.range; static if(forward) { items.each!(item => doStuff()); } else { items.retro.each!(item => doStuf

Re: how to get rid of "cannot deduce function from argument types" elegantly

2016-06-14 Thread pineapple via Digitalmars-d-learn
On Monday, 13 June 2016 at 22:54:13 UTC, Ali Çehreli wrote: Tree!T tree(TL, T, TR)(TL left, T node, TR right) { return new Tree!T(left, node, right); } There's also this: Tree!T tree(TL, T, TR)(TL left, T node, TR right) if( (is(TL == Tree!T) || is(TL == typeof(null))) &&

Re: How to call one static method from another?

2016-06-14 Thread pineapple via Digitalmars-d-learn
On Tuesday, 14 June 2016 at 07:35:36 UTC, Andrea Fontana wrote: Simply: method2(); Also, typeof(this).method2();

Passing anonymous templated functions as template parameters

2016-06-15 Thread pineapple via Digitalmars-d-learn
Here's a simple code example to illustrate what I expected to work and didn't - is this a mistake in my syntax or a limitation of the language? template SomeTemplate(alias func){ auto templatefunc(T)(int x){ return func!T(x); } } // Valid auto somefu

Shorthand for defining numeric literals as size_t and ptrdiff_t

2016-06-23 Thread pineapple via Digitalmars-d-learn
There are suffixes for numbers like 0L, 0u, 0f, 0d, etc. What about suffixes representing size_t and ptrdiff_t? Do they exist? If not, why?

Typesafe variadic functions requiring at least one argument

2016-07-06 Thread pineapple via Digitalmars-d-learn
I'd like to do something like this but it doesn't seem to be legal - void test(int[] ints...) if(ints.length){ // stuff } Not being able to specify this interferes with how I'd like to define my method overloads. What's the best way to achieve what I'm looking for?

Re: Typesafe variadic functions requiring at least one argument

2016-07-07 Thread pineapple via Digitalmars-d-learn
On Thursday, 7 July 2016 at 03:52:40 UTC, Jonathan M Davis wrote: However, it looks like you can combine those two types of variadic functions to get more or less what you want (albeit more verbosely). e.g. template isInt(T) { enum isInt = is(std.traits.Unqual!T == int); } void test(Args..

Defining and overriding methods of an abstract base class which must accept a template parameter

2016-07-10 Thread pineapple via Digitalmars-d-learn
This is essentially what I'm trying to accomplish. The intuitive solution, of course, does not work. In theory I could write a separate method for every anticipated return type, but that would be horrible and in that case I'd probably just write the damn thing in a dynamically-typed language in

Re: Defining and overriding methods of an abstract base class which must accept a template parameter

2016-07-10 Thread pineapple via Digitalmars-d-learn
On Sunday, 10 July 2016 at 21:20:34 UTC, Basile B. wrote: The problem you encounter here is that templatized functions cannot be virtual. If you remove "abstract" and put an empty body than it works, but you lose the whole OOP thing, i.e you cannot call the most derived override from the base.

Interface final methods are erased by the overloads of a subclass

2016-07-13 Thread pineapple via Digitalmars-d-learn
I was surprised when this didn't work. What's the rationale? Is there any better workaround than renaming methods? interface A{ void foo(); final void foo(int x){} } class B: A{ void foo(){} } void main(){ auto b = new B(); b.foo();

Re: to auto or not to auto ( in foreach )

2016-07-16 Thread pineapple via Digitalmars-d-learn
On Saturday, 16 July 2016 at 22:05:49 UTC, ketmar wrote: actually, `foreach (v; rng)` looks like `foreach` is *reusing* *existing* *variable*. most of the time you can put `immutable` or something like that there to note that it is not reusing (purely cosmetical thing), but sometimes you cannot

Re: to auto or not to auto ( in foreach )

2016-07-16 Thread pineapple via Digitalmars-d-learn
On Sunday, 17 July 2016 at 01:57:21 UTC, pineapple wrote: On Saturday, 16 July 2016 at 22:05:49 UTC, ketmar wrote: actually, `foreach (v; rng)` looks like `foreach` is *reusing* *existing* *variable*. most of the time you can put `immutable` or something like that there to note that it is not

Re: shuffle a character array

2016-07-20 Thread pineapple via Digitalmars-d-learn
On Wednesday, 20 July 2016 at 08:02:07 UTC, Mike Parker wrote: You can then go to the documentation for std.range.primitives.isRandomAccessRange [2], where you'll find the following: "Although char[] and wchar[] (as well as their qualified versions including string and wstring) are arrays, i

Re: shuffle a character array

2016-07-20 Thread pineapple via Digitalmars-d-learn
On Wednesday, 20 July 2016 at 13:33:34 UTC, Mike Parker wrote: There is no auto-decoding going on here, as char[] and wchar[] are rejected outright since they are not considered random access ranges. They are considered random access ranges by my ranges library, because they are treated as ar

Re: shuffle a character array

2016-07-20 Thread pineapple via Digitalmars-d-learn
On Wednesday, 20 July 2016 at 16:03:27 UTC, pineapple wrote: On Wednesday, 20 July 2016 at 13:33:34 UTC, Mike Parker wrote: There is no auto-decoding going on here, as char[] and wchar[] are rejected outright since they are not considered random access ranges. They are considered random acces

Re: shuffle a character array

2016-07-20 Thread pineapple via Digitalmars-d-learn
On Wednesday, 20 July 2016 at 16:04:50 UTC, pineapple wrote: On Wednesday, 20 July 2016 at 16:03:27 UTC, pineapple wrote: On Wednesday, 20 July 2016 at 13:33:34 UTC, Mike Parker wrote: There is no auto-decoding going on here, as char[] and wchar[] are rejected outright since they are not consid

Re: shuffle a character array

2016-07-21 Thread pineapple via Digitalmars-d-learn
On Wednesday, 20 July 2016 at 18:32:15 UTC, Jesse Phillips wrote: I think you mean that your range library treats them as arrays of code units, meaning your library will break (some) unicode strings. Right - I disagree with the assessment that all (or even most) char[] types are intended to r

Verifying the arguments of a function with ref parameters?

2016-07-28 Thread pineapple via Digitalmars-d-learn
Why doesn't this code do what I'd expect it to, and how can I fix it? unittest{ import std.traits : Parameters; // Works as expected alias dg = int delegate(int value); enum bool dgcallable = is(typeof((){dg(Parameters!dg.init);})); pragma(msg, dgcal

Re: Verifying the arguments of a function with ref parameters?

2016-07-28 Thread pineapple via Digitalmars-d-learn
On Thursday, 28 July 2016 at 20:28:39 UTC, jdfgjdf wrote: "Parameters!dgref.init" does not yield a reference. The real error is not displayed. In a normal context it would be "stuff is not callable with" What would be a better way to check whether some callable can be called using a param

Re: Verifying the arguments of a function with ref parameters?

2016-07-28 Thread pineapple via Digitalmars-d-learn
On Thursday, 28 July 2016 at 21:49:00 UTC, pineapple wrote: On Thursday, 28 July 2016 at 20:28:39 UTC, jdfgjdf wrote: "Parameters!dgref.init" does not yield a reference. The real error is not displayed. In a normal context it would be "stuff is not callable with" What would be a better wa

Re: string mixin and alias

2016-07-29 Thread pineapple via Digitalmars-d-learn
On Friday, 29 July 2016 at 06:38:17 UTC, Andre Pany wrote: Hi, is there a way to alias a string mixin? Neither foo nor foo2 compiles. import std.meta : Alias; alias foo = (s) => Alias!(mixin(generateCode(s))); alias foo2(string s) = Alias!(mixin(generateCode(s))); string generateCode(string s)

Re: string mixin and alias

2016-07-29 Thread pineapple via Digitalmars-d-learn
On Friday, 29 July 2016 at 12:22:54 UTC, Andre Pany wrote: It is more or less syntax sugar. In the main function instead of writing "mixin(generateCode(s));" I want to write "foo(s);". So, the mixin statement is hidden while the functionality of mixin stays. Kind regards André As far as I k

FunctionTypeOf behaves unexpectedly for function pointers?

2016-07-29 Thread pineapple via Digitalmars-d-learn
This failure seems curious and I haven't been able to understand why it occurs, or whether it might be intentional. For all other callable types, including functions and delegates and types implementing opCall, the assertion passes. import std.traits : FunctionTypeOf; void function() f

Re: FunctionTypeOf behaves unexpectedly for function pointers?

2016-08-01 Thread pineapple via Digitalmars-d-learn
On Saturday, 30 July 2016 at 12:54:32 UTC, Basile B. wrote: func is a pointer to a function but FunctionTypeOf extracts the target type. So the correct assertion is static assert(is(FunctionTypeOf!func* == typeof(func))); I can't believe that it worked for delegates because the same happe

Re: Why Does Dscanner Warn About a Missing toHash if opEquals is Defined?

2016-08-01 Thread pineapple via Digitalmars-d-learn
On Sunday, 31 July 2016 at 18:57:50 UTC, Jack Stouffer wrote: Next question: what's the fastest hashing implementation that will provide the least collisions? Is there a hash implementation that's perfered for AAs? There's no hashing function that would be specifically better for associative

Re: minor question of the difference between " and '

2016-08-11 Thread pineapple via Digitalmars-d-learn
On Wednesday, 10 August 2016 at 23:32:54 UTC, WhatMeWorry wrote: Afterall, isn't that the definition of a string? So what's up with the two groupings of single quotes? http://www.howtogeek.com/howto/29980/whats-the-difference-between-single-and-double-quotes-in-the-bash-shell/

Re: compile error while use `extern(C++, class)`

2016-08-18 Thread pineapple via Digitalmars-d-learn
On Thursday, 18 August 2016 at 11:43:03 UTC, Lodovico Giaretta wrote: On Thursday, 18 August 2016 at 11:11:10 UTC, mogu wrote: On Thursday, 18 August 2016 at 10:45:14 UTC, Lodovico Giaretta wrote: Which kind of error? An error message by the compiler? One by the linker? The compiler crashes?

Does D have any construct like Python's with keyword?

2016-08-26 Thread pineapple via Digitalmars-d-learn
I've grown to very much appreciate how context initialization and teardown can be very conveniently handled using `with` in Python. Is there any clean way to imitate this syntax in D?

Re: Does D have any construct like Python's with keyword?

2016-08-26 Thread pineapple via Digitalmars-d-learn
On Friday, 26 August 2016 at 23:30:15 UTC, Cauterite wrote: On Friday, 26 August 2016 at 23:28:27 UTC, pineapple wrote: I've grown to very much appreciate how context initialization and teardown can be very conveniently handled using `with` in Python. Is there any clean way to imitate this synt

  1   2   >