Re: how to determine of a module or any other symbol is visible?

2018-06-18 Thread Cauterite via Digitalmars-d-learn
On Monday, 18 June 2018 at 09:28:00 UTC, rikki cattermole wrote: On 18/06/2018 9:24 PM, Mr.Bingo wrote: On Monday, 18 June 2018 at 09:10:59 UTC, rikki cattermole wrote: This doesn't work with depreciation warnings. There won't be a way to check for those (I think). Easier to not worry about

Re: scope(success) lowered to try-catch ?

2018-06-18 Thread Cauterite via Digitalmars-d-learn
On Monday, 18 June 2018 at 03:58:47 UTC, Neia Neutuladh wrote: ... yeah, at an AST level it makes sense why it was implemented like this. it's unfortunate that there's no straightforward way to express 'finally(success) {'.

Re: scope(success) lowered to try-catch ?

2018-06-17 Thread Cauterite via Digitalmars-d-learn
On Sunday, 17 June 2018 at 12:10:33 UTC, Nicholas Wilson wrote: I suspect scope(success) is lowered because scope(exit) and scope(failure) are, and that would result in a simpler (compiler) implementation of it. does adding nothrow to main fix it? For dcompute I specifically allow

scope(success) lowered to try-catch ?

2018-06-17 Thread Cauterite via Digitalmars-d-learn
Hello, I'm not sure whether I'm missing something obvious here, but is there a reason for scope(success) being lowered to a try-catch statement? I would have expected only scope(exit) and scope(failure) to actually interact with exception handling, while scope(success) simply places code on

Re: immutable postblit unusable?

2018-02-11 Thread Cauterite via Digitalmars-d
issue opened here: https://issues.dlang.org/show_bug.cgi?id=18417 thanks Jon

Re: Debugging on Windows

2018-02-11 Thread Cauterite via Digitalmars-d-learn
On Thursday, 8 February 2018 at 21:09:33 UTC, JN wrote: Hi, is there any way to debug binaries on Windows? I'd at least like to know which line of code made it crash. If it's D code, I get a call trace usually, but if it's a call to a C library, I get a crash and that's it. I am using VSCode

Re: immutable postblit unusable?

2018-02-11 Thread Cauterite via Digitalmars-d
On Sunday, 11 February 2018 at 08:25:41 UTC, Jonathan M Davis wrote: … Thanks, I couldn't have asked for a more thorough explanation. Especially that __xpostblit detail, which I now vaguely recall seeing in the runtime code. Sounds like making `this(this) immutable` illegal is the way to

immutable postblit unusable?

2018-02-11 Thread Cauterite via Digitalmars-d
https://dpaste.dzfl.pl/80d2a208519c struct A { this(this) immutable {} } struct B { A a; } // Error: immutable method f18.A.__postblit is not callable using a mutable object - I honestly don't know what to make of this. I guess the auto-generated

Re: DIP1001: DoExpression

2016-09-03 Thread Cauterite via Digitalmars-d
On Saturday, 3 September 2016 at 16:03:39 UTC, Jonathan M Davis wrote: So, instead of having the return statement which everyone knows to look for and is easy to grep for, you want to add a way to return _without_ a return statement? I think you've misunderstood. Even with DoExpressions, the

Re: DIP1001: DoExpression

2016-09-03 Thread Cauterite via Digitalmars-d
On Saturday, 3 September 2016 at 16:28:15 UTC, Andrei Alexandrescu wrote: This is a terrible argument. It has "why not" all over it. -- Andrei Sorry, it's my first time proposing a language feature.

Re: DIP1001: DoExpression

2016-09-03 Thread Cauterite via Digitalmars-d
On Saturday, 3 September 2016 at 16:10:16 UTC, Jonathan M Davis wrote: .. and from what I've seen, it seems to be the case that just about only the only folks who read it correctly are the ones who use it frequently .. You know what else is easy to misread? { x; y; return z; }();

Re: DIP1001: DoExpression

2016-09-03 Thread Cauterite via Digitalmars-d
On Saturday, 3 September 2016 at 15:28:36 UTC, Andrei Alexandrescu wrote: What's wrong with: auto seq(T...)(auto ref T vals) { return vals[$ - 1]; } Well there's nothing *wrong* with that, but I really think that 'do' is the perfect word for this purpose, and the fact that it's already a

Re: DIP1001: DoExpression

2016-09-03 Thread Cauterite via Digitalmars-d
On Saturday, 3 September 2016 at 14:47:50 UTC, rikki cattermole wrote: I may dislike not using return but please consider at the very least using ; instead of , for the last element do(x, y ; z). Just something to hint that the last one is special. Not a bad idea, actually. I feel like the

Re: DIP1001: DoExpression

2016-09-03 Thread Cauterite via Digitalmars-d
On Saturday, 3 September 2016 at 14:26:30 UTC, Stefan Koch wrote: Introducing an expression for this seems overkill. The same could be said for the '=>' lambda syntax. Doesn't do anything that {return x;} can't do.

Re: DIP1001: DoExpression

2016-09-03 Thread Cauterite via Digitalmars-d
On Saturday, 3 September 2016 at 14:25:49 UTC, rikki cattermole wrote: I propose a slight change: do(x, y, return z) Hmm, I suppose I should mention one other motivation behind this DIP: I really like to avoid using the 'return' keyword inside expressions, because I find it visually

Re: Hash table element existence check

2016-09-03 Thread Cauterite via Digitalmars-d-learn
On Saturday, 3 September 2016 at 12:33:26 UTC, Illuminati wrote: On Saturday, 3 September 2016 at 07:44:28 UTC, Cauterite wrote: On Friday, 2 September 2016 at 19:38:34 UTC, Illuminati wrote: I am trying to create a hash table and would like an efficient way to be able to know if an element

Re: Hash table element existence check

2016-09-03 Thread Cauterite via Digitalmars-d-learn
On Friday, 2 September 2016 at 19:38:34 UTC, Illuminati wrote: I am trying to create a hash table and would like an efficient way to be able to know if an element exists to test for collisions. Just do a regular lookup on the hash? It's an O(1) operation, like 4 instructions.

Re: ADL

2016-09-02 Thread Cauterite via Digitalmars-d
On Friday, 2 September 2016 at 12:15:25 UTC, Manu wrote: The only problem I have with this feature is that it would lead to implicit-importation, which is a totally foreign concept in D, and I would assume a design choice to not support it. import bob : S; S s; // implicit `import bob :

Re: Equivalent of FirstOrDefault with ranges

2016-09-02 Thread Cauterite via Digitalmars-d-learn
On Friday, 2 September 2016 at 06:56:07 UTC, Lutger wrote: You could do: names.find("bob").chain(only(``)).front; It's not very expressive though.

Re: Fallback 'catch-all' template functions

2016-09-01 Thread Cauterite via Digitalmars-d
On Thursday, 1 September 2016 at 17:21:02 UTC, Meta wrote: I just thought of this, but cannot test if it works. If it does, maybe it would be a suitable solution? void f(T)(T t) if(isSomething!T) {} void f(T)(T t) if(isSomethingElse!T) {} //Taken if no other "overload" of f will intantiate

Re: DMD front-end can be used as a library with Dub

2016-09-01 Thread Cauterite via Digitalmars-d
On Monday, 29 August 2016 at 10:42:23 UTC, Alexander Breckel wrote: Because of the poor memory management in the compiler, I included a modified GC-stub when I compiled the frontend as a library, so that it can be used in long-running processes:

Re: Fallback 'catch-all' template functions

2016-09-01 Thread Cauterite via Digitalmars-d
On Thursday, 1 September 2016 at 10:50:18 UTC, Dominikus Dittes Scherkl wrote: On Thursday, 1 September 2016 at 10:43:50 UTC, Dominikus Dittes Scherkl wrote: I have never seen what benefit could be gained from having overloads. I think they are a relict from languages without static if. I

testing for deprecation

2016-09-01 Thread Cauterite via Digitalmars-d-learn
How does one test whether a symbol is deprecated? I would have expected something like: __traits(isDeprecated, foo). In the compiler we have Dsymbol.isDeprecated, is that not accessible in any way from code? The only solution I can think of is compiling with -de and using __traits(compiles,

You can call Fiber.yield() inside a vectored exception handler (win32)

2016-08-31 Thread Cauterite via Digitalmars-d
In case anyone was wondering, in 32-bit Windows you can call Fiber.yield() from inside a vectored exception handler, and subsequently resume the fibre again. As far as I can tell it works flawlessly. Here's a little example: --- extern(Windows) int on_exception_global(EXCEPTION_POINTERS* X)

Re: Debug prints in @nogc

2016-08-31 Thread Cauterite via Digitalmars-d-learn
On Wednesday, 31 August 2016 at 16:17:51 UTC, Yuxuan Shui wrote: No. When you use assumeUnique, you know something the compiler does know, and have to use assumeUnique to tell the compiler that (at least when you use it correctly). But when you use assumeNogc, it's always because you want to

Re: Multi-threading how-to

2016-08-31 Thread Cauterite via Digitalmars-d-learn
On Wednesday, 31 August 2016 at 17:37:25 UTC, solidstate1991 wrote: I decided to add a functionality that if multiple programs use the same instance of the library on the same computer, the messages will be passed directly instead of via networking. What you're describing here is not actually

Re: Debug prints in @nogc

2016-08-31 Thread Cauterite via Digitalmars-d-learn
On Wednesday, 31 August 2016 at 15:10:11 UTC, Seb wrote: AssumeNogc is potentially dangerous, so I don't know whether it can make it directly, but only if you try you know ;-) So is assumeUnique

Re: D to C++

2016-08-31 Thread Cauterite via Digitalmars-d-learn
On Wednesday, 31 August 2016 at 11:43:12 UTC, Nick wrote: That's quite nice, but not what I'm looking for. What Calypso does, as far as I can see, is to make it possible to compile C++ and D together. I'm looking for a compiler that takes in D code and spits out either C or C++ code. Your

Re: Debug prints in @nogc

2016-08-30 Thread Cauterite via Digitalmars-d-learn
On Tuesday, 30 August 2016 at 14:38:47 UTC, Nordlöw wrote: Just being able to print a string is not good enough. I want the variadic part writeln so I can debug-print values in my buggy code. Do you have a similar solution? Take a look at the example here:

Re: if-expressions

2016-08-30 Thread Cauterite via Digitalmars-d
On Tuesday, 30 August 2016 at 07:41:35 UTC, w0rp wrote: I don't think this particular syntax is desirable. We already have ternary expressions, and anything more complicated than a regular ternary should probably be written with a regular series of if statements. The problem is when you're

Re: Does D have anything like the generators of Python and some other languages?

2016-08-29 Thread Cauterite via Digitalmars-d-learn
On Monday, 29 August 2016 at 21:24:52 UTC, A D dev wrote: Hi group, Does D have anything like the generators of Python and some other languages? Thanks. Ranges serve some of the purposes that generators are often used for: http://dlang.org/phobos/std_range.html But you can of course

Re: Do we need a FAQ page?

2016-08-29 Thread Cauterite via Digitalmars-d
On Monday, 29 August 2016 at 13:50:07 UTC, Andrea Fontana wrote: It's very deep inside menu. Anyway this FAQ sections sounds not right for a newcomer that never seen D IMO. You can actually fork the website ( https://github.com/dlang/dlang.org/blob/master/faq.dd ) and improve it yourself if

Re: Unicode function name? ∩

2016-08-29 Thread Cauterite via Digitalmars-d-learn
On Monday, 29 August 2016 at 12:53:26 UTC, Jesper Tholstrup wrote: Personally, I would prefer 'intersect' as a function name over '∩' anytime. Which benifits does the symbols add? Sounds like you'd love Java. x = new BigDecimal("0.1") x.negate().divide(y).compareTo(z) who needs symbols? >_>

Re: if-expressions

2016-08-28 Thread Cauterite via Digitalmars-d
On Sunday, 28 August 2016 at 13:48:43 UTC, Tomer Filiba wrote: Python uses `x = 5 if cond else 6`, which is by far more readable -tomer conseq1 if cond1 else conseq2 if cond2 else conseq3 if cond3 else conseq4 I dunno man, it seems all backwards to me. If you're gonna do it this way,

Re: Allows the use of part of the language keywords?

2016-08-28 Thread Cauterite via Digitalmars-d
On Sunday, 28 August 2016 at 08:25:38 UTC, Basile B. wrote: to think that it can be detected with a simple lookup backward (or forward from the KW) is too simplistic. I'm not saying it'd necessarily be easy to distinguish keyword 'body' from identifier 'body' in the lexer, I'm just saying a

Re: if-expressions

2016-08-28 Thread Cauterite via Digitalmars-d
On Sunday, 28 August 2016 at 10:08:09 UTC, vladdeSV wrote: Nice work! However, don't you think it's a bit odd that `if(asdf : <-- colon 5 else 6)` equals `asdf ? <-- questionmark 5 : <-- colon 6;` Mm you're right, I had the same concern. The ':' or '?' could both be just as easily used

Re: Allows the use of part of the language keywords?

2016-08-28 Thread Cauterite via Digitalmars-d
On Sunday, 28 August 2016 at 04:32:46 UTC, Basile B. wrote: You must keep track of the previous token, which is not usually done in a scanner. That sounds like a pretty trivial feature to me. There's no way that's a legitimate obstacle.

Re: Unicode function name? ∩

2016-08-28 Thread Cauterite via Digitalmars-d-learn
On Sunday, 28 August 2016 at 05:21:03 UTC, Tofu Ninja wrote: Are unicode function names not supported in dmd? Here's a few ANSI characters you can use (and can type with alt-codes): ª º · Ø ø µ ƒ I use º pretty often, it makes a nice sigil.

Re: if-expressions

2016-08-27 Thread Cauterite via Digitalmars-d
On Saturday, 27 August 2016 at 01:45:58 UTC, Bill Hicks wrote: Yes, fully implementing new language syntax is how I troll on the internet.

Re: Proper concurrent nearly lock free efficient nogc storage structures?

2016-08-27 Thread Cauterite via Digitalmars-d-learn
On Saturday, 27 August 2016 at 01:06:53 UTC, Illuminati wrote: Surely one of the many intelligent people on this forum should be able to implement some of the basic structures fairly quickly? Most of these people are happy to use the GC, so @nogc structures are not a priority.

Re: Proper concurrent nearly lock free efficient nogc storage structures?

2016-08-26 Thread Cauterite via Digitalmars-d-learn
On Friday, 26 August 2016 at 23:38:02 UTC, Illuminati wrote: Does D have any such thing? I'm having to recreate the wheel here and it isn't fun ;/ Getting in the way of real work ;/ @nogc is such a new language feature that you can't expect a lot of support yet from e.g. the standard

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

2016-08-26 Thread Cauterite via Digitalmars-d-learn
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 syntax in D? Yep, scope guards. auto p = OpenProcess(...);

Re: GC Inspiration

2016-08-26 Thread Cauterite via Digitalmars-d
On Friday, 26 August 2016 at 21:41:04 UTC, Robert M. Münch wrote: I'm just digging into LuaJIT and found this interesting GC concept page: http://wiki.luajit.org/New-Garbage-Collector Not sure if this is widly known but I like it, it shows a lot of different approaches with rational etc.

Re: if-expressions

2016-08-26 Thread Cauterite via Digitalmars-d
On Friday, 26 August 2016 at 18:25:00 UTC, Cauterite wrote: // any number of condition/predicate pairs ehem... "any number of predicate:consequent pairs"

if-expressions

2016-08-26 Thread Cauterite via Digitalmars-d
Here's a little patch you guys might enjoy: https://github.com/dlang/dmd/compare/master...Cauterite:ifExpr0 It enables this syntax: int foo = if(asdf: 5 else 6); equivalent to int foo = asdf ? 5 : 6; Here's some other examples which work: // any number of condition/predicate pairs foo = if(

Re: Allows the use of part of the language keywords?

2016-08-26 Thread Cauterite via Digitalmars-d
On Friday, 26 August 2016 at 14:16:27 UTC, Brian wrote: package application.module.user.model; I get "Error: identifier expected following '.' instead of 'module'" So I'm not sure how that compiles for you.

Re: C# 7 Features - Tuples

2016-08-26 Thread Cauterite via Digitalmars-d
On Thursday, 25 August 2016 at 14:43:35 UTC, Dominikus Dittes Scherkl wrote: But I dislike the named tuple members. Why not declare them at the calling site? (int, int, int, string) fn() { return (3, 2, 1, "meins"); } Because how are you supposed to know what each member of the tuple

Re: using .init reliably

2016-08-26 Thread Cauterite via Digitalmars-d-learn
On Friday, 26 August 2016 at 15:14:42 UTC, Steven Schveighoffer wrote: FYI, you cannot make this patch until we fully deprecate the use of TypeInfo.init: https://github.com/dlang/druntime/blob/master/src/object.d#L294 So at least until 2.075. -Steve Ah yes, good thinking. I'll keep that in

Re: using .init reliably

2016-08-26 Thread Cauterite via Digitalmars-d-learn
On Friday, 26 August 2016 at 09:48:00 UTC, Jonathan M Davis wrote: And I expect that it will become an error at some point in the future to define an init member for a user-defined type, at which point, there won't be any choice about fixing it. I might take a crack at this patch. Sounds

using .init reliably

2016-08-26 Thread Cauterite via Digitalmars-d-learn
How can I get the initial value of an arbitrary type? Since any struct can override it, .init is not reliable: struct Z { enum init = 6; string val = `asdf`; }; assert(Z.init == 6); assert(typeof(Z()).init == 6); I know I could use *(cast(Z*) typeid(Z).initializer.ptr) but that

Re: Optimisation possibilities: current, future and enhancements

2016-08-25 Thread Cauterite via Digitalmars-d
On Thursday, 25 August 2016 at 12:27:20 UTC, Cecil Ward wrote: When I said GCC/LLVM I meant GDC(GNU D Compiler)/LDC(LLVM D Compiler). I might have caused some confusion there.

Re: Optimisation possibilities: current, future and enhancements

2016-08-25 Thread Cauterite via Digitalmars-d
On Thursday, 25 August 2016 at 11:16:52 UTC, Cecil Ward wrote: * the GCC "__builtin_expect()" Instead of adding individual micro-optimisation features like this, I'd be more interested in the potential for profile-guided optimisation (which *ideally* can make these micro-optimisation

Re: Optimisation possibilities: current, future and enhancements

2016-08-25 Thread Cauterite via Digitalmars-d
On Thursday, 25 August 2016 at 11:16:52 UTC, Cecil Ward wrote: I long for the day we ditch signalling NaNs — they would surely prevent `-ffast-math` from being effective. I have a couple more ideas, here's one of them: - if a function is pure and called with constexpr parameters, the

Re: nested enum

2016-08-25 Thread Cauterite via Digitalmars-d-learn
On Thursday, 25 August 2016 at 10:36:21 UTC, Daniel Kozak wrote: Btw, tehre is no need for extra semicolon (`;`) after enum and struct definition Thanks. This forum insists on reminding me every time I write code here.

Re: nested enum

2016-08-25 Thread Cauterite via Digitalmars-d-learn
On Wednesday, 24 August 2016 at 23:04:25 UTC, Illuminati wrote: Well those other answers aren't wrong, but I envisioned that you'd have multiple categories within your sub-enums and whatnot, so you'd need something more like this: struct A { enum X { one,

Re: pull requ. 6068 (issue 15257) -- need advice

2016-08-24 Thread Cauterite via Digitalmars-d
On Wednesday, 24 August 2016 at 20:42:36 UTC, Cauterite wrote: _> now it appears. Sorry guys, feel free to delete this thread.

pull requ. 6068 (issue 15257) -- need advice

2016-08-24 Thread Cauterite via Digitalmars-d
NOTE: I tried to post this on the DMD sub-board, but it gave me and error and my post never appeared, so I'm putting it here instead. I've been working on this patch: https://github.com/dlang/dmd/pull/6068 which fixes up some severe flaws in the inline assembler. But I've hit a

Re: Usability of D on windows?

2016-08-23 Thread Cauterite via Digitalmars-d
On Tuesday, 23 August 2016 at 21:37:57 UTC, John Burton wrote: Although they have windows as a host it says that the target is arm-linux-gnueabi so I assumed they were cross compilers? I heard that GDC worked with MinGW at some point in the past, so it may still be feasible without

Re: Usability of D on windows?

2016-08-23 Thread Cauterite via Digitalmars-d
On Tuesday, 23 August 2016 at 21:36:12 UTC, John Burton wrote: It might be fast enough though so I could try it. Remember, if you don't like the compiler's output, you can always substitute it with your own (inline assembly!). Incidentally I'm in the process of fixing a number of IASM bugs

Re: Usability of D on windows?

2016-08-23 Thread Cauterite via Digitalmars-d
On Tuesday, 23 August 2016 at 21:15:40 UTC, John Burton wrote: Well, you're fighting a losing battle by trying to use GDC/LDC on Windows, since Windows is priority #2 for D, and GDC/LDC are still struggling with priority #1 (Linux). You make the Digital Mars backend sound unusable, but I

Re: Do you like bounded integrals?

2016-08-23 Thread Cauterite via Digitalmars-d
On Tuesday, 23 August 2016 at 20:40:06 UTC, Andrei Alexandrescu wrote: I think all of these questions have answers, but I wanted to gauge the interest in bounded checked integrals. Would the need for them justify additional complications in the definition? Well, this occurs very frequently in

Re: Phobos uni methods

2016-08-22 Thread Cauterite via Digitalmars-d
On Monday, 22 August 2016 at 07:58:50 UTC, Andrew wrote: Note that changing isAlpha() can potentially break any D code with unicode in its identifiers, because the DMD frontend uses isAlpha() to determine which characters are allowed in identifiers.

Re: Float values are wrong in union

2016-08-21 Thread Cauterite via Digitalmars-d-learn
On Monday, 22 August 2016 at 04:37:50 UTC, stunaep wrote: I made a union to convert between int bits and floats, but the values are coming out wrong sometimes. I can already tell what this is going to be... The problem is almost certainly nothing to do with your union, it's this line: float

Re: Mem Mgmt: With & Without the GC

2016-08-21 Thread Cauterite via Digitalmars-d-learn
On Sunday, 21 August 2016 at 18:31:26 UTC, Zane wrote: I see - That makes sense, but is there no way to "pause/stop" the GC, but still be able to use the 'new' syntax? Oh you can use `new` when the GC is disabled, no problem. All the GC's functionality is still available. But be careful

Re: Mem Mgmt: With & Without the GC

2016-08-21 Thread Cauterite via Digitalmars-d-learn
On Sunday, 21 August 2016 at 16:14:53 UTC, Zane wrote: 1) If using the GC, but for whatever reason, I need to free something _right now_, is core.GC.free() the proper way to do this? The main problem is that `new` does not necessarily give you a pointer to the start of an allocation, and

Re: Mem Mgmt: With & Without the GC

2016-08-21 Thread Cauterite via Digitalmars-d-learn
On Sunday, 21 August 2016 at 16:14:53 UTC, Zane wrote: 5) Is there a way to do simple heap allocation with 'new' while ensuring the GC doesn't deallocate until I want it to? While my earlier suggestion of using malloc/emplace is one option, another is to use `GC.addRoot(objPtr)`. It ensures

Re: Compiling DMD on Windows: A journey of mystery and madness

2016-08-21 Thread Cauterite via Digitalmars-d
On Sunday, 21 August 2016 at 16:41:27 UTC, NX wrote: [warning: rant ahead] Consider using Digger ( https://github.com/CyberShadow/Digger ) in your future attempts to build DMD, to save yourself some trouble. I've had a great experience using it, apart from the dependency on visual studio.

Re: Mem Mgmt: With & Without the GC

2016-08-21 Thread Cauterite via Digitalmars-d-learn
On Sunday, 21 August 2016 at 16:14:53 UTC, Zane wrote: 2) Does calling object.destroy() mean that the object is marked for future collection? If not, how can I ensure it is properly marked. Because the GC is not of the incremental type, it can't perform any marking outside of a

Re: Mem Mgmt: With & Without the GC

2016-08-21 Thread Cauterite via Digitalmars-d-learn
On Sunday, 21 August 2016 at 16:14:53 UTC, Zane wrote: 6) If the GC is off, how is allocation/deallocation handled? Can I still use new for example (and how do I dealloc)? All the allocation/deallocation functionality is the same as normal, except the GC won't start a collection cycle unless

Re: Mem Mgmt: With & Without the GC

2016-08-21 Thread Cauterite via Digitalmars-d-learn
On Sunday, 21 August 2016 at 16:14:53 UTC, Zane wrote: 5) Is there a way to do simple heap allocation with 'new' while ensuring the GC doesn't deallocate until I want it to? I can answer this at least, If you don't want the GC to ever collect the object itself, here's the best way: Allocate

Re: MurmurHash3 behaviour

2016-08-19 Thread Cauterite via Digitalmars-d-learn
On Friday, 19 August 2016 at 21:03:22 UTC, Seb wrote: http://dlang.org/phobos-prerelease/std_digest_murmurhash.html Ah great, I just finished writing my own murmurhash digest module ( https://github.com/Cauterite/phobos/blob/murmur/std/digest/murmur.d ), and now I discover someone's already

MurmurHash3 behaviour

2016-08-19 Thread Cauterite via Digitalmars-d-learn
Regarding the MurmurHash3 implementation in core.internal.hash, it is my understanding that: // assuming a and b are uints bytesHash([a, b], 0) == bytesHash([b], bytesHash([a], 0)) Is this correct? I'm just not quite certain of this property when I try to read the code myself, and I

Re: having a trivial anonymous function call in template prevents compilation?

2016-08-17 Thread Cauterite via Digitalmars-d-learn
On Wednesday, 17 August 2016 at 13:33:26 UTC, Steven Schveighoffer wrote: I think the OP's case is a bug. Please file. Thanks, I've filed it. Just wanted to get a second opinion before concluding that it's a bug.

Re: having a trivial anonymous function call in template prevents compilation?

2016-08-17 Thread Cauterite via Digitalmars-d-learn
On Wednesday, 17 August 2016 at 13:18:06 UTC, Adam D. Ruppe wrote: Best you can do is use them in an alias argument directly, but you cannot use them in an enum argument. I think you missed the point; it works perfectly fine without having this `({return 0;})()` in the template body (which,

having a trivial anonymous function call in template prevents compilation?

2016-08-17 Thread Cauterite via Digitalmars-d-learn
// -- Example: -- template A(alias Arg) { enum A = Arg; enum Unrelated = ({return 0;})(); // this line prevent compilation }; void main() { enum FnPtr = enum _ = A!FnPtr; }; void asdf() {}; // ( https://dpaste.dzfl.pl/79301f12e5fc ) Just by having a

Re: When does take modify the underlying iterator?

2016-08-16 Thread Cauterite via Digitalmars-d-learn
On Tuesday, 16 August 2016 at 21:01:14 UTC, cy wrote: This has also been annoying me lately, so I came up with this workaround: InputRange!T X = inputRangeObject(Src); X.take(6); // remove+return items 0 to 5 X.take(3); // remove+return items 6 to 8

Re: Passing Structs to function like in C

2016-08-14 Thread Cauterite via Digitalmars-d-learn
On Sunday, 14 August 2016 at 16:21:58 UTC, D.Rex wrote: so '();' works the same as 'foo.bar();'? with pointers, D automatically rewrites expressions like this: f.fooMethod() to this: (*f).fooMethod() which is why you're able to index an object-pointer-pointer (Foo*) the same

Re: if static member then call

2016-08-13 Thread Cauterite via Digitalmars-d-learn
On Saturday, 13 August 2016 at 18:34:43 UTC, Engine Machine wrote: static if (hasStaticMember!(T, "foo")) Here I suspect you're looking for this: __traits(isStaticFunction, __traits(getMember, T, "foo"))

Re: if static member then call

2016-08-13 Thread Cauterite via Digitalmars-d-learn
On Saturday, 13 August 2016 at 18:34:43 UTC, Engine Machine wrote: auto ref foo(T, Args...)(args) { static if (hasStaticMember!(T, "foo")) return T.foo!(T)(args); } Basically I want to forward the *static* call to T if possible(if foo exists in T). The main problem is actually

Re: Passing Structs to function like in C

2016-08-13 Thread Cauterite via Digitalmars-d-learn
On Saturday, 13 August 2016 at 15:47:51 UTC, D.Rex wrote: /* memory.d file */ module memory; import include.linux.sched;/* contains task_struct definition */ void free_page_tables(task_struct* tsk) { /* do something with */ } And to use the method from somewhere else /* use

Re: 'importing' threads — i.e. thread_attachThis()

2016-08-12 Thread Cauterite via Digitalmars-d-learn
On Friday, 12 August 2016 at 18:59:35 UTC, Guillaume Piolat wrote: On Friday, 12 August 2016 at 10:45:22 UTC, Cauterite wrote: Thanks, this is very helpful. I already feel much more confident about the idea. My use is definitely the 'whole-lifetime' case, so I might be able to get away

Re: Passing Structs to function like in C

2016-08-12 Thread Cauterite via Digitalmars-d-learn
Thanks colon-nazis, I'll take that into consideration ¬_¬

Re: Passing Structs to function like in C

2016-08-12 Thread Cauterite via Digitalmars-d-learn
On Friday, 12 August 2016 at 16:50:43 UTC, ag0aep6g wrote: On 08/12/2016 05:23 PM, Cauterite wrote: No semicolon there, please. Why would I not terminate a declaration with a semi-colon? Why should a declaration not end in a semi-colon just because the last token is a brace? Why should I not

Re: Passing Structs to function like in C

2016-08-12 Thread Cauterite via Digitalmars-d-learn
On Friday, 12 August 2016 at 15:21:22 UTC, D.Rex wrote: extern unsigned long free_page_tables(struct task_struct * tsk); extern(C) ulong free_page_tables(task_struct* tsk); void main() { task_struct tsk = …… ; free_page_tables(); }; That should be what you're after?

'importing' threads — i.e. thread_attachThis()

2016-08-12 Thread Cauterite via Digitalmars-d-learn
I'm planning on 'importing' a thread into the D runtime using thread_attachThis(), and was just wondering about the potential pitfalls of this process. For example: - Would having an entry function other than core.thread.thread_entryPoint() pose problems? What about during stack unwinding?

Re: method static-ness has no effect on the type?

2016-08-08 Thread Cauterite via Digitalmars-d-learn
On Monday, 8 August 2016 at 10:21:47 UTC, ag0aep6g wrote: Also thanks for submitting the bug for me.

Re: method static-ness has no effect on the type?

2016-08-08 Thread Cauterite via Digitalmars-d-learn
On Monday, 8 August 2016 at 10:05:58 UTC, ag0aep6g wrote: The first assert compares the return types of f1 and f2. They both return `void`, so everything's fine there. I think you're mistaken about this. typeof(S.f1) definitely gives the type of the function, not of the return. Try it out:

Re: [DIP] In-place struct initialization

2016-08-08 Thread Cauterite via Digitalmars-d
On Friday, 5 August 2016 at 07:04:55 UTC, deadalnix wrote: Also, there are nice library solution for named argument already. Which ones do you have in mind?

Re: Tracking memory usage

2016-08-08 Thread Cauterite via Digitalmars-d-learn
On Sunday, 7 August 2016 at 00:28:40 UTC, Alfred Pincher wrote: this is a very nice feature. I hope D has something similar? If you want to implement that kind of allocation tracking you'll probably want to use gc_getProxy()+gc_setProxy(). They're global C functions you can access by

method static-ness has no effect on the type?

2016-08-08 Thread Cauterite via Digitalmars-d-learn
See: https://dpaste.dzfl.pl/2ec6780d4b25 We have two methods defined, f1 and f2, where f2 is static but they have otherwise identical signatures. We can see from the disassembly that f1 receives a `this` pointer while f2 does not. Yet, typeof() == typeof(). This makes no sense, how can the

Re: Cannot distinguish between template function wtih 0 args and 1 arg

2016-08-08 Thread Cauterite via Digitalmars-d-learn
On Monday, 8 August 2016 at 02:36:24 UTC, Engine Machine wrote: Error: template Mem cannot deduce function from argument types !(cast(eException)1280L, "main.d", 38u, "main.WinMain")(int), candidates are: Mem(T, B = eX, string file = __FILE__, uint line = __LINE__, string func =

Re: assert or throw in range members?

2016-08-05 Thread Cauterite via Digitalmars-d-learn
On Friday, 5 August 2016 at 10:25:42 UTC, Nordlöw wrote: Should range members front() and back() assert() or throw() on emptyness? I'm pretty sure it's assert() here. The contract is that the caller is responsible for checking emptiness beforehand, and the whole of Phobos is coded around

Re: Overflows in Phobos

2016-07-31 Thread Cauterite via Digitalmars-d
On Saturday, 30 July 2016 at 00:55:11 UTC, Charles Hixson wrote: FWIW, in that case I always use assert (false, "..."); I try to never use integers for booleans. But this may well be a common usage. I suspect `assert(0)` is really `assert(constexpr>)`, so you should be fine. Both styles are

Re: [DIP] In-place struct initialization

2016-07-30 Thread Cauterite via Digitalmars-d
On Saturday, 30 July 2016 at 22:05:29 UTC, cym13 wrote: On Saturday, 30 July 2016 at 21:45:31 UTC, Cauterite wrote: On Saturday, 30 July 2016 at 21:42:42 UTC, cym13 wrote: ... Here's something you might enjoy in the meantime:

Re: [DIP] In-place struct initialization

2016-07-30 Thread Cauterite via Digitalmars-d
On Saturday, 30 July 2016 at 21:42:42 UTC, cym13 wrote: ... Here's something you might enjoy in the meantime: https://github.com/Cauterite/dlang-pod-literals/blob/master/podliterals.d

Re: Does D have object wrappers for primitives?

2016-07-30 Thread Cauterite via Digitalmars-d-learn
On Saturday, 30 July 2016 at 04:12:45 UTC, stunaep wrote: Thank you. This is just what I needed. I am curious though as to why this doesn't work with strings. It would work if I removed immutable from the Boxed constructor but I thought strings were immutable. I get a compiler error 'not

Re: [OT] Music to Program Compilers To

2016-07-29 Thread Cauterite via Digitalmars-d
On Friday, 29 July 2016 at 22:44:04 UTC, Walter Bright wrote: http://70sdisconights.com/ Yes, I listen to it while I work. that webpage design though >_<

Re: Does D have object wrappers for primitives?

2016-07-29 Thread Cauterite via Digitalmars-d-learn
On Friday, 29 July 2016 at 20:26:47 UTC, Ali Çehreli wrote: I was going to suggest Algebraic because it allows arrays of mixed primitive types (wrapped in Algebraic): https://dlang.org/phobos/std_variant.html#.Algebraic Ali It could work, but keep in mind Algebraic is a structure, not

Re: Does D have object wrappers for primitives?

2016-07-29 Thread Cauterite via Digitalmars-d-learn
On Friday, 29 July 2016 at 20:13:34 UTC, stunaep wrote: I have some java code I need to convert and at one point it uses an Object[] array to store various ints, longs, and strings. Java has built in Integer and Long classes that wrap the primitives in an object and strings are already

Re: When I should to call destroy?

2016-07-29 Thread Cauterite via Digitalmars-d-learn
On Friday, 29 July 2016 at 13:18:00 UTC, Suliman wrote: But I can't understand if D have GC it should remove objects when their life is finished. When I should to call `destroy`? What would be if I will not call it? `destroy` is mainly about running destructors deterministically. From the

  1   2   >