Re: C Macro deeper meaning?

2016-01-30 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 31 January 2016 at 02:58:28 UTC, Andrew Edwards wrote: But it cannot be that simple, so what am I missing? I'm guessing the macro was there in C to silence compiler warnings about not using a return value. So I think your translation is ok: NOTUSED(somefunction()); still

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

2016-01-28 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 28 January 2016 at 14:39:46 UTC, sigod wrote: I tried to compile your code on dpaste (2.070.0) and got this: dpaste has an input mangling bug with some characters as a result of the form submission over the web.

Re: What is the best declaration type for a string like parameter?

2016-01-28 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 28 January 2016 at 13:36:46 UTC, Puming wrote: I searched the forum and found that people use `const(char)[]` or `in char[]` to accept both string and char[] arguments. There's also the hyper-generic signatures Phobos uses like void foo(S)(S s) if(isSomeString!S) and the input

Re: tell if __traits(allMembers, ... ) is an enum (not manifest constant)

2016-02-24 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 25 February 2016 at 04:25:25 UTC, Nicholas Wilson wrote: foreach(m; __traits(allMembers, ...) { static if(is(m== enum)) } That's close but not quite there... try static if(is(typeof(__traits(getMember, Item, m)) == enum)) for member variables, or if you are looking at a

Re: How to detect if an array if dynamic or static

2016-02-24 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 25 February 2016 at 01:31:17 UTC, Chris Wright wrote: When you get to GC-allocated stuff, there's no way to tell. The GC is easy, you can simply ask it: http://dpldocs.info/experimental-docs/core.memory.GC.addrOf.1.html "If p references memory not originally allocated by this

Re: Initialize associate array

2016-02-29 Thread Adam D. Ruppe via Digitalmars-d-learn
Use a constructor instead.

Re: static init of associative array of enums not working.. why?

2016-02-26 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 27 February 2016 at 04:37:24 UTC, Øivind wrote: Should I file a ticket for this? It is already known, just nobody has fixed it yet (and probably won't for a long time still)

Re: static init of associative array of enums not working.. why?

2016-02-26 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 27 February 2016 at 04:15:06 UTC, Øivind wrote: Shouldn't this work? According to "Static Initialization of AAs" on this page, it should: https://dlang.org/spec/hash-map.html It just isn't implemented in the compiler. Instead, you can declare it outside and set it in a static

Re: arsd.dom getElementsByTagNameChildrenOnly?

2016-02-23 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 23 February 2016 at 11:10:17 UTC, Nicholas Wilson wrote: How do I iterate over the child level elements only (ignoring the ones like VkStructureType)? Element.childNodes gives only direct children. You could also do document.querySelectorAll("types > type") to get only the tags

Re: Can D "prevents segfaults, and guarantees thread safety"?

2016-02-22 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 23 February 2016 at 04:28:14 UTC, mahdi wrote: A selling point of Rust language is that it "prevents segfaults, and guarantees thread safety". Is there a library in D language which provides same features? The core d runtime (including the garbage collector) does such things.

Re: how to initialise const variables

2016-02-25 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 26 February 2016 at 02:32:44 UTC, Nicholas Wilson wrote: struct A { const (void *) p; } struct B { Aa; this(void * _p) { a.p = _p; } } I cannot change the definition of A how do I initialise b.a.p? Use a constructor for A instead of trying to write

Re: How to detect if an array if dynamic or static

2016-02-24 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 24 February 2016 at 21:48:14 UTC, mahdi wrote: How can we detect is `array` is static (fixed size) or dynamic, inside the function body? `array` there is always dynamic because it is not of a fixed size type. Why do you want to know though?

Re: Is this a feature?

2016-01-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 21 January 2016 at 14:35:09 UTC, Sebastiaan Koppe wrote: static if (!is(SomethingUndefined!moreUndefined[0] : UndefinedThing)) Yes, the is expression returns false for undefined things because they aren't types. The standard library uses this in a lot of places to test for

Re: Possible to get Class of Interface at runtime

2016-01-22 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 22 January 2016 at 23:38:58 UTC, Josh Phillips wrote: Is there any way that I can find out what class obj is inside of printClass? There's a .classinfo property that works on Objects. If you have an interface, cast to Object first, and check for null, then get .classinfo off that.

Re: is there a set container?

2016-01-25 Thread Adam D. Ruppe via Digitalmars-d-learn
The std.container.RedBlackTree is close: http://dlang.org/phobos/std_container_rbtree.html Or you may prefer my work-in-progress unofficial docs: http://dpldocs.info/experimental-docs/std.container.rbtree.RedBlackTree.html You can see methods there like insert, removeKey, and opBinaryRight,

Re: Distribution of D apps

2016-01-20 Thread Adam D. Ruppe via Digitalmars-d-learn
By default, a binary compiled with D will have the standard library statically linked in, so all you need to distribute are other shared libs you choose to use (which might include curl btw if you use the std.net.curl functions). But many .exes from D can be distributed alone and expected to

Re: Possible to get Class of Interface at runtime

2016-01-23 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 23 January 2016 at 21:03:21 UTC, Josh Phillips wrote: I tried this but it will return A not B Are you sure you correctly casted first?

Re: Can't add ubytes together to make a ubyte... bug or feature?

2016-01-19 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 19 January 2016 at 22:12:06 UTC, Soviet Friend wrote: I don't care if my computer needs to do math on a 4 byte basis, I'm not writing assembly. x86 actually doesn't need to do math that way, if you were writing assembly, it would just work. This is just an annoying rule brought

Re: D ASM. Program fails

2016-01-22 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 22 January 2016 at 12:18:53 UTC, anonymous wrote: I don't know much about these things, but it seems to be the `ret;`. Right. This is an ordinary D function so the compiler generates code to set up a stack for local variables. It looks like: push ebp; mov ebp, esp; sub EBP,

Re: Difference between toLower() and asLowerCase() for strings?

2016-01-24 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 24 January 2016 at 20:56:20 UTC, Jon D wrote: I'm trying to identify the preferred ways to lower case a string. In std.uni there are two functions that return the lower case form of a string: toLower() and asLowerCase(). There is also toLowerInPlace(). toLower will allocate a new

Re: Duration at runtime

2016-02-18 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 19 February 2016 at 04:08:02 UTC, Zekereth wrote: How is seconds able to be read at compile time but unitType cannot? "seconds" is a literal value that the compiler knows about. unitType is a variable that might change between its declaration and use (it doesn't here, but the

Re: D Grammar Parser In D

2016-02-19 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 19 February 2016 at 22:29:32 UTC, Patience wrote: Is there anything in D like https://irony.codeplex.com/ https://github.com/Hackerpilot/libdparse/

Re: 111

2016-02-19 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 20 February 2016 at 00:42:36 UTC, Chris Wright wrote: How do you calculate the area of a triangle? Same way as you'd do it by hand -- 1/2 base times height. Getting the height can be tricky sometimes though, depending on what information you know about the triangle. I like to

Re: What happens if memory allocation fails?

2016-02-20 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 20 February 2016 at 14:21:28 UTC, tcak wrote: What happens if memory allocation fails with "new" keyword? Be aware that memory allocation might never actually fail. It really depends on the operating system. But if it did fail, it would throw OutOfMemoryError

Re: compilation issues (dmd, rdmd, ldc2)

2016-02-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 21 February 2016 at 21:51:27 UTC, kraxli wrote: a) doesn't work, I need to search for more information on linking as I would like to understand these kind of basics in D :-). The books I consulted so far (Learn D and D cookbook) did not help me to understand the linking so far ...

Re: wrapSocket for socket_t? As wrapFile for FILE*

2016-02-13 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 14 February 2016 at 04:13:12 UTC, Beginner-8 wrote: Anyone seen Socket constructor which uses already available socket of socket_t type? See the list on my unofficial docs here: http://dpldocs.info/experimental-docs/std.socket.Socket.html This one does it:

Re: Backslash escaping weirdness

2016-02-29 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 1 March 2016 at 04:18:11 UTC, Nicholas Wilson wrote: What is causing these errors? I'm using \t and \n in string all over the place and they work. I don't think there's enough context to know for sure... but my guess is you forgot to close one of the quotes a couple lines above.

Re: Classes and CTFE

2016-03-10 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 10 March 2016 at 13:56:18 UTC, Andrea Fontana wrote: I used to think that classes can't be used with CTFE. Classes have worked normally with CTFE for several years now. You don't need to do anything special with them. Ex: http://dpaste.dzfl.pl/5879511dff02 This just doesn't

Re: Get address of object in constructor.

2016-03-13 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 13 March 2016 at 16:16:55 UTC, MGW wrote: void* thisAddr = cast(void*) This doesn't really make sense anyway, this is a local variable, you want to do cast(void*) this in a class if you need the address (which btw, you shouldn't actually, the reference itself ought to be enough)

Re: C.h to D conversion (structs)

2016-03-15 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 15 March 2016 at 16:32:56 UTC, Chris wrote: The error I get is something like undefined reference to `_D3test7testmodule13A6__initZ' undefined reference to `_D3test7testmodule13B6__initZ' You still need to compile/link in the module (or in this specific case, void initialize the

Re: C.h to D conversion (structs)

2016-03-15 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 15 March 2016 at 16:56:00 UTC, Chris wrote: Do you mean I need to void initialize them in the C code or in D? And if in D, how would I do that, with `static this`? in D, at the usage point with =void where you declare the variable of that type. So in your code: struct C { A a

Re: GC scan for pointers

2016-03-09 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 9 March 2016 at 15:14:02 UTC, Gerald Jansen wrote: will the large memory blocks allocated for a, b and/or c actually be scanned for pointers to GC-allocated memory during a garbage collection? If so, why? No. It knows that the type has no pointers in it, so it will not scan it

Re: Clearing associative array.

2016-03-12 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 12 March 2016 at 12:34:16 UTC, ciechowoj wrote: If above doesn't work how am I supposed to clear the array? `x = string[string].init;` is somewhat ugly. Read the Tip of the Week section here: http://arsdnet.net/this-week-in-d/dec-13.html Short answer: use `= null` to clear the

Re: Clearing associative array.

2016-03-12 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 12 March 2016 at 12:59:02 UTC, ciechowoj wrote: Nice article :), thanks. But still, what about clear()? In the documentation https://dlang.org/spec/hash-map.html#properties there is written that associative arrays have clear property. I don't think that actually works... might be

Re: Why does array loses it internal capacity on length change?

2016-03-12 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 12 March 2016 at 09:56:48 UTC, Uldis wrote: Why is this happening, how to avoid it? Details here: http://dlang.org/d-array-article.html it is so one slice can never stomp over the contents of another slice when you append to it. array.assumeSafeAppend() can override it.

Re: C.h to D conversion (structs)

2016-03-15 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 15 March 2016 at 18:04:00 UTC, Chris wrote: I'm not 100% sure what you mean with compile+link in the modules. Like you would another D library. The structs are all defined in the original (third party) C header file. It's nothing I added (in which case I would have to recompile

Re: asserting dmd has a problem?

2016-03-11 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 11 March 2016 at 18:45:12 UTC, Russel Winder wrote: The following code compiles fine using DMD 2.70.2: Using -release? Or catching the AssertError?

Re: How to be more careful about null pointers?

2016-03-28 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 28 March 2016 at 21:01:19 UTC, cy wrote: No exception raised for dereferencing a null. If it didn't give the error, either you swallowed it or you didn't actually dereference null. The latter is a kinda strange happenstance, but if you are calling a static or final method on an

Re: Async read an output stream but how many bytes ?

2016-03-30 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 31 March 2016 at 00:50:16 UTC, Basile B. wrote: There should be a way to know how many bytes are available ? You are already using poll()... I'd just use read() directly on the file number too. It will read as much as is available up to the max size of the buffer, but if it

Re: Get VTable pointer as a constant

2016-04-07 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 7 April 2016 at 20:43:04 UTC, Johan Engelen wrote: Does anybody know how to get the class's vtable pointer without doing a memory read? I don't think you can... why do you want it though?

Re: Unexpected Crash

2016-04-07 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 7 April 2016 at 20:42:17 UTC, default0 wrote: If I enter "5,5,5" on the commandline, hit enter, then enter "5,5,5" When you hit enter, that puts a \n character in the buffer. readf doesn't skip that automatically, so it complains upon hitting that newline (the error message

Re: overriding methods

2016-04-05 Thread Adam D. Ruppe 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 source\game\client.d(8,20): Deprecation: implicitly overriding base class method

Re: overriding methods

2016-04-05 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 5 April 2016 at 18:38:43 UTC, stunaep wrote: I get a deprecation warning with @Override, but I was unable to find the proper way to do it. What error message exactly are you getting and on what code? Both styles you put there should work equally well.

Re: Dynamic library

2016-04-11 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 11 April 2016 at 13:40:14 UTC, Chris wrote: For the record, I fixed it by changing the contents of libphobos2.so from How did you do that btw? The file there should really just be a link to some binary file, maybe it got mangled in copying at some point.

Re: Cancelling a stdin.read?

2016-04-11 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 10 April 2016 at 08:29:22 UTC, Lass Safin wrote: Thus, my question is: Is there any way to cancel the read from stdin prematurely from another thread, so that the thread can finish? What operating system are you on? I wouldn't be using threads for this at all, you might want to

Re: Cancelling a stdin.read?

2016-04-11 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 11 April 2016 at 14:57:27 UTC, Lass Safin wrote: I can't put it in one loop, since the window also has some autonomous features. Eh, my terminal.d and simpledisplay.d can combine event loops, you use a muliplexing function like select() on both the window and terminal so it waits

Re: Is it legal to use std.windows modules?

2016-04-11 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 8 April 2016 at 22:50:05 UTC, FreeSlave wrote: std.windows.syserror and others have documentation comments, but they are not listed in online documentation on dlang.org. Is it ok to use functions and classes from this modules in D applications? For what it is worth, my

Re: execute bash?

2016-04-08 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 8 April 2016 at 23:03:15 UTC, Puming wrote: Do you have this pseudo terminal thing in terminal.d? No, terminal.d is for your program to interact with the user's terminal rather than program to program stuff. My terminal emulator

Re: execute bash?

2016-04-08 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 8 April 2016 at 13:23:10 UTC, Adam D. Ruppe wrote: Odds are it is that there's terminal output for the background process NOT a character btw, just any output, then the OS puts you on hold so it can do its thing. To catch a signal, it is just like in C

Re: execute bash?

2016-04-08 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 8 April 2016 at 10:08:07 UTC, Puming wrote: but with each command loop, the program is stopped (equal to Ctrl-Z). Your program is stopped, right? Odds are it is that there's terminal output for the background process, which sends your program a signal which, by default, stops it.

Re: execute bash?

2016-04-08 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 8 April 2016 at 15:31:13 UTC, Puming wrote: The D version behavior is strange. Are you still calling bash? Cuz that is going to complicate things a lot because bash does its own signal handling too and could be intercepting it. When Using while with readln, after hitting Ctrl-C,

Re: execute bash?

2016-04-08 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 8 April 2016 at 15:20:09 UTC, Puming wrote: I tried with signal, but didn't catch SIGTTOU, it seems that spawnProcess with `bash -i -c` will signal with SIGTTIN. Oh, surely because it wants to be interactive and is thus waiting for user input from the terminal.. You might need to

Re: execute bash?

2016-04-08 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 8 April 2016 at 14:09:16 UTC, Puming wrote: I just found that you have terminal.d in arsd repo, are you writing a repl with it? I'm hoping I might be able to use it. I have done it before. terminal.d has a getline function and writeln functions you could loop over. Its getline has

Re: Some strange behaviors of enums and string.startsWith

2016-04-08 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 8 April 2016 at 14:38:10 UTC, Andre wrote: Therefore I use std.conv.text to convert the string enum? to string. That converts the *name* of the enum to string, not the contents. (BTW, I think the name of the enum is actually the more useful behavior.) Use cast(string) if you

Re: Getting the current module as a symbol

2016-04-12 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 12 April 2016 at 13:44:07 UTC, Mithun Hunsur wrote: I'm looking for the equivalent of `typeof(this)` in module scope (so that it gets the current module). The trick I use is `mixin(__MODULE__)`. I also mentioned this in my book

Re: Passing _arguments into another variadic function

2016-04-12 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 12 April 2016 at 09:08:06 UTC, Satoshi wrote: Is it possible to pass varargs to another function or must I do it by asm? In C, you would make a version of the function that takes the va_list type (see, for example, vprintf). I believe in D, you'd want to do the same thing. Make

Re: execute bash?

2016-04-09 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 10 April 2016 at 00:47:28 UTC, Puming wrote: 3. when hiting 'vim a.file' on the command, things go messy. Have you got these interactive commands work in dexpect? It is surely capturing exactly what vim sends to a terminal, which is primarily a series of control sequences to draw

Re: Putting things in an enum's scope

2016-04-06 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 6 April 2016 at 13:59:42 UTC, pineapple wrote: Is there any way in D to define static methods or members within an enum's scope, as one might do in Java? No. You could make a struct rather than an enum though with the methods, and a bunch of static things to simulate

Re: casting to a voldemort type

2016-03-19 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 19 March 2016 at 15:10:56 UTC, Alex wrote: void* funVoldemort(size_t my_size) The term 'voldemort type' refers to a public type, just an unnamed one. What you have here is a pointer to a private type... and void* is something you often should avoid since the compiler

Re: module renaming by declaration

2016-03-19 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 19 March 2016 at 16:02:33 UTC, Christof Schardt wrote: What am I doing wrong? Using rdmd. It assumes the filename will match the module name to locate the file, though the language itself doesn't require this. What you want to do to make this work is use ordinary dmd and pass

Re: Updating D-based apps without recompiling it

2016-03-23 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 23 March 2016 at 12:21:33 UTC, Ozan wrote: Has someone experience with handling upgrading/updating D-Apps on the fly? The way I always did it was to simply have old and new running side-by-side in the transition. So, without stopping the old version, compile the new one and

Re: getOverloads, but also include all the imported members

2016-03-24 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 24 March 2016 at 12:11:33 UTC, Marc Schütz wrote: On Wednesday, 23 March 2016 at 20:54:20 UTC, Yuxuan Shui wrote: module one; void func(int a){} / module two; import one; void func(float a){} Add in module two: alias func = one.func; Indeed, the two funcs

Re: getOverloads, but also include all the imported members

2016-03-24 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 24 March 2016 at 15:07:09 UTC, Yuxuan Shui wrote: Is there a way to do this automatically? No. You have to decide to bring them together if you want them to overload.

Re: Enabling Only Top-Level Unittests

2016-03-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 21 March 2016 at 15:15:41 UTC, Nordlöw wrote: This is because my project has grown beyond 30klines of code and at that scale not even D's speed is enough for getting fast incremental builds through dmd. Note that lines of code isn't really important to build time... $ time dmd -c

Re: Random Access I/O

2016-03-25 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 26 March 2016 at 00:10:23 UTC, Chris Williams wrote: None of the access modes for std.stdio.File seem to allow that. Any usage of the "w" mode causes my code to consider the file empty if it pre-exists (though, it doesn't always actually truncate the disk on file?) Mode "a+" or

Re: Variant.type bug ?

2016-03-23 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 23 March 2016 at 08:01:36 UTC, Voitech wrote: Hi Variant stores variant.type as not the "highest" in hierarchy. Yeah, it stores the static type. You can use it to get that then do a normal dynamic cast to test for a more derived type.

Re: parsing HTML for a web robot (crawler) like application

2016-03-23 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 23 March 2016 at 10:49:03 UTC, Nordlöw wrote: HTML-docs here: http://dpldocs.info/experimental-docs/arsd.dom.html Indeed, though the docs are still a work in progress (the lib is now about 6 years old, but until recently, ddoc blocked me from using examples in the comments so

Re: rawWrite of a struct suggestions

2016-03-25 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 25 March 2016 at 18:25:28 UTC, Charles Hixson wrote: But when I try to cast a Chnk to a ubyte[], I get an error, and rawWrite takes a generic array of anything... you should be able to rawWrite((_object)[0 .. 1])

Re: Needed return type in static method? bug or feature?

2016-03-08 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 8 March 2016 at 13:40:06 UTC, Antonio Corbi wrote: Is it a feature or a bug? It is allowed because the "auto" keyword doesn't actually required for auto functions (or variables), what you need is any one of the storage classes. Those include static, auto, const, immutable, even

Re: Is it safe to use 'is' to compare types?

2016-03-03 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 3 March 2016 at 23:46:50 UTC, Yuxuan Shui wrote: Will typeid(a) is typeid(b) yield different results than typeid(a) == typeid(b)? No. Indeed, opEquals on TypeInfo just calls is itself.

Re: Template mixins and struct constructors

2016-03-02 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 2 March 2016 at 12:27:04 UTC, Adrian Matoga wrote: Is it by design or is it a bug? And, if it is by design, what is the reason for that? That's by design. It allows you to override names from a template mixin like inheritance but no runtime cost. Read my tip of the week here

Re: Array Indexing/Slicing Range Checking, Exceptions and @nogc

2016-03-30 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 30 March 2016 at 13:12:49 UTC, Nordlöw wrote: I'm however uncertain about how to implement error handling of bounds checking and how these interact with `@nogc`. My main goal is to match semantics of builtin D arrays and slices. I would actually cheat on this somehow and

Re: foreach UFCS

2016-03-31 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 31 March 2016 at 13:39:25 UTC, ixid wrote: What is going on with UFCS and foreach? There's no such thing as UFCS on foreach. UFCS only works on variables, not a foreach statement. foreach(i;0..5).writeln; You can add a line break and optional braces there to see what it

Re: how to declare C's static function?

2016-03-28 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 28 March 2016 at 04:53:19 UTC, aki wrote: So... You mean there are no way to declare functions without exporting the symbol? alas, no, even if it is private it can conflict on the outside (so stupid btw). Is it all the same function being referenced? Just importing from there

Re: Using ffmpeg in command line with D

2016-03-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 21 March 2016 at 17:26:09 UTC, Karabuta wrote: I am new to this kind of multimedia stuff and all this is currently theoretical. Will this work and is it the right approach used by video convertor front-ends? Eh, it is how I did it before, it works and is pretty easy to do.

Re: C header file: tagged enumerations

2016-04-26 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 26 April 2016 at 23:33:08 UTC, Stefan Koch wrote: static if (win32msi >= 500) . Won't work here because static if must have a complete declaration inside it, and the C pattern only has a few elements of the whole inside each #if. D doesn't handle this C pattern well... you

Re: D GUI Toolkit Comparison

2016-04-29 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 29 April 2016 at 13:52:59 UTC, Nordlöw wrote: Could somebody briefly outline the different GUI toolkits available in D and how they differ especially in terms of cleverly the make use of all idioms available in the language aswell as in Phobos. For instance: DlangUI and Adams D

Re: What does alias do?

2016-04-23 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 23 April 2016 at 19:52:15 UTC, xtreak wrote: I just thought posting to forum will have more people to discuss on this. Sorry for the double post. There's no problem with posting to the forums and talking on IRC. Since the chat isn't searchable and disappears fast, the forums

Re: GC allocation

2016-04-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 21 April 2016 at 22:59:58 UTC, Alex wrote: Ok... I make slices of them, carefully avoiding to make copies... Yeah, that shouldn't make a difference.. Huh? I think, this is the place, where I lack some background... So, I bind my delegates via Can you post any more of your

Re: ErrorException thrown when errno is modified ?

2016-05-19 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 19 May 2016 at 13:05:19 UTC, chmike wrote: Checking the std.exception documentation I see that ErrnoException may be thrown when errors setting errno may occur. Does this affect the posix calls ? It just means the Phobos functions that use these functions (like std.file or

Re: Trying to get type and name at compile time

2016-05-24 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 24 May 2016 at 15:01:33 UTC, Edwin van Leeuwen wrote: // I expected AliasSeq!(double,"x")??? pragma(msg,test); // tuple((double), "x") What Phobos calls AliasSeq is called tuple inside the compiler. They are the same thing, just different names. static assert(is(test ==

Re: full copies on assignment

2016-05-24 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 24 May 2016 at 14:29:53 UTC, John Nixon wrote: This naively doesn’t seem right because the RHS of an assignment should not be altered by it. It's because the char[] being shallow copied still leads to mutable stuff. What I typically do here is just add a method `dup` to the

Re: Is there an easy way to convert a pointer to malloc'd memory to an array?

2016-05-24 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 24 May 2016 at 18:42:41 UTC, Gary Willoughby wrote: I have a T* pointer to the start of a malloc'd chunk of memory, the type T and the number of T's stored in the chunk. Is there an efficient way of converting this information to a D array of type T[] or even T[n]? Slice it:

Re: opDispatch and UFCS

2016-05-11 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 11 May 2016 at 23:46:48 UTC, John Colvin wrote: Bug? Or am I misunderstanding how these two features are supposed to interact? I'm not sure what you actually expected there, but I'd note that in general, opDispatch will always be preferred over UFCS, just like any other member

Re: Dynamically setting struct values from hash map

2016-05-12 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 12 May 2016 at 20:52:46 UTC, Andrew Chapman wrote: I have seen the "allMembers" method from the traits module that can give me the names of the struct fields, but I am unsure if it's even possible to set the struct values using variable/dynamic names. Yes. You can't loop over

Re: Abstract attribute ?

2016-05-17 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 17 May 2016 at 16:52:01 UTC, Lucien wrote: Why a attribute cannot be abstract ? Because it cannot be virtual and cannot be overridden. This is different than Python, but in line with other C-style languages (and the lower level implementation) Use a property function instead to

Re: undefined identifier 'size_t'

2016-05-03 Thread Adam D. Ruppe via Digitalmars-d-learn
Is there a file called object.d in your current directory?

Re: Ascii string literal.

2016-05-06 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 6 May 2016 at 20:01:27 UTC, Alexandru Ermicioi wrote: Is it possible somehow to convert implicitly a string literal Not implicitly (well, unless you just use string, ascii is a strict subset of utf-8 anyway), but you could do it explicitly easily. immutable(ubyte)[] ascii(string

Re: Accepting function or delegate as function argument

2016-05-04 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 4 May 2016 at 14:54:39 UTC, chmike wrote: Two constructors, one accepting a function and the other one accepting a delegate would do the job for the API. Is there a simple method to convert a function pointer into a delegate pointer that is also efficient ? Do the overload and

Re: Ascii string literal.

2016-05-06 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 7 May 2016 at 01:37:30 UTC, Jonathan M Davis wrote: In general, it's better to use representation than to cast, because representation gets the constness right, whereas if you cast, there's always the risk that you won't. Yeah, if it is a general thing, but here it is a simple

Re: Which application is much suited and which is not.

2016-04-16 Thread Adam D. Ruppe via Digitalmars-d-learn
I use D for everything unless I cannot by some exterior constraint.

Re: Anonymous structure

2016-04-17 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 18 April 2016 at 02:12:24 UTC, Tofu Ninja wrote: Just out of curiosity, what is the point of the following? struct a{ struct{ int x; int y; int z; } } The grouping matters when it is nested inside a union. Here's a

Re: Anonymous structure

2016-04-17 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 18 April 2016 at 03:57:26 UTC, Tofu Ninja wrote: x,y,and z seem to all be immutable and all have the UDA testUDA. But even odder, it seems that "struct" in there is doing absolutely nothing. The same thing can be done with Yeah, any attribute can be grouped with braces or colons

Re: Anonymous structure

2016-04-17 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 18 April 2016 at 02:42:15 UTC, Nicholas Wilson wrote: IIRC D doesn't allow anonymous structures. They are allowed only if they are inside another aggregate.

Re: Ascii string literal.

2016-05-06 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 6 May 2016 at 21:39:35 UTC, Anonymouse wrote: Is this different from what std.string.representation does? No, it does the same thing, but with your own function the intention may be clearer (or you could do a template to avoid any function or custom types too)

Re: Template mixin Instantiation

2016-05-25 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 25 May 2016 at 07:45:32 UTC, Jorge Lima wrote: I can understand that array1 is not expanded to its value representation in the first call, but why is then when passed as an argument to the Constructor of the literal argument in the second call? Am I missing something obvious?

Re: Is there an easy way to convert a pointer to malloc'd memory to an array?

2016-05-25 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 24 May 2016 at 19:52:17 UTC, Era Scarecrow wrote: You can do that??? I thought slices weren't allowed on raw pointers. You just blew my mind away! Slicing and indexing are both allowed (actually, that's a way to disable bounds checking on an individual expression, see tip:

Re: randomIO, std.file, core.stdc.stdio

2016-07-26 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 26 July 2016 at 19:30:35 UTC, Charles Hixson wrote: It looks as if the entire file is stored in memory, which is not at all what I want, but I also can't really believe that's what's going on. It is just mapped to virtual memory without actually being loaded into physical

Re: Confused about referencing in D

2016-07-14 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 14 July 2016 at 06:23:15 UTC, Gorge Jingale wrote: I think that the assignment in the first case is not assigning the reference returned by auto ref GetValue(). `ref` in D is shallow, it only applies to the thing it is specifically on and is lost across assignments. Once you

Re: Trouble checking for null-ness

2016-07-25 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 25 July 2016 at 13:09:22 UTC, Bahman Movaqar wrote: From what I could gather, it's not possible to check for `null` at runtime for reference based types. Am I right? No, it is only possible to check for null for reference based types. But map's result is not a reference based

<    2   3   4   5   6   7   8   9   10   11   >