std.range.only with different range types

2015-11-08 Thread Freddy via Digitalmars-d-learn
--- import std.algorithm; import std.range; import std.stdio; void main(){ only(iota(0,4),[1,4,5]).writeln; } --- How can I call std.range.only with different range types?

generate with state

2015-11-02 Thread Freddy via Digitalmars-d-learn
Is there a version of http://dlang.org/phobos/std_range.html#.generate with state.

Re: generate with state

2015-11-02 Thread Freddy via Digitalmars-d-learn
On Tuesday, 3 November 2015 at 00:08:54 UTC, Ali Çehreli wrote: generate() already allows "callables", which can be a delegate: import std.stdio; import std.range; struct S { int i; int fun() { return i++; } } void main() { auto s = S(42); writefln("%(%s %)",

Unionize range types

2015-11-02 Thread Freddy via Digitalmars-d-learn
Is there any way I can Unionize range Types? --- auto primeFactors(T)(T t, T div = 2) { if (t % div == 0) { return t.only.chain(primeFactors(t / div, div)); } if (div > t) { return []; } else { return primeFactors(t, div + 1); } } ---

Re: good reasons not to use D?

2015-11-01 Thread Freddy via Digitalmars-d-learn
On Friday, 30 October 2015 at 10:35:03 UTC, Laeeth Isharc wrote: I'm writing a talk for codemesh on the use of D in finance. I want to start by addressing the good reasons not to use D. (We all know what the bad ones are). I don't want to get into a discussion here on them, but just wanted

Re: std.algorithm.startsWith only predicate

2015-10-18 Thread Freddy via Digitalmars-d-learn
On Sunday, 18 October 2015 at 17:58:30 UTC, Meta wrote: Is this a simplified use case of some actual code you have? Otherwise, you can just do: bool iden(string str) { auto f = str.front; return f.isAlpha || f == '_'; } It's simplified, i wanted to check for empty

std.algorithm.startsWith only predicate

2015-10-18 Thread Freddy via Digitalmars-d-learn
How do you call startsWith with only a predicate --- import std.algorithm; import std.ascii; bool iden(string str) { return str.startsWith!(a => a.isAlpha || a == '_'); } ---

Alias lamda argument vs Type template argument

2015-10-15 Thread Freddy via Digitalmars-d-learn
There are two these different ways to pass functions as template arguments. Which is preferred? --- void funcA(alias calle)() { calle(); } void funcB(T)(T calle) { calle(); } void main() { funcA!(() => 0); funcB(() => 0); } ---

How to use std.range.interfaces in pure @safe code

2015-10-02 Thread Freddy via Digitalmars-d-learn
How do I use http://dlang.org/phobos/std_range_interfaces.html in pure @safe code?

Range of variables

2015-09-30 Thread Freddy via Digitalmars-d-learn
Is there a way to make a range of a variables lazily? --- int var1; int var2; void func() { int var3; auto range = /*range of var1,var2,var3*/ ; } ---

address of overloaded function

2015-09-30 Thread Freddy via Digitalmars-d-learn
How do you take the address of a specific overloaded function. This won't compile --- import std.range; void main() { ForwardAssignable!int range; int delegate() @property get = void delegate(int) @property set = } ---

scope in function argument

2015-09-23 Thread Freddy via Digitalmars-d-learn
What does it mean when there is a scope in a function argument. --- void func(scope int* a){} ---

Reading dmd's source code

2015-08-19 Thread Freddy via Digitalmars-d-learn
dmd's source code is very big, are there tips for reading it(important files)?

pragma(mangle, on a template)

2015-08-16 Thread Freddy via Digitalmars-d-learn
I can't get pragma(mangle) to work on templates(or structs). import std.stdio; struct MyStruct(T...) { int var; void func() { writeln(var); } } pragma(mangle, MyAlias) alias MyAlias = MyStruct!(a, b, c /+very long symbol bloating list+/ ); void main() { auto

Re: Pointers to Dynamic Arrays

2015-08-16 Thread Freddy via Digitalmars-d-learn
On Monday, 17 August 2015 at 02:45:22 UTC, Brandon Ragland wrote: if(file[(*pos + i)] == '}'){ *pos += i; return; } That code doesn't do what you want it do. file is a ((char[])*) you are indexing the pointer(accessing invalid memory) and getting a char[].

Re: pragma(mangle, on a template)

2015-08-16 Thread Freddy via Digitalmars-d-learn
On Monday, 17 August 2015 at 03:14:16 UTC, Adam D. Ruppe wrote: On Monday, 17 August 2015 at 02:46:02 UTC, Freddy wrote: Mangling is done at a different level in the compiler than aliases, so I don't think this is intended to work. Is there any way I can mangle a template struct then?

Indivisual Incremental Compalation with dub

2015-08-12 Thread Freddy via Digitalmars-d-learn
I have a file that takes a while to compile with a static interface. Is there any way i can make dub keep the object file of only that file(for faster compilation)?

ImplicitConversionTargets opposite

2015-05-21 Thread Freddy via Digitalmars-d-learn
std.traits has ImplicitConversionTargets. Is there any template that returns the types that can implicty convert to T?

Associative array on the heap

2015-05-18 Thread Freddy via Digitalmars-d-learn
How do you allocate an associative array on the heap? void main(){ alias A=int[string]; auto b=new A; } $ rdmd test test.d(4): Error: new can only create structs, dynamic arrays or class objects, not int[string]'s Failed: [dmd, -v, -o-, test.d, -I.]

Re: Associative array on the heap

2015-05-18 Thread Freddy via Digitalmars-d-learn
On Tuesday, 19 May 2015 at 00:00:30 UTC, Meta wrote: On Monday, 18 May 2015 at 23:55:40 UTC, Freddy wrote: How do you allocate an associative array on the heap? void main(){ alias A=int[string]; auto b=new A; } $ rdmd test test.d(4): Error: new can only create structs,

Re: Adding pointers to GC with destructers

2015-04-20 Thread Freddy via Digitalmars-d-learn
On Monday, 20 April 2015 at 02:56:35 UTC, Ali Çehreli wrote: Not automatically. Check out addRange and addRoot: http://dlang.org/phobos/core_memory.html Ali The destructor doesn't seem to be running import std.stdio; import std.c.stdlib; import core.memory; struct Test{

Re: Adding pointers to GC with destructers

2015-04-20 Thread Freddy via Digitalmars-d-learn
On Monday, 20 April 2015 at 22:24:53 UTC, Ali Çehreli wrote: On 04/20/2015 02:48 PM, Freddy wrote: On Monday, 20 April 2015 at 02:56:35 UTC, Ali Çehreli wrote: Not automatically. Check out addRange and addRoot: http://dlang.org/phobos/core_memory.html Ali The destructor doesn't seem to be

Adding pointers to GC with destructers

2015-04-19 Thread Freddy via Digitalmars-d-learn
C libraries have a pattern of HiddenType* getObj(); void freeObj(HiddenType*); Is there any way I can make the GC search for a HiddenType* and run freeObj when the pointer is not found.

final switch on Algebraic

2015-03-29 Thread Freddy via Digitalmars-d-learn
Is there any way to do a final switch statement in std.variant's Algebraic.

strings and array literal mutability

2015-02-24 Thread Freddy via Digitalmars-d-learn
Why are strings immutable but array literals are not?

Comparing function pointers

2015-02-11 Thread Freddy via Digitalmars-d-learn
import std.stdio; auto test1(){ void testFunc(){ } return testFunc; } auto test2(){ uint a; void testFunc(){ a=1; } return testFunc; } void main(){ writeln(test1()==test1());//true

Why does hello world not compile in safe?

2014-11-28 Thread Freddy via Digitalmars-d-learn
import std.stdio; @safe: void main() { writeln(Edit source/app.d to start your project.); } source/app.d(5): Error: safe function 'D main' cannot call system function 'std.stdio.writeln!(string).writeln'

How does this work?

2014-11-23 Thread Freddy via Digitalmars-d-learn
I know what this does, but can someone explain how it works? static if((typeof((inout int=0){ })));

Re: passing duck-typed objects and retaining full type information

2014-11-11 Thread Freddy via Digitalmars-d-learn
On Tuesday, 11 November 2014 at 19:23:39 UTC, Adam Taylor wrote: * i apologize in advance, this is my first post -- the code formatting probably wont turn out so great... I have a bunch of duck typed interfaces for containers similar to what you would find in std.range. i.e. template

Re: How the memory layout of global variable is reliable ?

2014-10-22 Thread Freddy via Digitalmars-d-learn
On Wednesday, 22 October 2014 at 20:29:58 UTC, Cjkp wrote: Hello, I have an idea about a small code tool related to the application resources. It would rely on the assumption that some global variabled, sharing the same type and attributes, declared in group, are contiguous. In short I need

How would you dive into a big codebase

2014-10-21 Thread Freddy via Digitalmars-d-learn
Is there any advice/tips for reading medium/big D codebases?

Re: building shared library from D code to import into cython

2014-10-07 Thread Freddy via Digitalmars-d-learn
On Tuesday, 7 October 2014 at 20:55:59 UTC, Laeeth Isharc wrote: Hi. I am trying to create a shared library in D linked against phobos so that I may use this in a cython extension module for Python. Ultimately I would like to be able to use a D class or struct (via the C++ interface) and

Re: Localizing a D application - best practices?

2014-09-29 Thread Freddy via Digitalmars-d-learn
On Sunday, 28 September 2014 at 21:29:21 UTC, Cliff wrote: Coming from the C# world, all of localization we did was based on defining string resource files (XML-formatted source files which were translated into C# classes with named-string accessors by the build process) that would get

Re: Dynamically loading a D dynamic library from a c++ program

2014-09-26 Thread Freddy via Digitalmars-d-learn
On Friday, 26 September 2014 at 16:43:30 UTC, Olivier Leduc wrote: Hello, I need to use a C++ SDK to create a plugin an existing closed source c++ application and I would like to know if its possible to use D for that task. Would is be possible to port the SDK header files and call the

Re: Dynamically loading a D dynamic library from a c++ program

2014-09-26 Thread Freddy via Digitalmars-d-learn
On Friday, 26 September 2014 at 16:43:30 UTC, Olivier Leduc wrote: Hello, I need to use a C++ SDK to create a plugin an existing closed source c++ application and I would like to know if its possible to use D for that task. Would is be possible to port the SDK header files and call the

Re: with (auto p = new ...)

2014-09-26 Thread Freddy via Digitalmars-d-learn
On Tuesday, 23 September 2014 at 15:19:59 UTC, Andre wrote: Hi, I just wonder why with (auto p = new ...) is not working. It would be some syntax sugar in this scenario: with (auto p = new Panel()) { parent = this; text = bla;

Re: with (auto p = new ...)

2014-09-26 Thread Freddy via Digitalmars-d-learn
On Friday, 26 September 2014 at 19:59:56 UTC, Freddy wrote: On Tuesday, 23 September 2014 at 15:19:59 UTC, Andre wrote: Hi, I just wonder why with (auto p = new ...) is not working. It would be some syntax sugar in this scenario: with (auto p = new Panel()) {

liblzma bindings in dub

2014-09-17 Thread Freddy via Digitalmars-d-learn
How do you include liblzma bindings(https://github.com/D-Programming-Deimos/liblzma) in a dub project?

Mutable array with fixed length

2014-09-04 Thread Freddy via Digitalmars-d-learn
How would you create a mutable array with a fixed(compile error when trying to change) length.

Re: Identifying 32 vs 64 bit OS?

2014-08-11 Thread Freddy via Digitalmars-d-learn
On Monday, 11 August 2014 at 05:19:01 UTC, Jeremy DeHaan wrote: I am looking at these versions as described here: http://dlang.org/version.html There are X86 and X86_64 version identifiers, but these specifically mention that they are versions for the processor type. Can they also be used to

opApply outside of struct/class scope

2014-08-10 Thread Freddy via Digitalmars-d-learn
I'm trying to implement a opApply outside of struct scope struct A{ int[] arr; } int opApply(ref A a,int delegate(ref int) dg){ return 0; } void main(){ A a; foreach(i;a){//i just want it to compile } } when i try compiling, the

Re: Can't build phobos

2014-08-04 Thread Freddy via Digitalmars-d-learn
On Monday, 4 August 2014 at 10:30:40 UTC, Marc Schütz wrote: On Sunday, 3 August 2014 at 23:41:27 UTC, Freddy wrote: I am currently working on a phobos fork to include associative ranges, however the unittest fail when i try to build. How am a supposed test any unittests that i add.

Can't build phobos

2014-08-03 Thread Freddy via Digitalmars-d-learn
I am currently working on a phobos fork to include associative ranges, however the unittest fail when i try to build. How am a supposed test any unittests that i add. link:https://github.com/Superstar64/phobos/tree/associative_ranges $ ../dmd/src/dmd |head -1 DMD32 D Compiler

Is there a way to map associative arrays

2014-08-01 Thread Freddy via Digitalmars-d-learn
#!/usr/bin/rdmd import std.algorithm; import std.stdio; uint[uint] test; void main(){ test=[0:2 ,1:3 ,2:4]; writeln(test.map!(a=a-2)); } $ ./test.d ./test.d(8): Error: template std.algorithm.map cannot deduce function from argument types !((a) = a - 2)(uint[uint]), candidates

Re: Is there a way to map associative arrays

2014-08-01 Thread Freddy via Digitalmars-d-learn
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