Re: Make a hash out of two ranges

2013-02-27 Thread Chris Cain
On Thursday, 28 February 2013 at 04:50:34 UTC, Andrej Mitrovic wrote: On 2/28/13, Chris Cain wrote: Map in std.algorithm doesn't really work like that. Many languages use "map" to mean hashing items, but "map" in functional programming (and D) really means something more like "apply this functi

Re: Make a hash out of two ranges

2013-02-27 Thread Andrej Mitrovic
On 2/28/13, Chris Cain wrote: > Map in std.algorithm doesn't really work like that. Many > languages use "map" to mean hashing items, but "map" in > functional programming (and D) really means something more like > "apply this function to each item." I know that, I was expecting it to work with m

Re: Make a hash out of two ranges

2013-02-27 Thread Andrej Mitrovic
On 2/28/13, Andrej Mitrovic wrote: > foreach (x; r2) > writeln(r2); // prints "[[1:2], [3:4]]" twice, why? Oh dumb me I'm priting r2 instead of x, my bad.

Re: Make a hash out of two ranges

2013-02-27 Thread Andrej Mitrovic
On 2/28/13, Jonathan M Davis wrote: > You'd need to wrap them in a single range of pairs with something like zip. I'm not exactly sure how to do that though. Just using zip in the argument place won't work. I've tried to create my own range, but I'm having issues: import std.string; import std.

Re: Transparent ANSI to UTF-8 conversion

2013-02-27 Thread Era Scarecrow
On Wednesday, 27 February 2013 at 10:56:16 UTC, Lubos Pintes wrote: Hi, I would like to transparently convert from ANSI to UTF-8 when dealing with text files. For example here in Slovakia, virtually every text file is in Windows-1250. If someone opens a text file, he or she expects that it wil

Re: Make a hash out of two ranges

2013-02-27 Thread Chris Cain
On Thursday, 28 February 2013 at 03:59:16 UTC, Andrej Mitrovic wrote: void main() { auto r = map!((a, b) => [a : b])([1, 3], [2, 4]); assert(r[0] == [1 : 2]); assert(r[1] == [3 : 4]); } Map in std.algorithm doesn't really work like that. Many languages use "map" to mean hashing ite

Re: Make a hash out of two ranges

2013-02-27 Thread Jonathan M Davis
On Thursday, February 28, 2013 04:56:48 Andrej Mitrovic wrote: > import std.algorithm; > import std.range; > > void main() > { > auto r = map!((a, b) => [a : b])(["foo"], ["bar"]); // error > assert(r.front == ["foo" : "bar"]); > } > > This doesn't compile, what am I missing? Map only w

Re: Make a hash out of two ranges

2013-02-27 Thread Andrej Mitrovic
On 2/28/13, Andrej Mitrovic wrote: > import std.algorithm; > import std.range; > > void main() > { > auto r = map!((a, b) => [a : b])(["foo"], ["bar"]); // error > assert(r.front == ["foo" : "bar"]); > } > > This doesn't compile, what am I missing? > A more clearer example: void main()

Re: nWayUnion(tuple)?

2013-02-27 Thread Chris Cain
On Thursday, 28 February 2013 at 00:44:58 UTC, bearophile wrote: Chris Cain: I'm playing around with some things and if I come up with a solution in code, I'll post it. If you have some useful idea then please add it to the ER itself: http://d.puremagic.com/issues/show_bug.cgi?id=9611 Bye,

Re: nWayUnion(tuple)?

2013-02-27 Thread Chris Cain
On Thursday, 28 February 2013 at 01:01:16 UTC, Chris Cain wrote: I'll post this to the ER as well, but here you go :) https://gist.github.com/Zshazz/c4da4c3e0099062ab7e5 And upon reading the ER, I see that this is (essentially) the solution it had. *doh* And I thought I was being pretty cleve

Re: nWayUnion(tuple)?

2013-02-27 Thread bearophile
Chris Cain: I'm playing around with some things and if I come up with a solution in code, I'll post it. If you have some useful idea then please add it to the ER itself: http://d.puremagic.com/issues/show_bug.cgi?id=9611 Bye, bearophile

Re: A little of coordination for Rosettacode

2013-02-27 Thread bearophile
A possible idea is to translate this last Python version to D: http://rosettacode.org/wiki/Hamming_numbers#Cyclic_generator_method_.232. - - - - - - - - - - - - Another idea is to add a D version of Merge Sort that works with just a Input Range (like a single linked list, as a SList): http://

Re: nWayUnion(tuple)?

2013-02-27 Thread Chris Cain
On Wednesday, 27 February 2013 at 23:54:31 UTC, Chris Cain wrote: I'm not sure how common the use case is, but I think it'd be fairly easy to support. Just internally have an array of indices to the tuple and use the heap with a less defined like "myTup[a] < myTup[b]" to use the indices to lo

Re: Playing with ranges and ufcs

2013-02-27 Thread bearophile
Jonathan M Davis: Because then it more closely matches how arrays work. The only part that doesn't is that it's fully tied to -release rather than -noboundschecked. I see, thank you. Honestly, I think that that's a complete pipe dream anyway, I will keep dreaming for some more decades. I

Re: Playing with ranges and ufcs

2013-02-27 Thread Jonathan M Davis
On Thursday, February 28, 2013 00:35:08 bearophile wrote: > Jonathan M Davis: > > What it should be doing is using version(assert) to throw a > > RangeError if the > > arguments are invalid, but the addition of version(assert) is > > quite recent > > (previously, the best that could have been done

Re: Playing with ranges and ufcs

2013-02-27 Thread Jonathan M Davis
On Thursday, February 28, 2013 00:46:56 bearophile wrote: > > To do the same with user-defined structures time ago I have > > suggested this, that is currently closed waiting for a better > > > solution: > What I meant to say is that if the assert(i <= j) is inside the > pre-condition then there's

Re: nWayUnion(tuple)?

2013-02-27 Thread Chris Cain
On Wednesday, 27 February 2013 at 19:36:44 UTC, bearophile wrote: But in some cases I'd like to merge different types of ranges, that I can't put in an array. Is this use case worth supporting (usually the number of ranges is small so for such use cases a heap is not so needed)? I'm not sure

Re: Playing with ranges and ufcs

2013-02-27 Thread bearophile
To do the same with user-defined structures time ago I have suggested this, that is currently closed waiting for a better solution: What I meant to say is that if the assert(i <= j) is inside the pre-condition then there's a hope to run it at compile time introducing some new trick inside the

Re: Playing with ranges and ufcs

2013-02-27 Thread bearophile
auto opSlice(size_t i, size_t j) in { assert(i <= j, "some message here"); } body { auto retval = this.save; retval._index += i; return takeExactly(retval, j - i); } This is the bug opened by Andrea Fontana for this thread: http://d.puremagic.com/issues/show_bug.cgi?id=9612 At

Re: Playing with ranges and ufcs

2013-02-27 Thread bearophile
Jonathan M Davis: What it should be doing is using version(assert) to throw a RangeError if the arguments are invalid, but the addition of version(assert) is quite recent (previously, the best that could have been done was to assert). Do you mean something like this? auto opSlice(size_t i,

Re: Playing with ranges and ufcs

2013-02-27 Thread bearophile
Andrea Fontana: Done! I was about to file it myself, so I have added a bit more meat to your bug report. Bye, bearophile

Re: Playing with ranges and ufcs

2013-02-27 Thread Andrea Fontana
On Wednesday, 27 February 2013 at 22:48:06 UTC, bearophile wrote: Andrea Fontana: writeln(iota(10).cycle()[5..2].take(4)); print: [5, 6, 7, 8] Shouldn't [5..2] slice throw a compile/runtime error? Please file it in bugzilla. The opSlice of cycle() lacks those pre-conditions or tests, and

Re: Playing with ranges and ufcs

2013-02-27 Thread Jonathan M Davis
On Wednesday, February 27, 2013 23:48:05 bearophile wrote: > Andrea Fontana: > > writeln(iota(10).cycle()[5..2].take(4)); > > > > print: > > > > [5, 6, 7, 8] > > > > > > Shouldn't [5..2] slice throw a compile/runtime error? > > Please file it in bugzilla. > > The opSlice of cycle() lacks thos

Re: nWayUnion(tuple)?

2013-02-27 Thread Ali Çehreli
On 02/27/2013 03:02 PM, bearophile wrote: If we add an overload of nWayUnion (better named nWayMerge: http://d.puremagic.com/issues/show_bug.cgi?id=6718 ) then there's no need to use inputRangeObject... The question is how much common my use case (mixed type iterables) is. I agree with you. E

Re: nWayUnion(tuple)?

2013-02-27 Thread bearophile
Ali Çehreli: It is not very pretty, but to match the elements of that array, there is inputRangeObject: OK. Phobos could have a function so that the code could be cleaner. A function that supports "treat these as InputRanges of ints": nWayUnion(inputRanges(a, b, c)); But it is not th

Re: Playing with ranges and ufcs

2013-02-27 Thread bearophile
Andrea Fontana: writeln(iota(10).cycle()[5..2].take(4)); print: [5, 6, 7, 8] Shouldn't [5..2] slice throw a compile/runtime error? Please file it in bugzilla. The opSlice of cycle() lacks those pre-conditions or tests, and there are not enough unittests in Phobos to catch this simple bug

Playing with ranges and ufcs

2013-02-27 Thread Andrea Fontana
This command: writeln(iota(10).cycle()[5..2].take(4)); print: [5, 6, 7, 8] Shouldn't [5..2] slice throw a compile/runtime error?

Re: Parsing string to string?

2013-02-27 Thread monarch_dodra
On Wednesday, 27 February 2013 at 20:37:01 UTC, Lubos Pintes wrote: And what about the opposite way? I like how Python is representing strings. Good when you want to partially inspect something binary. Dňa 27. 2. 2013 19:39 monarch_dodra wrote / napísal(a): I have a text file, that contains te

Re: Best way to handle settings files (ini file syntax or similar)

2013-02-27 Thread Dicebot
Btw now I have actually noticed it is really bad and dirty, so good to sometimes check your 2-year code. I think you can write better one anyway, just an example of how small it can be.

Re: Best way to handle settings files (ini file syntax or similar)

2013-02-27 Thread Dicebot
I use this simple snippet to get quick and dirty key-value config: --- string[string] data; foreach( line; readText(filename).splitLines() ) { auto config_pair = array( filter!("a.length > 0")( map!(strip)( line.splitter("=") ) ) );

Best way to handle settings files (ini file syntax or similar)

2013-02-27 Thread Samuel Lampa
Hi, I was wondering what would be the most straightforward way to handle settings files in D, currently? Is there support for ini filesor something similar, or would I be better off going with JSON or XML or similar? BR // Samuel

Re: nWayUnion(tuple)?

2013-02-27 Thread Ali Çehreli
On 02/27/2013 11:36 AM, bearophile wrote: > But in some cases I'd like to merge different types of ranges, that I > can't put in an array. Is this use case worth supporting (usually the > number of ranges is small so for such use cases a heap is not so needed)? nWayUnion requires a range of rang

Re: Transparent ANSI to UTF-8 conversion

2013-02-27 Thread Dmitry Olshansky
28-Feb-2013 00:35, Lubos Pintes пишет: I don't understand the CTFE usage in this context. I thought about something like dchar[] windows_1250=[...]; Isn't this enough? Thank It's fine. What I've meant is if all you want to do is convert ANSI -> UTF8 there is no need to convert to dchar and the

Re: Parsing string to string?

2013-02-27 Thread Lubos Pintes
And what about the opposite way? I like how Python is representing strings. Good when you want to partially inspect something binary. Dňa 27. 2. 2013 19:39 monarch_dodra wrote / napísal(a): I have a text file, that contains text with escaped characters, eg: // hello\tworld. this line\ncont

Re: Transparent ANSI to UTF-8 conversion

2013-02-27 Thread Lubos Pintes
I don't understand the CTFE usage in this context. I thought about something like dchar[] windows_1250=[...]; Isn't this enough? Thank Dňa 27. 2. 2013 18:32 Dmitry Olshansky wrote / napísal(a): 27-Feb-2013 16:20, monarch_dodra пишет: On Wednesday, 27 February 2013 at 10:56:16 UTC, Lubos Pinte

Re: Linking C and D

2013-02-27 Thread jerro
On Wednesday, 27 February 2013 at 18:40:40 UTC, monarch_dodra wrote: On Wednesday, 27 February 2013 at 17:08:38 UTC, Alexandr Druzhinin wrote: 27.02.2013 23:50, monarch_dodra пишет: dmc seems to start choking when my font files start to reach about 15 Mo. I suppose there's a switch somewher

nWayUnion(tuple)?

2013-02-27 Thread bearophile
Currently std.algorithm.nWayUnion requires an array of ranges, because it internally keeps them in a heap, to be fast when you give it hundreds+ of ranges. But in some cases I'd like to merge different types of ranges, that I can't put in an array. Is this use case worth supporting (usually t

Re: Linking C and D

2013-02-27 Thread Michael
Also C runtime can be statically compiled with your c/dll library. You just need copy c dll and your d exe without additional dependencies. C dll can be prepared by visual c.

Re: Linking C and D

2013-02-27 Thread Michael
With Dmd you can use dmc directly. Second way is: you can compile your code as dll library and then create import library with implib utility for win32, for win64 a import library can be used directly. First way works good, but I prefer second one. Both approaches for win32 and win64 works go

Re: Linking C and D

2013-02-27 Thread monarch_dodra
On Wednesday, 27 February 2013 at 17:08:38 UTC, Alexandr Druzhinin wrote: 27.02.2013 23:50, monarch_dodra пишет: dmc seems to start choking when my font files start to reach about 15 Mo. I suppose there's a switch somewhere, but I've never used dmc before, so all the switches are unknown to

Parsing string to string?

2013-02-27 Thread monarch_dodra
I have a text file, that contains text with escaped characters, eg: // hello\tworld. this line\ncontains a break. and this one a\x20binary character. and this one\u0020an escaped unicode. // The idea is that once parse line by line, I want 4 strings (1 for each line), but with the esca

Re: Template alias parameter does not accept functions

2013-02-27 Thread Nick Treleaven
On 27/02/2013 18:06, Dicebot wrote: Ye, lambda litteral issue is different one. OK. My code example: http://dpaste.1azy.net/b06370ea The problem may be related to optional parentheses and stringof, and may be a compiler bug. You can pass function names as a template alias parameter: imp

Re: Template alias parameter does not accept functions

2013-02-27 Thread Dicebot
Fuck. Optional. Parens. Thank you. I have tried some other code than .stringof but guess it invoked Symbols somewhere silently, too.

Re: scope(exit) & stack => double free or corruption (fasttop) ... help?

2013-02-27 Thread Charles Hixson
On 02/26/2013 04:24 PM, Ben Davis wrote: On 26/02/2013 06:21, Charles Hixson wrote: On 02/24/2013 05:39 PM, H. S. Teoh wrote: On Sun, Feb 24, 2013 at 03:14:01PM -0800, Charles Hixson wrote: Given a struct with: ~this() { close(); } void close() { if (currentKey !is null) currentKey = null; i

Re: Template alias parameter does not accept functions

2013-02-27 Thread Dicebot
Ye, lambda litteral issue is different one. My code example: http://dpaste.1azy.net/b06370ea

Re: Template alias parameter does not accept functions

2013-02-27 Thread Nick Treleaven
On 27/02/2013 17:38, Nick Treleaven wrote: On 27/02/2013 15:20, Dicebot wrote: Looking here: http://dlang.org/template.html#TemplateAliasParameter There are no function symbols in the list. And quick check that it won't compile. Two questions arise: a) Why so? b) Is there a workaround? Actua

Re: Template alias parameter does not accept functions

2013-02-27 Thread Nick Treleaven
On 27/02/2013 15:20, Dicebot wrote: Looking here: http://dlang.org/template.html#TemplateAliasParameter There are no function symbols in the list. And quick check that it won't compile. Two questions arise: a) Why so? b) Is there a workaround? This has sometimes come up in the NG, with some s

Re: Transparent ANSI to UTF-8 conversion

2013-02-27 Thread Dmitry Olshansky
27-Feb-2013 16:20, monarch_dodra пишет: On Wednesday, 27 February 2013 at 10:56:16 UTC, Lubos Pintes wrote: Hi, I would like to transparently convert from ANSI to UTF-8 when dealing with text files. For example here in Slovakia, virtually every text file is in Windows-1250. If someone opens a te

Re: Template alias parameter does not accept functions

2013-02-27 Thread Dicebot
Actually it looks like a somewhat broken behavior as it works for parameter-less functions.

Re: Linking C and D

2013-02-27 Thread Alexandr Druzhinin
27.02.2013 23:50, monarch_dodra пишет: dmc seems to start choking when my font files start to reach about 15 Mo. I suppose there's a switch somewhere, but I've never used dmc before, so all the switches are unknown to me. I guess I'll just have to learn (anybody know?). If worst comes to worst

Re: Linking C and D

2013-02-27 Thread Alexandr Druzhinin
27.02.2013 23:12, monarch_dodra пишет: I can't seem to get the executable to link correctly. I'm using gcc and dmd on windows. I'm building foo.c with: gcc -c foo.c -o foo.obj Then I build my exe with: dmd foo.obj main.d But I get: OPTLINK (R) for Win32 Release 8.00.12 Copyright (C) Digital

Re: Linking C and D

2013-02-27 Thread monarch_dodra
On Wednesday, 27 February 2013 at 16:37:06 UTC, Alexandr Druzhinin wrote: 27.02.2013 23:12, monarch_dodra пишет: I can't seem to get the executable to link correctly. I'm using gcc and dmd on windows. I'm building foo.c with: gcc -c foo.c -o foo.obj Then I build my exe with: dmd foo.obj main.

Re: Linking C and D

2013-02-27 Thread monarch_dodra
On Wednesday, 27 February 2013 at 16:20:43 UTC, Andrej Mitrovic wrote: On Wednesday, 27 February 2013 at 16:12:13 UTC, monarch_dodra wrote: I'm trying to get the hello world of cross compiling working: The short story is you can't link GCC and DMD object files on win32 because DMD emits OMF,

Re: Linking C and D

2013-02-27 Thread Andrej Mitrovic
On Wednesday, 27 February 2013 at 16:12:13 UTC, monarch_dodra wrote: I'm trying to get the hello world of cross compiling working: The short story is you can't link GCC and DMD object files on win32 because DMD emits OMF, GCC emits COFF, these are incompatible. You might want to read this:

Linking C and D

2013-02-27 Thread monarch_dodra
I'm trying to get the hello world of cross compiling working: main.d // extern (C) void foo(); void main() { foo(); } // foo.c // #include void foo() { printf("hello world"); } // I can't seem to get the executable to link correctly. I'm using gcc and dmd on windows. I

Re: Transparent ANSI to UTF-8 conversion

2013-02-27 Thread monarch_dodra
On Wednesday, 27 February 2013 at 10:56:16 UTC, Lubos Pintes wrote: Hi, I would like to transparently convert from ANSI to UTF-8 when dealing with text files. For example here in Slovakia, virtually every text file is in Windows-1250. If someone opens a text file, he or she expects that it will

Re: A little of coordination for Rosettacode

2013-02-27 Thread FG
On 2013-02-27 12:47, FG wrote: On 2013-02-26 15:10, bearophile wrote: This third version is much simpler and it seems good enough for Rosettacode: http://codepad.org/YJjb1t91 Nice. Myself I'd add bits.reverse; after the N.iota.map..., because I'm more used to a truth table where the left-most

Re: A little of coordination for Rosettacode

2013-02-27 Thread FG
On 2013-02-26 15:10, bearophile wrote: This third version is much simpler and it seems good enough for Rosettacode: http://codepad.org/YJjb1t91 Nice. Myself I'd add bits.reverse; after the N.iota.map..., because I'm more used to a truth table where the left-most operands iterate the slowest.

Re: Type of complex expression

2013-02-27 Thread bearophile
Lubos Pintes: auto a=" 1 2 3 4 5 " .split(" ") .filter!"!a.empty" .map!"to!int(a)"; writeln(a); better (untested): auto a = " 1 2 3 4 5 " .split .map!(to!int) .writeln; Bye, bearophile

Transparent ANSI to UTF-8 conversion

2013-02-27 Thread Lubos Pintes
Hi, I would like to transparently convert from ANSI to UTF-8 when dealing with text files. For example here in Slovakia, virtually every text file is in Windows-1250. If someone opens a text file, he or she expects that it will work properly. So I suppose, that it is not feasible to tell someon

Re: D timer

2013-02-27 Thread David
Am 26.02.2013 14:19, schrieb bearophile: > David: > >> Not sure what you mean, but I have a pretty solid Timer implementation >> (Threaded) >> >> https://github.com/Dav1dde/BraLa/blob/master/brala/utils/thread.d >> >> The file has no dependencies, so copy it over and have fun. License of >> the wh

Re: Type of complex expression

2013-02-27 Thread Jonathan M Davis
On Wednesday, February 27, 2013 11:02:59 Lubos Pintes wrote: > Hi, > Some time ago I asked how to efficiently parse a space delimited list of > ints to array. Ireceived a good answer, but recently I discovered this: > auto a=" 1 2 3 4 5 " >.split(" ") >.filter!"!a.empty" >.map!"to

Type of complex expression

2013-02-27 Thread Lubos Pintes
Hi, Some time ago I asked how to efficiently parse a space delimited list of ints to array. Ireceived a good answer, but recently I discovered this: auto a=" 1 2 3 4 5 " .split(" ") .filter!"!a.empty" .map!"to!int(a)"; writeln(a); //writes [1, 2, 3, 4, 5] as expected. But: writeln(t

Re: std.concurrency.thisTid.send() feat. immutable(struct with several arrays)

2013-02-27 Thread Alexandr Druzhinin
27.02.2013 14:19, Jonathan M Davis пишет: On Wednesday, February 27, 2013 13:19:22 Alexandr Druzhinin wrote: This code doesn't compiles http://dpaste.dzfl.pl/706a0d12 But if you comment one of arrays it will do. I take a look at varaint.d but can't understand why two arrays cause this error. How