Re: Endiannes & Splitting Values

2016-07-06 Thread Alex Parrill via Digitalmars-d-learn
On Wednesday, 6 July 2016 at 21:44:37 UTC, BitGuy wrote: I'm trying to implement a feistel cipher that'll give the same results regardless of the endianness of the machine it runs on. To make the cipher I need to split a 64bit value into two 32bit values, mess with them, and then put them back

Re: Dynamic array of objects

2016-06-27 Thread Alex Parrill via Digitalmars-d-learn
On Monday, 27 June 2016 at 22:00:15 UTC, gummybears wrote: Hi, Today thought lets learn D. I am writing a compiler for a language and read D compiles very fast. Switched my compiler from C++ to D and ran my test suite to use D. Doing somethin wrong as creating array of objects gives me a seg

Re: arsd png bug

2016-06-20 Thread Alex Parrill via Digitalmars-d-learn
On Monday, 20 June 2016 at 21:39:45 UTC, Joerg Joergonson wrote: 1810: case 3: auto arr = data.dup; foreach(i; 0 .. arr.length) { auto prev = i < bpp ? 0 : arr[i - bpp];

Re: Strange Issues regarding aliases

2016-06-14 Thread Alex Parrill via Digitalmars-d-learn
On Tuesday, 14 June 2016 at 17:37:40 UTC, Joerg Joergonson wrote: On Tuesday, 14 June 2016 at 17:34:42 UTC, Joerg Joergonson wrote: This is how derelict does it, I simply moved them in to the class for simplicity. I mean glad: http://glad.dav1d.de/ It seems that a loader is required for some

Re: Fibers, what for?

2016-06-12 Thread Alex Parrill via Digitalmars-d-learn
On Sunday, 12 June 2016 at 08:38:03 UTC, chmike wrote: Fibers don't need synchronization to access shared data. This removes the overhead of synchronization and simplifies "multitheaded" programming greatly. This is misleading. Any sort of cooperative system needs synchronization when two or

Re: Why can't I assign a mixin to an alias?

2016-06-10 Thread Alex Parrill via Digitalmars-d-learn
On Saturday, 11 June 2016 at 02:46:00 UTC, Adam D. Ruppe wrote: On Saturday, 11 June 2016 at 02:33:46 UTC, Alex Parrill wrote: Mixins are statements. No, they're not. Well, yes they are [1], but there are also mixin expressions [2]. Not to be confused with the TemplateMixin[3], which is inde

Re: Why can't I assign a mixin to an alias?

2016-06-10 Thread Alex Parrill via Digitalmars-d-learn
On Friday, 10 June 2016 at 22:38:29 UTC, Dechcaudron wrote: I have the following code: private string getVariableSignalWrappersName(VarType)() { return VarType.stringof ~ "SignalWrappers"; } void addVariableListener(VarType)(int variableIndex, void delegate(int, VarType)) { alias typ

Re: Parse File at compile time, but not embedded

2016-06-10 Thread Alex Parrill via Digitalmars-d-learn
On Thursday, 9 June 2016 at 22:02:44 UTC, Joerg Joergonson wrote: On Tuesday, 7 June 2016 at 22:09:58 UTC, Alex Parrill wrote: Accessing a SQL server at compile time seems like a huge abuse of CTFE (and I'm pretty sure it's impossible at the moment). Why do I need to install and set up a MySQL

Re: Parse File at compile time, but not embedded

2016-06-07 Thread Alex Parrill via Digitalmars-d-learn
On Monday, 6 June 2016 at 21:57:20 UTC, Pie? wrote: On Monday, 6 June 2016 at 21:31:32 UTC, Alex Parrill wrote: But reading sensitive data at compile-time strikes me as dangerous, depending on your use case. If you are reading sensitive information at compile time, you are presumably going to

Re: Error: mutable method isolated.graphics.g3d.model.Model.begin is not callable using a const object

2016-06-07 Thread Alex Parrill via Digitalmars-d-learn
On Monday, 6 June 2016 at 21:55:00 UTC, ag0aep6g wrote: On 06/06/2016 11:25 PM, Alex Parrill wrote: You might be able to get away with casting the const away, if you are sure it won't modify the hash or equality check. Casting away const and then mutating has undefined behavior. The compiler

Re: Enum that can be 0 or null

2016-06-07 Thread Alex Parrill via Digitalmars-d-learn
On Tuesday, 7 June 2016 at 04:31:56 UTC, ParticlePeter wrote: On Monday, 6 June 2016 at 20:32:23 UTC, Alex Parrill wrote: They'd be the same type, since you would define the vulkan functions to take these structures instead of pointer or integer types. It relies on a lot of assumptions about

Re: Parse File at compile time, but not embedded

2016-06-06 Thread Alex Parrill via Digitalmars-d-learn
On Monday, 6 June 2016 at 17:31:52 UTC, Pie? wrote: Is it possible to parse a file at compile time without embedding it into the binary? I have a sort of "configuration" file that defines how to create some objects. I'd like to be able to read how to create them but not have that config file

Re: Error: mutable method isolated.graphics.g3d.model.Model.begin is not callable using a const object

2016-06-06 Thread Alex Parrill via Digitalmars-d-learn
On Monday, 6 June 2016 at 21:16:18 UTC, Begah wrote: Does the key of a associative array will be const if the reference is requested? That's probably what it is, actually. Modifying the key with the ref could cause the hash of the key to change without the hashtable knowing about it, causing

Re: Error: mutable method isolated.graphics.g3d.model.Model.begin is not callable using a const object

2016-06-06 Thread Alex Parrill via Digitalmars-d-learn
On Monday, 6 June 2016 at 20:40:12 UTC, Begah wrote: I have a pretty weird error : Error: mutable method isolated.graphics.g3d.model.Model.begin is not callable using a const object [...] It may infer const from the type of `this.instance`, which may be further modified if the method you ar

Re: Enum that can be 0 or null

2016-06-06 Thread Alex Parrill via Digitalmars-d-learn
On Monday, 6 June 2016 at 18:43:33 UTC, ParticlePeter wrote: On Saturday, 21 May 2016 at 06:36:53 UTC, tsbockman wrote: ... As an example, if VK_NULL_HANDLE only ever needs to be assigned to opaque types on the D side (that is, types that serve only as an ID or address for communicating with t

Re: Emulate C's (polymorphic) NULL type

2016-06-06 Thread Alex Parrill via Digitalmars-d-learn
On Monday, 6 June 2016 at 18:33:36 UTC, ParticlePeter wrote: On Monday, 6 June 2016 at 16:19:02 UTC, Alex Parrill wrote: On Monday, 6 June 2016 at 09:43:23 UTC, ParticlePeter wrote: In C NULL can be used as integer as well as null pointer. Is there a way to create such a type in D? The type sh

Re: Emulate C's (polymorphic) NULL type

2016-06-06 Thread Alex Parrill via Digitalmars-d-learn
On Monday, 6 June 2016 at 09:43:23 UTC, ParticlePeter wrote: In C NULL can be used as integer as well as null pointer. Is there a way to create such a type in D? The type should have only one value which is obviously (0/null). A extern( C ) function should be able to take it as either one. Over

Re: Why do some T.init evaluate to true while others to false?

2016-05-30 Thread Alex Parrill via Digitalmars-d-learn
On Friday, 27 May 2016 at 15:49:16 UTC, ArturG wrote: On Friday, 27 May 2016 at 15:24:18 UTC, Adam D. Ruppe wrote: On Friday, 27 May 2016 at 15:19:50 UTC, ArturG wrote: yes but i have to check for that when some one does Why? This is no different than if they set any of the other four billio

Re: Why simple code using Rebindable doesn't compile ?

2016-05-30 Thread Alex Parrill via Digitalmars-d-learn
On Monday, 30 May 2016 at 10:09:19 UTC, chmike wrote: This code compile, but array appending doesn't work alias Rebindable!(immutable(InfoImpl)) Info; class InfoImpl { void foo() {} static immutable(InfoImpl) info() { __gshared immutable InfoImpl x = new immutable InfoI

Re: Testing array ptr for offset 0...

2016-05-26 Thread Alex Parrill via Digitalmars-d-learn
On Thursday, 26 May 2016 at 07:51:46 UTC, Era Scarecrow wrote: ... This smells like an XY problem [0]. Why exactly do you need the internal layout of the array structure? The line "not having to make another array to keep track of lengths and then shorten them" is fairly vague. "Shortening"

Re: Enum that can be 0 or null

2016-05-20 Thread Alex Parrill via Digitalmars-d-learn
On Saturday, 21 May 2016 at 02:04:23 UTC, Mike Parker wrote: On Saturday, 21 May 2016 at 01:09:42 UTC, Alex Parrill wrote: Looks like my best bet is to mark it as deprecated and point them to Vk(Type).init instead. I would prefer to do something like this: enum VK_NULL_HANDLE_0 = 0; enum V

Re: Enum that can be 0 or null

2016-05-20 Thread Alex Parrill via Digitalmars-d-learn
On Friday, 20 May 2016 at 22:10:51 UTC, tsbockman wrote: Why do you need to? Just use null for pointer types, and 0 for integers. D is not C; you aren't *supposed* to be able to just copy-paste any random C snippet into D and expect it to work without modification. If that's not a satisfact

Enum that can be 0 or null

2016-05-20 Thread Alex Parrill via Digitalmars-d-learn
(How) can I make a constant that is either zero or null depending on how it is used? Vulkan has a VK_NULL_HANDLE constant which in C is defined to be zero. It is used as a null object for several types of objects. In D however, zero is not implicitly convertible to a null pointer, and vice ve

Re: ErrorException thrown when errno is modified ?

2016-05-19 Thread Alex Parrill via Digitalmars-d-learn
On Thursday, 19 May 2016 at 13:05:19 UTC, chmike wrote: Hello, I'm planning to call some posix functions core.sys.posix that may set the errno value in case of error. e.g. read() or write(). Checking the std.exception documentation I see that ErrnoException may be thrown when errors setting

Re: Single-Allocation Variable-Sized Array

2016-05-18 Thread Alex Parrill via Digitalmars-d-learn
On Wednesday, 18 May 2016 at 21:28:56 UTC, Nordlöw wrote: What's the preferred way in D to implement single-allocation variable-sized arrays such as /** Single-Allocation Array. */ struct ArrayN { ubyte length; // <= maxLength size room; // allocated length ubyte[0] data; // `r

Re: parameter pack to inputRange

2016-05-09 Thread Alex Parrill via Digitalmars-d-learn
On Sunday, 8 May 2016 at 14:11:31 UTC, Ali Çehreli wrote: I like Alex Parrill's only() solution but it allocates a dynamic array as well by doing the equivalent of [args] in the guts of its implementation. No it does not. The constructor does `this.data = [values];`, but `this.data` is a fix

Re: parameter pack to inputRange

2016-05-06 Thread Alex Parrill via Digitalmars-d-learn
On Friday, 6 May 2016 at 05:00:48 UTC, Erik Smith wrote: Is there an existing way to adapt a parameter pack to an input range? I would like to construct an array with it. Example: void run(A...) (A args) { Array!int a(toInputRange(args)); } Use std.range.only: http://dlang.org/phobos/st

Re: what's the right way to get char* from string?

2016-05-05 Thread Alex Parrill via Digitalmars-d-learn
On Thursday, 5 May 2016 at 07:49:46 UTC, aki wrote: extern (C) int strcmp(char* string1, char* string2); This signature of strcmp is incorrect. strcmp accepts const char* arguments [1], which in D would be written as const(char)*. The immutable(char)* values returned from toStringz are implic

Re: what is equivalent to template template

2016-05-03 Thread Alex Parrill via Digitalmars-d-learn
On Tuesday, 3 May 2016 at 21:31:35 UTC, Erik Smith wrote: C++ has template templates. I'm not sure how to achieve the same effect where (in example below) the template function myVariadic is passed to another function. void myVaridatic(A...)(A a) {} static void call(alias F,A

Re: constructed variadic call

2016-05-03 Thread Alex Parrill via Digitalmars-d-learn
On Monday, 2 May 2016 at 18:22:52 UTC, Erik Smith wrote: Is there way to construct an "argument pack" from a non-static array (like the switch below)? I need to transport a variadic call through a void*. switch (a.length) { case 1: foo(a[1]); break; case 2: foo(a[1], a[2]); break; case

Re: Garbage Collector : Ignoring a reference

2016-04-26 Thread Alex Parrill via Digitalmars-d-learn
On Tuesday, 26 April 2016 at 09:07:59 UTC, Begah wrote: I am trying to create an asset manager for my textures. I had the idea ( it may be a wrong idea ) to create a hashmap of my textures with a string as the key. When the program request a texture, it firts check if it is in the hashmap and t

Re: Handling arbitrary char ranges

2016-04-20 Thread Alex Parrill via Digitalmars-d-learn
On Wednesday, 20 April 2016 at 22:44:37 UTC, ag0aep6g wrote: On 20.04.2016 23:59, Alex Parrill wrote: On Wednesday, 20 April 2016 at 17:09:29 UTC, Matt Kline wrote: [...] First, you can't assign anything to a void[], for the same reason you can't dereference a void*. This includes the slice

Re: Handling arbitrary char ranges

2016-04-20 Thread Alex Parrill via Digitalmars-d-learn
On Wednesday, 20 April 2016 at 17:09:29 UTC, Matt Kline wrote: [...] First, you can't assign anything to a void[], for the same reason you can't dereference a void*. This includes the slice assignment that you are trying to do in `buf[0..minLen] = remainingData[0..minLen];`. Cast the buffe

Re: VariantPointer

2016-04-20 Thread Alex Parrill via Digitalmars-d-learn
On Wednesday, 20 April 2016 at 13:41:27 UTC, Nordlöw wrote: At https://github.com/nordlow/phobos-next/blob/master/src/variant_pointer.d I've implemented a pointer-only version of Variant called VariantPointer. I plan to use it to construct light-weight polymorphism in trie containers for D

Re: Shallow copy object when type is know

2016-04-20 Thread Alex Parrill via Digitalmars-d-learn
On Wednesday, 20 April 2016 at 12:32:48 UTC, Tofu Ninja wrote: Is there a way to shallow copy an object when the type is known? I cant seem to figure out if there is a standard way. I can't just implement a copy function for the class, I need a generic solution. A generic class copy function

Re: Handling arbitrary char ranges

2016-04-20 Thread Alex Parrill via Digitalmars-d-learn
On Wednesday, 20 April 2016 at 17:09:29 UTC, Matt Kline wrote: I'm doing some work with a REST API, and I wrote a simple utility function that sets an HTTP's onSend callback to send a string: [...] IO functions usually work with octets, not characters, so an extra encoding step is needed. F

Re: .opAssign disabled without @disable

2016-04-16 Thread Alex Parrill via Digitalmars-d-learn
On Saturday, 16 April 2016 at 11:48:56 UTC, denizzzka wrote: Hi! DMD and LDC2 complain about disabled opAssign, but I am not used @disable and depend package "gfm" also isn't uses @disable. ... Try removing the const from this line: debug private const bool isLeafNode = false; I suspect t

Re: Lazy evaluation of function pointers.

2016-04-10 Thread Alex Parrill via Digitalmars-d-learn
On Sunday, 10 April 2016 at 18:08:58 UTC, Ryan Frame wrote: Greetings. The following code works: void main() { passfunc(&func); } void passfunc(void function(string) f) { f("Hello"); } void func(string str) { import std.stdio : writeln; writeln(str); } Now if I change passfun

Re: Fiber and Thread Communication

2016-04-08 Thread Alex Parrill via Digitalmars-d-learn
On Friday, 8 April 2016 at 14:08:39 UTC, Nordlöw wrote: So a TId can represent either a thread or a fiber? It represents a "logical thread", which currently consists of coroutines or OS threads but could theoretically be extended to, say, other processes or even other machines.

Re: __traits(compiles) and template instantiation

2016-04-07 Thread Alex Parrill via Digitalmars-d-learn
On Thursday, 7 April 2016 at 20:31:12 UTC, jmh530 wrote: I've been playing around with __traits and I find myself confused on one aspect. In the code below, I was testing whether some templates would compile given types. For the most part it works as I would expect. I think I get why the thir

Re: Best properly way to destroy a 2 dimensional array?

2016-04-06 Thread Alex Parrill via Digitalmars-d-learn
On Wednesday, 6 April 2016 at 23:14:10 UTC, Jonathan Villa wrote: On Wednesday, 6 April 2016 at 21:33:14 UTC, Alex Parrill wrote: My general idea is first to get the predicted quantity of combinations Seems like you already know; your OP says you have 2^n combinations. so I can divide and

Re: Putting things in an enum's scope

2016-04-06 Thread Alex Parrill 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? It can sometimes help with code organization. For example, this is something that coming from Java I'd have expected to be vali

Re: Best properly way to destroy a 2 dimensional array?

2016-04-06 Thread Alex Parrill via Digitalmars-d-learn
On Wednesday, 6 April 2016 at 19:54:32 UTC, Jonathan Villa wrote: I wrote a little program that given some number it generates a list of different combinations (represented by a ubyte array), so in the end my function with name GenerateCombinations(int x) returns a ubyte[][] (list of arrays of

Re: What's the rationale for considering "0x1.max" as invalid ?

2016-04-06 Thread Alex Parrill via Digitalmars-d-learn
On Tuesday, 5 April 2016 at 21:40:59 UTC, Basile B. wrote: On Tuesday, 5 April 2016 at 21:10:47 UTC, Basile B. wrote: On Tuesday, 5 April 2016 at 20:56:54 UTC, Alex Parrill wrote: On Tuesday, 5 April 2016 at 19:00:43 UTC, Basile B. wrote: 0x1.max // exponent expected in hex float 0x1 .max // O

Re: What is the best way to store bitarray (blob) for pasting in database?

2016-04-06 Thread Alex Parrill via Digitalmars-d-learn
On Wednesday, 6 April 2016 at 12:56:39 UTC, Suliman wrote: I have next task. There is PostgreSQL DB. With field like: id, mydata. mydata - is binary blob. It can be 10MB or even more. I need load all data from PostgreSQL to SQLLite. I decided ti create struct that and fill it with data. And th

Re: What's the rationale for considering "0x1.max" as invalid ?

2016-04-05 Thread Alex Parrill via Digitalmars-d-learn
On Tuesday, 5 April 2016 at 19:00:43 UTC, Basile B. wrote: 0x1.max // exponent expected in hex float 0x1 .max // OK 1.max // OK What's the ambiguity when it's an hex literal ? It's potentially ambiguous with hexadecimal floating point numbers 0xdeadbeef.p5 // hex float or hex int + method? d

Re: Need help with delegates and vibed

2016-03-19 Thread Alex Parrill via Digitalmars-d-learn
On Saturday, 19 March 2016 at 19:53:01 UTC, Suliman wrote: Thanks! I am understand a little bit better, but not all. ``` shared static this() { auto settings = new HTTPServerSettings; settings.port = 8080; listenHTTP(settings, &handleRequest); } void handleRequest(HTTPS

Re: Error: constructor Foo.this default constructor for structs only allowed with @disable, no body, and no parameters

2016-03-07 Thread Alex Parrill via Digitalmars-d-learn
On Monday, 7 March 2016 at 13:23:58 UTC, Nicholas Wilson wrote: I'm not quite sure what this error is saying. Is it that the only struct constructor that can have no parameters is @disable this(){} ? Yes, this is exactly right. You cannot have a structure with a default constructor, except wi

Re: std.range: Lockstep vs. Zip

2016-03-03 Thread Alex Parrill via Digitalmars-d-learn
On Wednesday, 2 March 2016 at 08:51:07 UTC, Manuel Maier wrote: Hi there, I was wondering why I should ever prefer std.range.lockstep over std.range.zip. In my (very limited) tests std.range.zip offered the same functionality as std.range.lockstep, i.e. I was able to iterate using `foreach(ke

Re: Combining template conditions and contracts?

2016-02-29 Thread Alex Parrill via Digitalmars-d-learn
On Monday, 29 February 2016 at 14:38:52 UTC, Ozan wrote: Is it possible to combine template conditions and contracts? Like in the following T square_root(T)(T x) if (isBasicType!T) { in { assert(x >= 0); } out (result) { assert((result * result) <= x && (result+1) * (result+1) > x);

Re: Why file.exists of relative path on Linux always return false?

2016-02-29 Thread Alex Parrill via Digitalmars-d-learn
On Monday, 29 February 2016 at 14:50:51 UTC, Suliman wrote: I am trying to check relative path on Linux for exists. import std.stdio; import std.path; import std.file; import std.string; string mypath = "~/Documents/imgs"; void main() { if(!mypath.exists) { writeln(m

Re: C Macro deeper meaning?

2016-01-31 Thread Alex Parrill via Digitalmars-d-learn
On Sunday, 31 January 2016 at 02:58:28 UTC, Andrew Edwards wrote: If I understand correctly, this piece of code: enum NOTUSED(v) do { (void)(1 ? (void)0 : ( (void)(v) ) ); } while(0) can be converted to the following in D: void notUsed(T)(T v) { return cast(void)0; }; since it always

Re: link to C++ function in a namespace whose name is a D keyword

2016-01-06 Thread Alex Parrill via Digitalmars-d-learn
On Wednesday, 6 January 2016 at 18:35:07 UTC, Carl Sturtivant wrote: Hello, From D I want to call e.g. /* C++ prototype */ namespace ns { int try(int x); } without writing a C or C++ wrapper. Presumably the following D doesn't work, because it doesn't mangle the name as if it's in the na

Re: Nothrow front() when not empty()

2016-01-06 Thread Alex Parrill via Digitalmars-d-learn
On Wednesday, 6 January 2016 at 14:17:51 UTC, anonymous wrote: try return !haystack.empty && pred(haystack.front); Might want to use std.exception.assumeWontThrow instead return assumeWontThrow(!haystack.empty && pred(haystack.front)); http://dlang.org/phobos/std_exception.html#.assumeW

Re: reduce a BitArray[]

2015-12-29 Thread Alex Parrill via Digitalmars-d-learn
On Tuesday, 29 December 2015 at 09:26:31 UTC, Alex wrote: The problem is, that the last line with the reduce does not compile. Why? If you get an error, it is imperative that you tell us what it is. For the record, this code: import std.bitmanip; import std.stdio; impo

Re: argument type const char* can pass string, buf why const wchar* can not pass wstring

2015-12-26 Thread Alex Parrill via Digitalmars-d-learn
On Sunday, 27 December 2015 at 03:34:18 UTC, riki wrote: void ccf(const char* str){} void cwf(const wchar* str){} void main() { ccf("aaa");//ok cwf("xxx"w); // error and why ? } Unrelated to your error, but those functions should probably take a `string` and `wstring` respectively

Re: Convert to string an enum item

2015-12-23 Thread Alex Parrill via Digitalmars-d-learn
On Wednesday, 23 December 2015 at 13:11:28 UTC, tcak wrote: [code] import std.stdio; import std.conv; enum Values: ubyte{ One = 1, Two = 2 } void main(){ writeln( std.conv.to!string( Values.One ) ); } [/code] Output is "One". casting works, but to be able to cast correctly, I need to

Re: Why should file names intended for executables be valid identifiers?

2015-12-17 Thread Alex Parrill via Digitalmars-d-learn
On Tuesday, 15 December 2015 at 03:31:18 UTC, Shriramana Sharma wrote: I expect it should not be difficult for the compiler to see that this D file is not a module being imported by anything else or even being compiled to a library which would need to be later imported. In which case, why does

Re: deep copying / .dup / template object.dup cannot deduce function from argument types

2015-12-13 Thread Alex Parrill via Digitalmars-d-learn
On Sunday, 13 December 2015 at 18:54:24 UTC, Robert M. Münch wrote: Hi, I just wanted to naively copy an object and used: a = myobj.dup; and get the following error messages: source/app.d(191): Error: template object.dup cannot deduce function from argument types !()(BlockV), candidates are:

Re: AA struct hashing bug?

2015-12-07 Thread Alex Parrill via Digitalmars-d-learn
On Monday, 7 December 2015 at 18:48:18 UTC, Random D user wrote: struct Foo { this( int k ) { a = k; } int a; } Foo foo; int[ Foo ] map; map[ foo ] = 1; // Crash! bug? // This also crashes. I believe crash above makes a call like this (or similar) in the rt. //auto h

Re: How do you create an opengl window with DerelictOrg?

2015-12-07 Thread Alex Parrill via Digitalmars-d-learn
On Monday, 7 December 2015 at 21:33:57 UTC, Enjoys Math wrote: I've seen these: https://github.com/DerelictOrg?page=1 BUt not sure how to use them, examples? Derelict is just bindings for other libraries, for using C libraries with D. Pick a library that does windows management (I use GLFW,

Re: mutex usage problem?

2015-12-02 Thread Alex Parrill via Digitalmars-d-learn
On Wednesday, 2 December 2015 at 13:55:02 UTC, Ish wrote: The following code does core dump (compiled with gdc). Pointers will be appreciated. import std.stdio; import std.conv; import std.math; import std.concurrency; import core.thread; import core.sync.mutex; enum count = 5; __gshared double

Re: std.socket replacement

2015-11-29 Thread Alex Parrill via Digitalmars-d-learn
On Sunday, 29 November 2015 at 09:12:14 UTC, tired_eyes wrote: On Sunday, 29 November 2015 at 09:05:37 UTC, tcak wrote: On Sunday, 29 November 2015 at 08:56:30 UTC, tired_eyes wrote: I was a bit surprised to see that std.socket is deprecated as of 2.069. Just curious, what's wrong with it? And

Re: Password Storage

2015-11-26 Thread Alex Parrill via Digitalmars-d-learn
On Friday, 27 November 2015 at 00:50:25 UTC, brian wrote: Thanks for the blatant faux pas. I wasn't going to use MD5, I just meant "hash it somehow", which was not apparent from my question. My bad. Algorithm aside, the rest of that approach seems sensible then? The hash implementation was p

Re: Password Storage

2015-11-26 Thread Alex Parrill via Digitalmars-d-learn
On Friday, 27 November 2015 at 00:17:34 UTC, brian wrote: I'm starting to build a small web-based application where I would like to authenticate users, and hence need to store passwords. After reading this: http://blog.codinghorror.com/youre-probably-storing-passwords-incorrectly/ and many oth

Re: Exit with code xx

2015-11-25 Thread Alex Parrill via Digitalmars-d-learn
On Wednesday, 25 November 2015 at 16:11:09 UTC, Ozan wrote: Hi Is there any overview, list, wiki about what's behind runtime errors like "Program exited with code -11"? Okay, I made a mistake...but it's better to know where and what kind? Thanks & Regards, Ozan You know about process exi

Re: scope keyword

2015-11-20 Thread Alex Parrill via Digitalmars-d-learn
On Thursday, 19 November 2015 at 23:16:04 UTC, Spacen Jasset wrote: I thought scope was deprecated, but I see that this is still here: http://dlang.org/attribute.html#scope Is it just the uses on classes and local variables that are discouraged, but the use in a function signature will continu

Re: template this and traits getOverloads issue.

2015-11-20 Thread Alex Parrill via Digitalmars-d-learn
Alternatively, you can use a static method and pass in the instance. Note that `new B` will print A's members twice, because A's constructor is always called and `__traits(allMembers, B)` includes A's members. --- import std.stdio; mixin template Bug() { import std.traits; static v

Re: template this and traits getOverloads issue.

2015-11-20 Thread Alex Parrill via Digitalmars-d-learn
On Friday, 20 November 2015 at 14:01:13 UTC, BBasile wrote: Background: === http://stackoverflow.com/questions/33764540/warning-about-overriden-methods-when-using-a-mixin Why this horrible trick has to be used: === cast this as (T) in a function temp

Re: A new instance of a variable?

2015-11-13 Thread Alex Parrill via Digitalmars-d-learn
On Friday, 13 November 2015 at 15:49:01 UTC, Ish wrote: foreach (i; 0..5) { immutable int j = i; etc. } I want each j to be assigned separate memory so that it can be passed to a calle function and not overwritten by next value of i in foreach()?? Just like in C, you'll have to allocate

Re: AliasSeq + isExpression type specialization behavior

2015-11-10 Thread Alex Parrill via Digitalmars-d-learn
On Monday, 9 November 2015 at 22:41:50 UTC, Brian Schott wrote: 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 a

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: 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 st

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)) { // in_stream

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 unfo

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 m

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

2015-11-08 Thread Alex Parrill via Digitalmars-d-learn
On Sunday, 8 November 2015 at 20:47:08 UTC, J.Frank wrote: Hello again, I'm a bit puzzled by the "File" type. Looking at the implementation, it seems that all I/O functions were stuffed into a single class^H^H^H^H^Hstruct. What I expected to find is some kind of "Stream" class (with read(), w

Re: parallel

2015-11-05 Thread Alex Parrill via Digitalmars-d-learn
On Thursday, 5 November 2015 at 20:30:05 UTC, Handyman wrote: Seems that 4 cores go all out on first 4 dishes, then 1 core deals with the last dish. With 4 cores I expect diner is ready after 5/4 = 1.25 secs though. What did I do wrong? The first four dishes get scheduled, all of them sleep

Re: Default method implementations in interfaces?

2015-10-23 Thread Alex Parrill via Digitalmars-d-learn
On Friday, 23 October 2015 at 14:58:43 UTC, pineapple wrote: Is it possible to have default method implementations in interfaces à la Java in D? Or some equivalent that allows multiple inheritance without a bunch of identical copypasted method bodies? Use template mixins: http://dlang.org/tem

Re: dynamic get from variantArray() data table

2015-10-13 Thread Alex Parrill via Digitalmars-d-learn
On Tuesday, 13 October 2015 at 16:22:36 UTC, data pulverizer wrote: Thanks for the suggestion Alex, however I need the dynamic behaviour properties of variantArray(), writing a struct each time would be undesirable. Perhaps I could boil down the question to something like, is there a way of w

Re: dynamic get from variantArray() data table

2015-10-13 Thread Alex Parrill via Digitalmars-d-learn
On Tuesday, 13 October 2015 at 15:17:15 UTC, data pulverizer wrote: Hi, I am trying to use variantArray() as a data table object to hold columns each of which is an array of a specific type. I need to be able to get values from data table but I am having problems ... import std.stdio; // i

Re: What difference between std.typecons.Tuple and std.meta.AliasSeq

2015-09-20 Thread Alex Parrill via Digitalmars-d-learn
On Sunday, 20 September 2015 at 18:10:49 UTC, Suliman wrote: Sometimes it's hard to understand the D philosophy, for example now I can't understand diffrence between std.typecons.Tuple and std.meta.AliasSeq. I know that in language like Python there is spatial data type named tuple like: tup1

Re: [Code Example for Beginners (like me)] Sockets with Fibers

2015-09-18 Thread Alex Parrill via Digitalmars-d-learn
On Friday, 18 September 2015 at 07:58:10 UTC, ddos wrote: hello! yesterday i got curious about how fibers work, and if the can be used as a replacement in network programming. so i started hacking a small example together, which is hopefully useful to other D beginners too :) http://pastebi

Re: char[] ported from C to char[0] in the D core library

2015-09-09 Thread Alex Parrill via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 16:49:39 UTC, badlink wrote: The struct core.sys.linux.sys.inotify.inotify_event contains the field "char[0] name" which corresponds to "char name[]" in C. Why it has been translated to "char[0]" ? For me "char*" would have been more appropriate. It's a flex

Re: Abstractioning away main/winMain

2015-09-04 Thread Alex Parrill via Digitalmars-d-learn
On Saturday, 5 September 2015 at 02:29:05 UTC, Prudence wrote: If I use functions instead of delegates it works. I suppose the problem then is that the delegate can't create a fat pointer when used in a static context. (i.e., why the functions work) The question is, then, Can I construct a d

Re: MmFile : Is this std.mmFile BUG?

2015-08-26 Thread Alex Parrill via Digitalmars-d-learn
On Wednesday, 26 August 2015 at 15:49:23 UTC, Junichi Nakata wrote: Hi, all. I have a question. When 'testdic' file does' t exist, something wrong. --- import std.mmFile; int main() { auto x = new MmFile("testdic",MmFile.Mode.readWrite,0,null); return 0; } --- OSX 10.10.3 , DMD64 D Compil

Re: Adding UDA at compile time

2015-08-26 Thread Alex Parrill via Digitalmars-d-learn
On Wednesday, 26 August 2015 at 14:29:30 UTC, Andrea Fontana wrote: __traits(setAttributes, ...) It would be useful, for example, if I have a list of functions to mark. Let's say enum toExport = ["oldFunction", "thisToo"]; foreach(d; toExport) __traits(setAttributes, ...); Lots of compile-

Re: Adding UDA at compile time

2015-08-26 Thread Alex Parrill via Digitalmars-d-learn
On Wednesday, 26 August 2015 at 08:19:04 UTC, Andrea Fontana wrote: I wonder if there's a way to add UDA to functions at compile-time (so I can read later from other parts of application). Andrea What do you mean? UDAs are already specified at compile time. @("hello") void

Re: Promises/A+ spec implementations?

2015-08-19 Thread Alex Parrill via Digitalmars-d-learn
On Wednesday, 19 August 2015 at 04:18:03 UTC, Alexander J. Vincent wrote: Hi, folks. Over ten years ago I had some interest in the D language. I'm starting to think about it again... I've been using Mozilla's Promises implementations for quite a while, now, and they're surprisingly nice to w

Re: D Classes Passed By Reference or Value?

2015-08-16 Thread Alex Parrill via Digitalmars-d-learn
On Sunday, 16 August 2015 at 22:31:02 UTC, Brandon Ragland wrote: Hi All, I'm a bit confused as to how Classes in D are passed in arguments and returns. Take this for example: class MyClass{ int x = 2; } And then in app.d ref MyClass doStuff(){ MyClass mc = new MyClass() // Heap allocation,

Re: D Classes Passed By Reference or Value?

2015-08-16 Thread Alex Parrill via Digitalmars-d-learn
On Sunday, 16 August 2015 at 22:31:02 UTC, Brandon Ragland wrote: ref MyClass doStuff(){ MyClass mc = new MyClass() // Heap allocation, using new return mc; } This attempts to return a reference to the _variable_ `mc`, not a reference to the class. Just remove `ref` from the function sig

Re: Dynamic array and foreach loop

2015-08-09 Thread Alex Parrill via Digitalmars-d-learn
On Sunday, 9 August 2015 at 15:37:23 UTC, Binarydepth wrote: So I should use the REF like this ? import std.stdio : writeln; void main() { immutable a=5; int[a] Arr; foreach(num; 0..a) { Arr[num] = num; } foreach(num, ref ele; Arr

Re: Removing elements from dynamic array

2015-08-09 Thread Alex Parrill via Digitalmars-d-learn
On Sunday, 9 August 2015 at 15:30:32 UTC, Reflexive wrote: I wrote import std.algorithm.remove ;, and I dont have any longer any error. But, it dont want to remove the item. Here is the source, the problem is in the shuffle() method : ... Why not just use std.random.shuffle [1]? import

Re: Thread communication

2015-08-05 Thread Alex Parrill via Digitalmars-d-learn
On Wednesday, 5 August 2015 at 14:31:20 UTC, Marc Schütz wrote: Maybe we can lift this restriction if we know that the thread's main function is pure and takes no references to mutable data, because then it can by definition never mess up the program's state. That'd be a pretty useless thread

Re: GLU in DerelictOrg

2015-07-24 Thread Alex Parrill via Digitalmars-d-learn
On Friday, 24 July 2015 at 12:56:29 UTC, Spacen Jasset wrote: Thanks Mike, that's fair enough. I shall just implement the functions I need I think until such time as I end up using the newer OpenGL 3 stuff. If you want, you can steal from Mesa's GLU implementation here: http://cgit.freedeskto

Re: Thread pools

2015-07-22 Thread Alex Parrill via Digitalmars-d-learn
On Wednesday, 22 July 2015 at 14:28:48 UTC, Chris wrote: What would be the best way to manage different threads (spawned via std.concurrency), e.g. to tell them to stop at once, once a new command comes in? A thread pool? How would that look like in D? I feel my knowledge of D threads is still

Re: How do i sanitize a string for database query?

2015-07-21 Thread Alex Parrill via Digitalmars-d-learn
On Tuesday, 21 July 2015 at 18:55:53 UTC, ddos wrote: On Tuesday, 21 July 2015 at 17:58:55 UTC, Gary Willoughby wrote: On Tuesday, 21 July 2015 at 17:23:30 UTC, ddos wrote: How do i sanitize a string for database query? Is there some builtin function? thx :) Use prepared statements instead.

Re: GLU in DerelictOrg

2015-07-21 Thread Alex Parrill via Digitalmars-d-learn
On Tuesday, 21 July 2015 at 14:51:47 UTC, John Colvin wrote: Isn't glu considered legacy these days? I think it's entirely OpenGL 2.x. For the maths stuff see http://code.dlang.org/packages/gl3n Yep. It still uses immediate mode, GL matrix functions, and all sorts of other stuff removed in Op

Re: Fixed Length Array Syntax in extern(C) Function Signatures

2015-07-09 Thread Alex Parrill via Digitalmars-d-learn
On Thursday, 9 July 2015 at 17:11:36 UTC, Per Nordlöw wrote: On Thursday, 9 July 2015 at 16:12:27 UTC, Timon Gehr wrote: No. You'll need explicit pass by reference on the D side. So, how should I modify my call to `image_copy` with respect to the four first parameters? In C, array parameter

Re: Coercing ranges to the same type

2015-07-06 Thread Alex Parrill via Digitalmars-d-learn
On Monday, 6 July 2015 at 19:46:51 UTC, Matt Kline wrote: Say I'm trying to expand an array of file and directory paths (such as ones given as command line args) into a range of file paths I can iterate over. A simplified example might be: auto getEntries(string[] paths, bool recursive) {

  1   2   >