Re: phobos: What type to use instead of File when doing I/O on streams?

2015-11-09 Thread Ali Çehreli via Digitalmars-d-learn
On 11/09/2015 01:48 AM, J.Frank wrote: My question is now: How can I make this work without using deprecated stuff? import std.cstream; void foo(InputStream in_stream, OutputStream out_stream) { //in_stream.seek(3); // compile error - good :) char[] line; while ((line =

Providing custom formatting without importing half of phobos.

2015-11-09 Thread rumbu via Digitalmars-d-learn
Let's say that I'm a library provider and I intend to offer a completely new data type suitable for printing with format() or writef(). According to this tutorial (http://wiki.dlang.org/Defining_custom_print_format_specifiers), to achieve this, one must import at least std.format :

Split range that has no length or slice?

2015-11-09 Thread Spacen Jasset via Digitalmars-d-learn
I can't seem to find a way of splitting a range of characters into lines unless the range has a length or can be sliced? This presumably is because i is a range of chunks, which cannot have a length or a slice. I do not see how to get anything else from the File object at the moment. import

Re: Split range that has no length or slice?

2015-11-09 Thread Adam D. Ruppe via Digitalmars-d-learn
File has a .byLine and .byLineCopy method you could use to just get lines from it.

std.experimental.allocator optlink error

2015-11-09 Thread ref2401 via Digitalmars-d-learn
Hello I wrote a small hello world app and imported the `std.experimental.allocator` module. I'm getting the following optlink error: --- OPTLINK (R) for Win32 Release 8.00.17 Copyright (C) Digital Mars 1989-2013 All rights reserved.

Re: Associative arrays

2015-11-09 Thread TheFlyingFiddle via Digitalmars-d-learn
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

@property

2015-11-09 Thread Fyodor Ustinov via Digitalmars-d-learn
Hi! Why do need "@proprety" if everything works without it? WBR, Fyodor.

Re: @property

2015-11-09 Thread Alex Parrill via Digitalmars-d-learn
On Monday, 9 November 2015 at 21:56:22 UTC, Fyodor Ustinov wrote: Hi! Why do need "@proprety" if everything works without it? WBR, Fyodor. Check out the following code: struct Test { int foo() { return 2; }

Re: Split range that has no length or slice?

2015-11-09 Thread Spacen Jasset via Digitalmars-d-learn
On Monday, 9 November 2015 at 18:04:23 UTC, Alex Parrill wrote: On Monday, 9 November 2015 at 17:56:14 UTC, Alex Parrill wrote: On Monday, 9 November 2015 at 15:23:21 UTC, Spacen Jasset wrote: On Monday, 9 November 2015 at 14:58:19 UTC, Adam D. Ruppe wrote: File has a .byLine and .byLineCopy

Re: phobos: What type to use instead of File when doing I/O on streams?

2015-11-09 Thread Alex Parrill via Digitalmars-d-learn
On Monday, 9 November 2015 at 19:42:53 UTC, J.Frank wrote: On Monday, 9 November 2015 at 18:44:00 UTC, Alex Parrill wrote: Ranges are streams. file.byLine(Copy) and byChunk are effectively streams that are ranges. I might be wrong, but from what I read so far I don't think that "ranges are

Re: Associative arrays

2015-11-09 Thread Brian Schott via Digitalmars-d-learn
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

Re: why does this error out?

2015-11-09 Thread Cauterite via Digitalmars-d-learn
Here's the output I get (DMD v2.068.2): [1, 3, 10, 12, 21, 30, 100, 102, 111, 120, 201, 210] core.exception.AssertError@std\range\package.d(4603): Assertion failure

Re: why does this error out?

2015-11-09 Thread lobo via Digitalmars-d-learn
On Tuesday, 10 November 2015 at 04:34:22 UTC, Cauterite wrote: Here's the output I get (DMD v2.068.2): [1, 3, 10, 12, 21, 30, 100, 102, 111, 120, 201, 210] core.exception.AssertError@std\range\package.d(4603): Assertion failure iota.front() is complaining the range is empty from this line.

Re: std.experimental.allocator optlink error

2015-11-09 Thread ref2401 via Digitalmars-d-learn
On Monday, 9 November 2015 at 14:42:01 UTC, ref2401 wrote: Hello I wrote a small hello world app and imported the `std.experimental.allocator` module. I'm getting the following optlink error: --- OPTLINK (R) for Win32 Release 8.00.17 Copyright

Re: Providing custom formatting without importing half of phobos.

2015-11-09 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Nov 09, 2015 at 03:09:26PM +, rumbu via Digitalmars-d-learn wrote: > Let's say that I'm a library provider and I intend to offer a > completely new data type suitable for printing with format() or > writef(). > > According to this tutorial >

Re: Providing custom formatting without importing half of phobos.

2015-11-09 Thread rumbu via Digitalmars-d-learn
On Monday, 9 November 2015 at 16:11:23 UTC, H. S. Teoh wrote: On Mon, Nov 09, 2015 at 03:09:26PM +, rumbu via Digitalmars-d-learn wrote: [...] Do you need *custom* format specifiers? If all you need is to be able to write: format("%s", myData), then the only thing you need to do is to

Compile time digest error

2015-11-09 Thread tcak via Digitalmars-d-learn
[code] private static import std.digest.md; public enum HashValue = std.digest.digest.digest!( std.digest.md.MD5)( "" ); void main(){} [/code] [output] dmd main.d /usr/include/dmd/phobos/std/digest/md.d(202): Error: reinterpreting cast from uint[16] to ubyte* is not supported in CTFE

Re: phobos: What type to use instead of File when doing I/O on streams?

2015-11-09 Thread Alex Parrill via Digitalmars-d-learn
On Monday, 9 November 2015 at 18:18:19 UTC, J.Frank wrote: On Monday, 9 November 2015 at 14:48:35 UTC, Ali Çehreli wrote: import std.stdio; import std.range; void foo(I, O)(I in_stream, O out_stream) if (isInputRange!I && isOutputRange!(O, ElementType!I)) { //

Re: phobos: What type to use instead of File when doing I/O on streams?

2015-11-09 Thread J.Frank via Digitalmars-d-learn
On Monday, 9 November 2015 at 14:48:35 UTC, Ali Çehreli wrote: import std.stdio; import std.range; void foo(I, O)(I in_stream, O out_stream) if (isInputRange!I && isOutputRange!(O, ElementType!I)) { // in_stream.seek(3); // compile error - good :) foreach (element;

Re: Split range that has no length or slice?

2015-11-09 Thread Alex Parrill via Digitalmars-d-learn
On Monday, 9 November 2015 at 15:23:21 UTC, Spacen Jasset wrote: On Monday, 9 November 2015 at 14:58:19 UTC, Adam D. Ruppe wrote: File has a .byLine and .byLineCopy method you could use to just get lines from it. Ah yes. but unfortunately I don't want to do that. I want to pass a range into

Re: Split range that has no length or slice?

2015-11-09 Thread Alex Parrill via Digitalmars-d-learn
On Monday, 9 November 2015 at 17:56:14 UTC, Alex Parrill wrote: On Monday, 9 November 2015 at 15:23:21 UTC, Spacen Jasset wrote: On Monday, 9 November 2015 at 14:58:19 UTC, Adam D. Ruppe wrote: File has a .byLine and .byLineCopy method you could use to just get lines from it. Ah yes. but

Re: Split range that has no length or slice?

2015-11-09 Thread Spacen Jasset via Digitalmars-d-learn
On Monday, 9 November 2015 at 14:58:19 UTC, Adam D. Ruppe wrote: File has a .byLine and .byLineCopy method you could use to just get lines from it. Ah yes. but unfortunately I don't want to do that. I want to pass a range into my print function. i.e. Sometimes it may not be a File, it might

Re: Providing custom formatting without importing half of phobos.

2015-11-09 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 9 November 2015 at 15:09:28 UTC, rumbu wrote: The problem is that just importing FormatSpec will create exactly 88 phobos dependencies. I would pull request that to move it into its own independent module and then make std.format import that. I know that's not an immediate

Re: phobos: What type to use instead of File when doing I/O on streams?

2015-11-09 Thread J.Frank via Digitalmars-d-learn
On Monday, 9 November 2015 at 19:38:06 UTC, Ali Çehreli wrote: As far as I understand, the issue is to prevent the seek() call at compile time, right? If so, the range types that byLine() and byLineCopy() return does not have such a member function. I think the code achieves that goal because

Re: phobos: What type to use instead of File when doing I/O on streams?

2015-11-09 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 9 November 2015 at 19:49:15 UTC, J.Frank wrote: I'm looking for a replacement for the deprecated inferfaces InputStream and OutputStream. Just keep using them. The deprecated note isn't really important... they will still be in Phobos for another year and you can copy the file out

Re: phobos: What type to use instead of File when doing I/O on streams?

2015-11-09 Thread J.Frank via Digitalmars-d-learn
On Monday, 9 November 2015 at 18:44:00 UTC, Alex Parrill wrote: Ranges are streams. file.byLine(Copy) and byChunk are effectively streams that are ranges. I might be wrong, but from what I read so far I don't think that "ranges are streams": - Can you read an arbitrary length of bytes from

Re: phobos: What type to use instead of File when doing I/O on streams?

2015-11-09 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 9 November 2015 at 19:42:53 UTC, J.Frank wrote: (BTW. Where do I find select()/poll() in phobos?) They are in `core.sys.posix.sys.select` In general, OS headers for Posix in C like "sys/select.h" can be gotten by "import core.sys.posix.sys.select;" is in "core.sys.posix.unistd"

Re: phobos: What type to use instead of File when doing I/O on streams?

2015-11-09 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 9 November 2015 at 08:49:08 UTC, J.Frank wrote: Hm. "Maybe the stream is seekable, maybe it is not" is not really an option for a language that is supposed to be type safe. It just isn't known at compile time. Files, especially on Unix, are interchangeable at compile time but

Re: phobos: What type to use instead of File when doing I/O on streams?

2015-11-09 Thread Ali Çehreli via Digitalmars-d-learn
On 11/09/2015 10:18 AM, J.Frank wrote: On Monday, 9 November 2015 at 14:48:35 UTC, Ali Çehreli wrote: import std.stdio; import std.range; void foo(I, O)(I in_stream, O out_stream) if (isInputRange!I && isOutputRange!(O, ElementType!I)) { // in_stream.seek(3); //

why does this error out?

2015-11-09 Thread steven kladitis via Digitalmars-d-learn
void main() { import std.stdio, std.algorithm, std.range, std.conv; enum digSum = (int n) => n.text.map!(d => d - '0').sum; //enum harshads = iota(1, int.max).filter!(n => n % digSum(n) == 0); enum harshads = iota(1, 256).filter!(n => n % digSum(n) == 0);

Re: Associative arrays

2015-11-09 Thread TheFlyingFiddle via Digitalmars-d-learn
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: On 09/11/15 4:57 PM, TheFlyingFiddle wrote: [...] Nope. [...] As far as I'm aware, you are stuck using e.g. structs to emulate AA behavior. I have a VERY basic

AliasSeq + isExpression type specialization behavior

2015-11-09 Thread Brian Schott via Digitalmars-d-learn
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: @property

2015-11-09 Thread Fyodor Ustinov via Digitalmars-d-learn
On Monday, 9 November 2015 at 22:06:22 UTC, Alex Parrill wrote: Check out the following code: struct Test { int foo() { return 2; } int bar() @property { return 2; }

Re: Parse d source file by using compiler

2015-11-09 Thread ZombineDev via Digitalmars-d-learn
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

Re: phobos: What type to use instead of File when doing I/O on streams?

2015-11-09 Thread J.Frank via Digitalmars-d-learn
On Sunday, 8 November 2015 at 23:50:58 UTC, Adam D. Ruppe wrote: You don't, in general. stdin is sometimes seekable and the compiler doesn't know if it is or not until you try at runtime. Hm. "Maybe the stream is seekable, maybe it is not" is not really an option for a language that is

Re: phobos: What type to use instead of File when doing I/O on streams?

2015-11-09 Thread J.Frank via Digitalmars-d-learn
My question is now: How can I make this work without using deprecated stuff? import std.cstream; void foo(InputStream in_stream, OutputStream out_stream) { // in_stream.seek(3); // compile error - good :) char[] line; while ((line = in_stream.readLine()) !is null)

Re: std.experimental.allocator optlink error

2015-11-09 Thread uiop via Digitalmars-d-learn
On Monday, 9 November 2015 at 18:07:39 UTC, ref2401 wrote: On Monday, 9 November 2015 at 14:42:01 UTC, ref2401 wrote: Hello I wrote a small hello world app and imported the `std.experimental.allocator` module. I'm getting the following optlink error:

Re: Parse d source file by using compiler

2015-11-09 Thread Brian Schott via Digitalmars-d-learn
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

Re: Associative arrays

2015-11-09 Thread rsw0x via Digitalmars-d-learn
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.

Re: Associative arrays

2015-11-09 Thread Brian Schott via Digitalmars-d-learn
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.