Re: Setting a list of values
On Monday, 2 May 2016 at 10:15:04 UTC, Marc Schütz wrote: This check can be done purely by looking at the tokens. In other words it's trivial for D-Scanner to warn about this. https://github.com/Hackerpilot/Dscanner/issues/341
Re: what's wrong with my class?
On Wednesday, 4 May 2016 at 23:19:08 UTC, Jonathan Villa wrote: What I'm doing wrong? :< All right. D's type system is marking the `Session` constructor as `shared`. This makes the check `static if (is(typeof(result.__ctor(args` in std.conv.emplace fail because `result` is a non-shared `Session`. `emplace` is used by `make` to actually initialize the memory returned by `malloc`, which is why you care about it here. The solution to this is to tell `make` that you want it to return a `shared Session`. Once you do this the type checks should pass. tldr: `return Mallocator.instance.make!(shared Session)(_parent, id_user);`
Re: what's wrong with my class?
On Wednesday, 4 May 2016 at 23:34:52 UTC, Jonathan Villa wrote: On Wednesday, 4 May 2016 at 23:33:28 UTC, Brian Schott wrote: On Wednesday, 4 May 2016 at 23:19:08 UTC, Jonathan Villa wrote: What I'm doing wrong? :< I see that the types of `id_user` aren't necessarily the same between `create` and `this`. Oh, they are indeed same (alias). I wrote uint because I didn't want you to confuse with such a large name and I forgot to change the other one c: import std.conv:emplace; synchronized class Session { this(uint u) { this.u = u; } private: uint u; } void main(string[] args) { ubyte[128] mem; Session s = emplace!Session(mem, 10); } Looks like the bug is actually with std.conv.emplace. It works if you remove "synchronized".
Re: what's wrong with my class?
On Wednesday, 4 May 2016 at 23:19:08 UTC, Jonathan Villa wrote: What I'm doing wrong? :< I see that the types of `id_user` aren't necessarily the same between `create` and `this`.
Re: Why is Linux the only OS in version identifier list that has a lowercase name?
On Monday, 11 April 2016 at 23:01:08 UTC, marcpmichel wrote: Is it because Linux is not an OS ? :p I gnu somebody would bring that up.
Re: Can file name, module name, class name and variable name be the same?
On Monday, 18 January 2016 at 05:20:42 UTC, WhatMeWorry wrote: I can workaround the problem but it seems like a kludge; I'm curious about the subtleties of this problems. You can't have a variable with the same name as a module because they're both symbols with the same name. It messes up the symbol resolution code. (Also, it confuses any programmer who reads your code) Check the "renamed imports" section at http://dlang.org/spec/module.html. You should be able to say something like `import c = camera;`.
Re: AliasSeq + isExpression type specialization behavior
On Tuesday, 10 November 2015 at 10:28:45 UTC, Marc Schütz wrote: This fails, too: static assert(is(AliasSeq!(char) : AliasSeq!(dchar))); Which makes sense IMO, because it can be thought of as an unnamed struct, cp. the following: struct A { char c; } struct B { dchar c; } static assert(is(A : B)); // fails, as expected You're talking about Tuple. I'm talking about AliasSeq.
Re: Associative arrays
On Tuesday, 10 November 2015 at 01:29:11 UTC, Brian Schott wrote: Yes. It's a hack that gives you a modulus without having to do a modulus. It only works on powers of two. http://graphics.stanford.edu/~seander/bithacks.html#ModulusDivisionEasy
AliasSeq + isExpression type specialization behavior
Given the following code: ``` import std.meta; static assert(is(char : dchar)); static assert(is(AliasSeq!(int, char) : AliasSeq!(int, char))); static assert(is(AliasSeq!(int, char) : AliasSeq!(int, dchar))); ``` The third static assert fails. Should it, given that the first and second pass?
Re: Parse d source file by using compiler
On Monday, 9 November 2015 at 05:49:25 UTC, tcak wrote: I checked for a flag in this page http://dlang.org/dmd-linux.html , but couldn't have found any for this purpose. Is there a way to parse a d source file so it generates a tree in JSON, XML, or something-that-can-be-processed-easily file format? --- My real purpose: I need to generate hash code (e.g. MD5) for a part of source code (let's say a class, struct, or a function). So whether the codes are changed or not can be detected. As you will guess, comments, text formatting etc. shouldn't affect the hash result. Use-Case: I am writing a code generator/back up system. It will check the last available code file. If important changes are done in a specific part of code, it will increase version number by 1. dscanner --ast path/to/file.d \ | xmllint --xpath "//classDeclaration[name='ClassYouCareAbout']" - \ | md5sum https://github.com/Hackerpilot/Dscanner The only problem here is that D-Scanner's XML output includes tags. You should be able to strip those out with sed or something.
Re: Associative arrays
On Monday, 9 November 2015 at 21:33:09 UTC, TheFlyingFiddle wrote: On Monday, 9 November 2015 at 04:52:37 UTC, rsw0x wrote: On Monday, 9 November 2015 at 04:29:30 UTC, Rikki Cattermole wrote: Fwiw, EMSI provides high quality containers backed by std.experimental.allocator. https://github.com/economicmodeling/containers I have a question regarding the implementation of the economicmodeling hashmap. Why must buckets be a power of two? Is it to be able to use the: hash & (buckets.length - 1) for index calculations or is there some other reason? Yes. It's a hack that gives you a modulus without having to do a modulus. It only works on powers of two.
Re: Problem Benchmarking HashSet from containers-em
On Thursday, 22 October 2015 at 22:06:47 UTC, Nordlöw wrote: Can't I use InSituRegion in this way? No. InSituRegion is not copyable. Try creating a `HashSet!(InSituRegion*)` instead.
Re: Feature or bug: print braces
On Thursday, 14 May 2015 at 00:29:06 UTC, Dennis Ritchie wrote: Why doesn't the compiler produces an error? - import std.stdio; void main() { writeln({}); } - http://ideone.com/qTZCAd You told it to output a function literal, so it did. (That or you told it to output a struct literal, but the compiler has arbitrarily decided that it's a function literal. This is NOT my favorite part of D's grammar.)
Re: Multiple template alias parameters
On Friday, 8 May 2015 at 02:03:17 UTC, Rikki Cattermole wrote: Can you not use something like this? Yes. I was getting confused by another problem that I had just worked on before this one.
Re: Multiple template alias parameters
On Friday, 8 May 2015 at 12:44:31 UTC, Artur Skawina wrote: On 05/08/15 03:53, Brian Schott via Digitalmars-d-learn wrote: The problem occurs when I want to register multiple modules to scan for functions. The grammar does not allow this syntax: ``` template (alias Modules ...) { ... ``` The grammar allows omitting the 'alias' keyword. artur alias parameters are different from normal template parameters. They're not necessary for this problem, but they are for others. As an example: void traceVar(alias var, size_t line = __LINE__, string file = __FILE__)() { import std.stdio: stderr; stderr.writeln(file, (, line, ) , var.stringof, : , var); } This allows you to print a variable's name and value by only passing the variable once as a template argument. Allowing template Tem(alias Args ...) syntax would let me trace multiple variables at once. If you omit alias, var.stringof evaluates to var instead of its name in the calling context.
Multiple template alias parameters
I have some code that automatically wires up control flow based on annotations. Use of this code looks something like this: ``` import some_package.some_module; void main(string[] args) { doMagicStuff!(some_package.some_module)(args); } ``` All of this works and everything is happy (Except the implementation, which is ugly because Phobos is missing a lot of functionality, but that's not the topic I'm discussing here). The problem occurs when I want to register multiple modules to scan for functions. The grammar does not allow this syntax: ``` template (alias Modules ...) { ... ``` Any ideas (besides STRING MIXINS EVERYWHERE)?
Re: getopt helpWanted
What you're trying to do is currently impossible. I filed a bug (https://issues.dlang.org/show_bug.cgi?id=14525) because what you're trying to do really should be possible. import std.stdio : writefln; import std.getopt; void main(string[] args) { string fname; try { getopt(args, std.getopt.config.required, file|f, File name, fname); writefln(Options parsed: fname=%s, fname); } catch (GetOptException e) { writefln(\nERROR: %s, e.msg); auto p = [placeholder]; auto r = getopt(p, file|f, File name, fname); defaultGetoptPrinter(Program usage:, r.options); } }
Re: What ?
On Monday, 30 March 2015 at 22:34:00 UTC, matovitch wrote: Hi again again, ulong u = 1 63; Raise : Error: shift by 63 is outside the range 0..31 This is a bug isn't it, the ulong are supposed to be on 64 bits ? I guess it's time I go to bed. Have a nice night ! The problem is that `1` isn't a ulong. The reason for this is probably C compatibility. Do this instead: ulong u = 1L 63;
Re: generate unique variable names?
On Wednesday, 8 October 2014 at 01:16:50 UTC, K.K. wrote: Is there a way to generate variable names using strings? What I'm trying to do in this particular case is use a for loop, to generate variables (then probably put them in an array in the end) that represent images. So the name is pretty much image + the image padding + iterator number. So image001, image002, etc. So visually (though not real syntax): auto imageName ~ imagePadding ~ i = new Imagefromfile(userDefinedLocation); The problem is I can't figure out how to actually create the unique variable. I was thinking of trying to use 'new' some how, but still not sure. Thanks in advance for any help! I'm 99% sure you actually want an array or associative array. Something like this maybe? ImageType[string] images; images[format(image%03d, i)] = new ImagefromFile(userDefinedLocation);
Re: GC-less Hash-Tables (AA)
On Wednesday, 17 September 2014 at 15:27:40 UTC, Justin Whear wrote: These containers are all certified GC-free. With the exception of getting keys and values arrays. Those return GC memory to the caller. I'm pretty sure it's documented that it does that though. Everything else uses allocators.
Re: Does D provide automatic dereferencing for accessing members through pointers?
On Wednesday, 27 August 2014 at 19:25:42 UTC, Gary Willoughby wrote: Why don't you need to dereference the pointer 'foo' to reach its member 'bar'? The compiler inserts the dereference for you. (It knows which types are references and which are values and can do this correctly) This makes the syntax consistent between value and reference types.
Re: DIP64 - Regarding 'pure' and 'nothrow'
I'd be more convinced if the following statements were false: 1. Writing an automated upgrade tool is difficult 2. The compiler would have no way of knowing what @nothrow means
Re: DIP64 - Regarding 'pure' and 'nothrow'
It would be nice if we could at least allow both nothrow and @nothrow. Because nothrow is already a keyword there's no possibility of a UDA overriding it. This would at least give people the option of making their code look nicer. The delete keyword is deprecated[1] and making that decision never broke any code. [1] http://dlang.org/deprecate.html#delete
Whath the heck does this do?
alias extern(Windows) HRESULT fnNtQuerySystemInformation( uint SystemInformationClass, void* info, uint infoLength, uint* ReturnLength ) nothrow; If you know, respond here or at the following bug report: https://issues.dlang.org/show_bug.cgi?id=13309
Re: Are Delimited strings and HereDoc strings just here to suck ?
On Monday, 11 August 2014 at 19:47:46 UTC, Klaus wrote: I mean when writing a D lexer, you necessarly reach the moment when you think: Oh no! is this feature just here to suck ? They are and they do.
Re: Are Delimited strings and HereDoc strings just here to suck ?
On Monday, 11 August 2014 at 22:20:54 UTC, Brian Schott wrote: On Monday, 11 August 2014 at 19:47:46 UTC, Klaus wrote: I mean when writing a D lexer, you necessarly reach the moment when you think: Oh no! is this feature just here to suck ? They are and they do. Also, use this: https://github.com/Hackerpilot/libdparse
Re: Is there a way to map associative arrays
On Friday, 1 August 2014 at 23:33:22 UTC, Freddy wrote: On Friday, 1 August 2014 at 23:22:06 UTC, bearophile wrote: Freddy: uint[uint] test; void main(){ test=[0:2 ,1:3 ,2:4]; writeln(test.map!(a=a-2)); } If you need keys or values you have .keys .values, .byKey, .byValue (the first two are eager). If you need both you are out of luck, and if you want to write safe code it's better to use a foreach loop. If you want to live dangerously you can use a test.byKey.zip(test.byValue). Take a look in Rosettacode, there are examples for all of them. Bye, bearophile Sorry, i wasn't very clear. I wanted to know if there a way to lazily change the look up operation eg: assert(test[1]==1); assert(test[2]==2); Give your struct/class a method called opIndex. http://dlang.org/operatoroverloading.html#Array
Re: RegEx for a simple Lexer
On Tuesday, 13 May 2014 at 19:53:17 UTC, Tim Holzschuh via Digitalmars-d-learn wrote: Hi there, I read a book about an introduction to creating programming languages (really basic). The sample code is written in Ruby, but I want to rewrite the examples in D. However, the Lexer uses Ruby's regex features to scan the code. I'm not very familiar with D's RegEx system (nor with another..), so it would be very helpful to receive some tips on how to translate the ruby RegEx's to D's implementation. You may find the following useful: http://hackerpilot.github.io/experimental/std_lexer/phobos/lexer.html The source of the lexer generator is located here: https://github.com/Hackerpilot/Dscanner/blob/master/std/lexer.d D lexer: https://github.com/Hackerpilot/Dscanner/blob/master/std/d/lexer.d There's also a parser and AST library for D in that same project. The lexer generator may not be as simple as what you're using right now, but it is very fast.