Is this a bug?

2014-05-04 Thread Alex via Digitalmars-d-learn
Hello, I am trying to use the std.log module that is here: https://github.com/linkrope/log.d And I encountered a segmentation fault using dmd 2.065 on a Linux 64 platform. The reduced test case is this: // import

Re: Is this a bug?

2014-05-04 Thread Alex via Digitalmars-d-learn
On Sunday, 4 May 2014 at 10:28:30 UTC, Mike Parker wrote: On 5/4/2014 6:42 PM, Alex wrote: Hello, I am trying to use the std.log module that is here: https://github.com/linkrope/log.d And I encountered a segmentation fault using dmd 2.065 on a Linux 64 platform. The reduced test case is

Re: Yes or No Options

2015-07-30 Thread Alex via Digitalmars-d-learn
My father owns a small software company, specialized in market data products. www.bccgi.com (in case anyone is interested) So programming was basically around all my life. I do a small job in his company and my next task was to learn D. There are two trainees and the three of us have to

Re: Yes or No Options

2015-07-31 Thread Alex via Digitalmars-d-learn
On Thursday, 30 July 2015 at 15:14:28 UTC, Chris wrote: On Thursday, 30 July 2015 at 14:20:41 UTC, Alex wrote: My father owns a small software company, specialized in market data products. www.bccgi.com (in case anyone is interested) So programming was basically around all my life. I do a

Re: Yes or No Options

2015-07-28 Thread Alex via Digitalmars-d-learn
So I now combined a few of the options here and got this, which finally works: import std.stdio; import std.string; import std.random; void main() { while (true) { string yesno; int weiter; char[] uschi; write(Press ENTER to roll the dice!);

Yes or No Options

2015-07-27 Thread Alex via Digitalmars-d-learn
Hey guys! I am super new to programming and still trying to learn the very basics via a book that I bought. My problem is the following: import std.stdio; import std.string; void main() { char[] yesno; write(Roll the dice: Enter a number!); int dieNumber;

Re: Yes or No Options

2015-07-27 Thread Alex via Digitalmars-d-learn
On Monday, 27 July 2015 at 17:31:08 UTC, Ali Çehreli wrote: On 07/27/2015 08:50 AM, Alex wrote: a book that I bought The program looks a lot like one of the exercises in this chapter: http://ddili.org/ders/d.en/if.html You didn't actually pay for it, right? Because it is free. :) Ali

Re: Yes or No Options

2015-07-27 Thread Alex via Digitalmars-d-learn
Okay. By pure trying I found out what I did wrong: Apparently by typing Y I entered the shift key. Could that have been the problem? I changed it to a small y and it at least jumped back to the commandline instead of just being stuck. And by changing: writeln(Do you want to play again?

Re: Yes or No Options

2015-07-27 Thread Alex via Digitalmars-d-learn
Thank you! That helped me a lot. I'm sure that - in order to get to the point to repeat the whole first part of the program - I'll have to read further in the instructions I have BUT let's just say that I don't want it to repeat the first part of the program but just writeln something like

on structs by reference

2015-11-14 Thread Alex via Digitalmars-d-learn
Hi everybody, I have the following question about "by reference" behavior related to structs. I have a struct, say S, which contains a member of reference type struct S { int[] member; } and I have a main, for testing: void main() { S s; // = new S(); s.arr = [1,2,3];

Re: on structs by reference

2015-11-14 Thread Alex via Digitalmars-d-learn
On Saturday, 14 November 2015 at 11:48:42 UTC, Mike Parker wrote: So, I create a first var of type S, then the second and copied the first into the second. The behavior is like intended, the array inside the struct is copied. But this is a deep copy, as the third block shows. If I change the

Re: on structs by reference

2015-11-16 Thread Alex via Digitalmars-d-learn
On Monday, 16 November 2015 at 07:51:53 UTC, Ali Çehreli wrote: import std.stdio; /* This is the storage to the slices that objects will share. * * (Surprisingly, creating a slice dynamically is not possible due * to syntax issues: new int[N] means "allocates N ints and make * a slice

proper range usage

2015-11-03 Thread Alex via Digitalmars-d-learn
Hi everybody, first of all: this question is going to be unclear, because I'm lack of the "buzz word" I would like to ask about, sorry for this in advance. I try to describe the problem, where I stuck and hope somebody could think just a step further. Just a hint where to read about the

Re: proper range usage

2015-11-03 Thread Alex via Digitalmars-d-learn
On Tuesday, 3 November 2015 at 08:23:20 UTC, Ali Çehreli wrote: > "Programming in D" book (the revision of 2015-10-24) Oooh! That smells very fresh. :) :) > In my case, the container class can't become empty. Even if it contains > one single element, in this case the example should return

Re: proper range usage

2015-11-03 Thread Alex via Digitalmars-d-learn
... and yes, each P's M's are meant to be the same, as the associated M's in the B's class to the P. If you understand, what I mean ;)

Re: proper range usage

2015-11-03 Thread Alex via Digitalmars-d-learn
On Tuesday, 3 November 2015 at 22:36:21 UTC, Ali Çehreli wrote: That's fine. D's slices do that all the time: arr[0..3] and arr[3..$] seem to share index 3 but it is not the case: The first slice does not use it but the second one does. Ok... great! This is what I worried about... Aside: If

opCmp with structs

2015-11-06 Thread Alex via Digitalmars-d-learn
I'm sure I'm doing a silly mistake somewhere, but why this doesn't work? import std.stdio; import std.algorithm; struct ku { immutable int id; alias id this; this(int i) { id = i; } int opCmp(ref const ku rhs)

Re: opCmp with structs

2015-11-06 Thread Alex via Digitalmars-d-learn
Ok... the question is not silly any more... without 'immutable' it works. So, what am I missing?

Re: opCmp with structs

2015-11-07 Thread Alex via Digitalmars-d-learn
On Saturday, 7 November 2015 at 14:36:25 UTC, Mike Parker wrote: So my general question is: why immutable variables shouldn't be able to be moved (inside an array)? To be pedantic, sort isn't actually moving anything. It's reassigning elements, i.e. a[1] = a[2]. The immutable member makes

Re: opCmp with structs

2015-11-07 Thread Alex via Digitalmars-d-learn
On Saturday, 7 November 2015 at 00:19:56 UTC, Ali Çehreli wrote: Continuing from your hint: So, opCmp works but it is sort() that cannot move objects of ku around because of that immutable variable. So my general question is: why immutable variables shouldn't be able to be moved (inside an

Re: opCmp with structs

2015-11-07 Thread Alex via Digitalmars-d-learn
Ok, ok... I see the direction, but I still miss something: From the point of view of "Programming in D", chapter 33.3, "Immutability of the slice vs the elements": I don't want to have an immutable slice but immutable elements. And your answers imply that sorting not only modify the slice

Re: opCmp with structs

2015-11-07 Thread Alex via Digitalmars-d-learn
On Saturday, 7 November 2015 at 10:24:03 UTC, BBaz wrote: void main() { ku*[] tt = [new ku(2),new ku(1)]; sort(tt); } Don't really like this ;) not because writeln(tt); doesn't work any more, but because I have to think about where to use pointers and where not...

Re: opCmp with structs

2015-11-07 Thread Alex via Digitalmars-d-learn
Ok... found the solution. The technical at least. import std.algorithm; import std.range; void main(){ ku[] tt = [ku(2), ku(1)]; //writeln(tt); auto index3 = new size_t[tt.length]; makeIndex!("a.id < b.id")(tt, index3); auto ind = indexed(tt, index3);

Re: opCmp with structs

2015-11-07 Thread Alex via Digitalmars-d-learn
Found something useful, here: http://dlang.org/phobos/std_algorithm_sorting.html#makeIndex with that I can achieve the following void main(){ ku[] tt = [ku(2), ku(1)]; //writeln(tt); auto index3 = new size_t[tt.length]; makeIndex!("a.id < b.id")(tt, index3);

Combining Unique type with concurrency module

2015-09-13 Thread Alex via Digitalmars-d-learn
Hi everybody! I'm new to this forum so, please excuse me in advance for asking silly questions. I think I'm not the first person which wondering about this topic, but I'm trying to combine Unique type and concurrency module, getting the compiler error struct std.typecons.Unique!(S).Unique is

Re: Combining Unique type with concurrency module

2015-09-15 Thread Alex via Digitalmars-d-learn
On Monday, 14 September 2015 at 08:08:35 UTC, Ali Çehreli wrote: void main() { MultiThreadedUnique!S u1 = produce(); auto childTid2 = spawn(, thisTid); u1.giveTo(childTid2); send(childTid2, cast(shared(MultiThreadedUnique!S*))); import core.thread; thread_joinAll();

Re: Combining Unique type with concurrency module

2015-09-14 Thread Alex via Digitalmars-d-learn
On Monday, 14 September 2015 at 00:11:07 UTC, Ali Çehreli wrote: On 09/13/2015 09:09 AM, Alex wrote: > I'm new to this forum so, please excuse me in advance for > asking silly questions. Before somebody else says it: There are no silly questions. :) > struct std.typecons.Unique!(S).Unique is

Move Semantics

2015-09-29 Thread Alex via Digitalmars-d-learn
Another question on move semantics from the cheap seats... See my code here: http://dpaste.dzfl.pl/995c5af59dd6 There are indeed three questions, all marked in the code, so the rest of the text here is maybe redundant... but just in case and for summary: I try to model a inner class of some

Re: Move Semantics

2015-09-29 Thread Alex via Digitalmars-d-learn
Thank you very much for the comments. It is much clearer now. The .outer link is just a shortcut, which does not mean I don't have to reset it, where I have to. So... essentially, my expectation WAS to subjective and I have to separate better, what is the part of the model in my head and what

Maximum number of threads

2015-09-24 Thread Alex via Digitalmars-d-learn
This should be a not so long question to answer, I hope. I took an example from the "Programming in D" book, chapter "Message Passing Concurrency", around page 550. The question of interest was, how many threads I can have spawned at the same time. So I made an array of robot objects from the

Re: Maximum number of threads

2015-09-24 Thread Alex via Digitalmars-d-learn
On Thursday, 24 September 2015 at 12:38:41 UTC, Temtaime wrote: Offtop: i think if number of threads > number of real cores, than there's something wrong with your design. Maybe fibers suit better ? Well... you got my idea :) So it is not so far offtop, as you think ))) Fibers DO suit better

benchmark on binary trees

2015-12-04 Thread Alex via Digitalmars-d-learn
Hi everybody, this is going to be a learning by doing a benchmark test - post. Found this "game" on the web http://benchmarksgame.alioth.debian.org/u64q/performance.php?test=binarytrees and wanted to experiment on my self, I tried to reimplement some code in D. This:

Re: benchmark on binary trees

2015-12-06 Thread Alex via Digitalmars-d-learn
Ok, lets conclude this post for now. Did some comparison runs with the original C++ code. Missed this at the beginning. The results so far are as following: Here is the original code in C++. http://benchmarksgame.alioth.debian.org/u64q/program.php?test=binarytrees=gpp=6 With modifications to

Re: benchmark on binary trees

2015-12-07 Thread Alex via Digitalmars-d-learn
On Sunday, 6 December 2015 at 12:23:52 UTC, visitor wrote: Hello, interesting exercise for me to learn about allocators :-) Nice to know, a novice can inspire someone :) i managed to parallelize the code reaching similar performance, in terms of speed, as the non parallel version :

Re: benchmark on binary trees

2015-12-07 Thread Alex via Digitalmars-d-learn
On Sunday, 6 December 2015 at 08:45:10 UTC, Rikki Cattermole wrote: Why is TreeNode not final? This is an interesting hint! Just after adding final the program takes two seconds less... This is roughly 5%. Do you have another hints of this kind? ;) Also yours does not use threads in any

Re: benchmark on binary trees

2015-12-04 Thread Alex via Digitalmars-d-learn
On Friday, 4 December 2015 at 19:31:22 UTC, anonymous wrote: Why did you expect the C++ inspired version to be faster? Just because the original was written in C++? From a quick skim the two versions seem to be pretty much identical, aside from names and struct vs class. Names don't make a

Re: benchmark on binary trees

2015-12-04 Thread Alex via Digitalmars-d-learn
On Friday, 4 December 2015 at 23:23:37 UTC, anonymous wrote: Why the parallel version is slower then the sequential? If you set int n = 14 in the main function the parallel version is MUCH slower then the sequential. At my machine 7x slower. Shouldn't it be the other way round? I don't know

reduce a BitArray[]

2015-12-29 Thread Alex via Digitalmars-d-learn
Hi there, a silly question from me for the turn of the year... I apparently missing the forest through the trees. The first part of the code works as expected: [code] int[] arr8 = [1,2,3,4,5]; int sum = 0; foreach(int summand; arr8) { sum += summand; }

Program exited with code -11

2015-11-26 Thread Alex via Digitalmars-d-learn
Hello guys. I am beginner with D and a hobbyist in general when it comes to programming. I am following an SFML tutorial in C++ and trying to "translate it" to D (at least the parts I think I understand). I am using Derelict SFML2 bindgings to CSFML. First I tried to do it procedural way

Re: Program exited with code -11

2015-11-26 Thread Alex via Digitalmars-d-learn
On Thursday, 26 November 2015 at 08:15:02 UTC, Rikki Cattermole wrote: You forgot to load the pointers to the functions in the shared library :) https://github.com/DerelictOrg/DerelictSFML2 OMG. I am embarrassed. Thank you very much.

Re: non empty slices

2016-06-02 Thread Alex via Digitalmars-d-learn
On Thursday, 2 June 2016 at 20:11:21 UTC, Alex wrote: On Thursday, 2 June 2016 at 16:21:03 UTC, ag0aep6g wrote: void f(int[] arr) { A a = arrayToA(arr); foreach (T; A.AllowedTypes) { if (T* p = a.peek!T) f_impl(*p); } } You totally hit

Re: non empty slices

2016-06-02 Thread Alex via Digitalmars-d-learn
On Thursday, 2 June 2016 at 16:21:03 UTC, ag0aep6g wrote: On 06/02/2016 05:16 PM, Alex wrote: I may be getting what you're up to. Maybe not. So we start with something like this (using arrays instead of arbitrary ranges to keep things simple): import std.stdio: writeln; void main()

Re: iota access in foreach loop

2016-06-04 Thread Alex via Digitalmars-d-learn
PPS: The error shown is in line with the iota inside foreach: Error: cannot infer argument types, expected 1 argument, not 2

Re: iota access in foreach loop

2016-06-04 Thread Alex via Digitalmars-d-learn
On Saturday, 4 June 2016 at 18:58:51 UTC, Brad Anderson wrote: On Saturday, 4 June 2016 at 18:55:09 UTC, Brad Anderson wrote: On Saturday, 4 June 2016 at 18:20:26 UTC, Alex wrote: [...] Check out enumerate() in std.range; Ah! thanks! int counter = 5; foreach(i, el;

iota access in foreach loop

2016-06-04 Thread Alex via Digitalmars-d-learn
Hi all! Could you help me clearify why a iota can't be accessed with two arguments in a foreach loop? following tests show my problem: What does work: int[] ku = [0, 1, 2, 3, 4]; foreach(i, el; ku) writeln("index: ", i, " element: ", el); What does not work: counter = 5;

Re: non empty slices

2016-06-02 Thread Alex via Digitalmars-d-learn
On Thursday, 2 June 2016 at 22:17:32 UTC, ag0aep6g wrote: Yeah, can't do it that way. You have only one f_impl call, but want it to go to different overloads based on dynamic information (caseS). That doesn't work. You need three different f_impl calls. You can generate them, so there's

Re: non empty slices

2016-06-02 Thread Alex via Digitalmars-d-learn
On Thursday, 2 June 2016 at 23:35:53 UTC, ag0aep6g wrote: It's the Algebraic. The `get` method isn't @nogc. The documentation [1] says that it may throw an exception, which is most probably being allocated through the GC. So that's a reason why it can't be @nogc. The alternative `peek`

Re: non empty slices

2016-06-02 Thread Alex via Digitalmars-d-learn
On Thursday, 2 June 2016 at 23:44:49 UTC, ag0aep6g wrote: On 06/03/2016 01:35 AM, ag0aep6g wrote: The alternative `peek` method is not documented to throw an exception, but it's not @nogc either. No idea why. Maybe Algebraic does GC allocations internally. I wouldn't know for what, though. Or

non empty slices

2016-06-02 Thread Alex via Digitalmars-d-learn
Ok, a strange question from my side again... Let's begin, with what works: Say, I define two types: import std.typecons : Nullable; alias M = uint; alias Mr = Nullable!M; then, I can write two types of methods. Those which can handle Mr's: void fun1(Mr val) { //do some funny stuff } and

Re: non empty slices

2016-06-02 Thread Alex via Digitalmars-d-learn
On Thursday, 2 June 2016 at 14:31:15 UTC, ag0aep6g wrote: A little terminology: "Slice" is not a synonym for "range". iota does not return a slice, it returns a range. "Slice" is being used as a synonym for "dynamic array" (Type[]), and in the context of the slicing operator (expression[] or

Re: Filling an array

2016-03-12 Thread Alex via Digitalmars-d-learn
On Saturday, 12 March 2016 at 15:44:00 UTC, Mike Parker wrote: On Saturday, 12 March 2016 at 14:33:19 UTC, Alex wrote: //arr[] = 1; The question is, why the commented out line throws the error: Error: cannot implicitly convert expression (1) of type int to Nullable!uint[], while the

Filling an array

2016-03-12 Thread Alex via Digitalmars-d-learn
Hi all! I have, maybe, a silly question.. Not sure, if https://forum.dlang.org/post/ibxhuqamgclrcatsy...@forum.dlang.org has something to do with the topic Having the following code: import std.typecons; import std.algorithm; void main() { uint[] arr_ref; arr_ref.length = 5;

Re: Filling an array

2016-03-12 Thread Alex via Digitalmars-d-learn
On Saturday, 12 March 2016 at 16:37:25 UTC, user42 wrote: On Saturday, 12 March 2016 at 14:33:19 UTC, Alex wrote: /snip I thought this was supposed to halt with an error rather than compile and set all members to 1. The syntax, to me anyways, doesn't really communicate the intention of: set

Re: Filling an array

2016-03-12 Thread Alex via Digitalmars-d-learn
On Saturday, 12 March 2016 at 19:35:30 UTC, ag0aep6g wrote: On 12.03.2016 16:44, Mike Parker wrote: arr[] = cast(Nullable!uint)1; Nicer than a cast: construct a Nullable!int. arr[] = Nullable!uint(1); ok... so... this makes the error very strange, then... almost senseless...

casting to a voldemort type

2016-03-19 Thread Alex via Digitalmars-d-learn
Finally. A question about Voldemort types :) I have the following class, with an accompanying function. Skip the code to the link for a runnable version. /*--- code begin ---*/ class roof { int huhu = 9; void* funVoldemort(size_t my_size) { auto gg = huhu;

Re: iota result as member variable

2016-03-24 Thread Alex via Digitalmars-d-learn
On Thursday, 24 March 2016 at 08:13:27 UTC, Edwin van Leeuwen wrote: Yeah this is one of the downsides of voldermort types. In these cases typeof and ReturnType are your friend. It often takes me a couple of tries to get it right, but the following seems to work: import std.traits :

iota result as member variable

2016-03-24 Thread Alex via Digitalmars-d-learn
Hi everybody, doing some optimization on my code, I faced some strange question: how to save a iota result in a class member? Say I have class A { ??? member; auto testIter4() { return iota(0,5); } } void main() { A a = new A(); a.member = testIter4(); } how

Re: iota result as member variable

2016-03-24 Thread Alex via Digitalmars-d-learn
As a comment on my own post: I’m aware, that there are some different return types from functions like iota. And I’m also aware, that there are much less different range types. I can, maybe, define what kind of range type I want to have, the question is, how to map all the different function

Re: array of delegates

2016-04-14 Thread Alex via Digitalmars-d-learn
On Thursday, 14 April 2016 at 06:27:29 UTC, Ali Çehreli wrote: On 04/13/2016 04:39 PM, Alex wrote: > import std.algorithm; > indarr.map!(a => partial!(sg, a)); I think you want to generate a different delegate for each element where the first argument to sg is the value of that element (0,

Re: array of delegates

2016-04-14 Thread Alex via Digitalmars-d-learn
On Thursday, 14 April 2016 at 05:54:38 UTC, David Skluzacek wrote: So, that message is a pretty cryptic, but the problem there is that map does its thing at runtime, but partial is a template and must be instantiated at compile time. Instead you can use std.meta.staticMap, by doing something

Re: GC allocation

2016-04-22 Thread Alex via Digitalmars-d-learn
On Friday, 22 April 2016 at 01:55:36 UTC, Adam D. Ruppe wrote: On Thursday, 21 April 2016 at 22:59:58 UTC, Alex wrote: Ok... I make slices of them, carefully avoiding to make copies... Yeah, that shouldn't make a difference.. Wait, wait... I try to make slices of the array of delegates,

Re: GC allocation

2016-04-21 Thread Alex via Digitalmars-d-learn
On Thursday, 21 April 2016 at 15:44:56 UTC, QAston wrote: Closure (delegate type) objects have to allocate because they're reference types and have state. For stateful reference types to be safe they have to be put on the GC allocated heap. Ok. So, does this mean, that they just allocate on

Re: Compare lambda expressions

2016-04-27 Thread Alex via Digitalmars-d-learn
On Wednesday, 27 April 2016 at 06:59:22 UTC, cym13 wrote: On Tuesday, 26 April 2016 at 14:32:59 UTC, Alex wrote: IMHO, if you are to parse them from strings then you need a parser in order to build an abstract tree, a simpler intermediary language to restrict the possible patterns expressing

Compare lambda expressions

2016-04-26 Thread Alex via Digitalmars-d-learn
Hi all! Not sure, if this belongs directly to the D language, or it is rather maths, but: given to delegate generating functions and a main auto func1(int arg) { bool delegate(int x) dg; dg = (x) => arg * x; return dg; } auto func2(int arg) { bool delegate(int x) dg; dg =

Re: GC allocation

2016-04-21 Thread Alex via Digitalmars-d-learn
On Thursday, 21 April 2016 at 19:37:59 UTC, QAston wrote: On Thursday, 21 April 2016 at 17:27:09 UTC, Alex wrote: Ok. So, does this mean, that they just allocate on creation/binding them? If so, there is no problem and there are no questions any more. Just like classes - when closure

Re: GC allocation

2016-04-21 Thread Alex via Digitalmars-d-learn
On Thursday, 21 April 2016 at 19:54:10 UTC, via Digitalmars-d-learn wrote: I'm on mobile so I will be brief now and expand later On Thu, Apr 21, 2016 at 07:37:59PM +, QAston via Digitalmars-d-learn wrote: Just like classes - when closure expression is executed. Heap closures are

Re: Void pointers

2016-05-17 Thread Alex via Digitalmars-d-learn
On Tuesday, 17 May 2016 at 08:16:15 UTC, Rene Zwanenburg wrote: On Tuesday, 17 May 2016 at 06:55:35 UTC, Alex wrote: with dmd test44.d -release the results are: You may want to pass '-O -inline' as well. -O enables general optimizations, -inline enables function inlining. -release is for

Re: Void pointers

2016-05-17 Thread Alex via Digitalmars-d-learn
On Tuesday, 17 May 2016 at 08:45:44 UTC, Alex wrote: so... besides void*, ubyte*, a pointer to a strange, not constructible struct, I could take a iota too... a comment on my own: even every type of the above mentioned is possible, there are slightly differences between them: 1. As I don't

Re: Void pointers

2016-05-17 Thread Alex via Digitalmars-d-learn
On Tuesday, 17 May 2016 at 12:24:58 UTC, ag0aep6g wrote: On 05/17/2016 12:53 PM, Alex wrote: 2. If I want to be able to slice a iota, I have to initialize it with the last number. But the object, which stores the pointer does not need to know anything about this number. So, I rather would not

Re: Void pointers

2016-05-17 Thread Alex via Digitalmars-d-learn
On Tuesday, 17 May 2016 at 13:25:34 UTC, ag0aep6g wrote: On 05/17/2016 03:14 PM, Alex wrote: For a slice I surely need two numbers. But this should all be, what I need for a slice. For a iota, I need a maximum, which is not provided (at least at this moment) to the object containing the

Re: Void pointers

2016-05-17 Thread Alex via Digitalmars-d-learn
On Monday, 16 May 2016 at 22:54:31 UTC, ag0aep6g wrote: On 05/17/2016 12:43 AM, Alex wrote: The point is, that in my model the slice has a meaning itself. So, the language provides one of a needed constructs... Huh? As far as I understand, the pointer of the slice is invalid, and you never

Re: Void pointers

2016-05-17 Thread Alex via Digitalmars-d-learn
On Monday, 16 May 2016 at 23:01:44 UTC, ag0aep6g wrote: On 05/17/2016 12:53 AM, Alex wrote: Just as the reality (in my head) is: you can count something without having written the natural numbers before you start to count... iota does that, too. A iota struct doesn't store all the numbers

Re: Void pointers

2016-05-17 Thread Alex via Digitalmars-d-learn
On Tuesday, 17 May 2016 at 17:25:48 UTC, ag0aep6g wrote: On 05/17/2016 05:33 PM, Alex wrote: But, if the slicing is made by means of iota, there is no (at least no explicit) dependence between the slices, which could be made by different objects. How is this dependency expressed with slices?

Re: Void pointers

2016-05-17 Thread Alex via Digitalmars-d-learn
On Tuesday, 17 May 2016 at 18:25:46 UTC, ag0aep6g wrote: On 05/17/2016 07:43 PM, Alex wrote: The relation is: some object A contains the pointer/iota/(if at all) some object B makes slices of the thing, which is in A. Ok, so you have some object that stores a void pointer. The pointer is

Void pointers

2016-05-16 Thread Alex via Digitalmars-d-learn
Hi all! Let's talk about void pointers a little bit. Found this already http://forum.dlang.org/thread/codoixfeqstvqswir...@forum.dlang.org?page=1 but my question/problem differs from the above, so maybe, I have found a useful application for void pointers... Form of the posting: I have some

Re: Void pointers

2016-05-16 Thread Alex via Digitalmars-d-learn
On Monday, 16 May 2016 at 21:04:32 UTC, ag0aep6g wrote: Typo here. Should be `ptr[a .. b]`. Thanks void main() { void* ptr; // this will stay uninitialized during the whole program run The pointer is being initialized, though. To null, which is why your shenanigans below work

Re: Void pointers

2016-05-16 Thread Alex via Digitalmars-d-learn
On Monday, 16 May 2016 at 21:15:16 UTC, Steven Schveighoffer wrote: On 5/16/16 4:39 PM, Alex wrote: // something that does not worked as expected: // how to rewrite a for loop for(auto i = 0; i < b.length; i++) writeln([i]); // into a foreach loop? What you need is a

Re: Void pointers

2016-05-16 Thread Alex via Digitalmars-d-learn
Background: Say, I have objects of kind E, which operate on structs of kind M. The problem: if an action is done on a struct, say M42, there should be also some action done on other structs, which have some relation to M42, but neither the operating object, nor M42 is aware of them (and the

Re: Void pointers

2016-05-16 Thread Alex via Digitalmars-d-learn
On Monday, 16 May 2016 at 21:41:20 UTC, Steven Schveighoffer wrote: Hey, there's nothing wrong with for-loops. Just trying to answer the question :) You could also do something like: foreach(i; 0 .. b.length) writeln([i]); Ha! Yes! :) Thanks :) -Steve

Re: Void pointers

2016-05-16 Thread Alex via Digitalmars-d-learn
On Monday, 16 May 2016 at 22:28:04 UTC, ag0aep6g wrote: I can't say that I understand the setup you describe. But are you sure that iota has a higher cost than (ab)using a slice? I mean, they're pretty much exactly the same: an offset, a length, and an increment operation. If inlining

Re: Void pointers

2016-05-16 Thread Alex via Digitalmars-d-learn
On Monday, 16 May 2016 at 22:30:38 UTC, ag0aep6g wrote: On 05/16/2016 11:33 PM, Alex wrote: Well... not wanting to have a variable, which stores numbers, which are natural numbers, beginning with zero, used for counting only. But you have such a variable: b. I may still be missing the

GC allocation

2016-04-21 Thread Alex via Digitalmars-d-learn
Hi all! timing my program with valgrind/cachegrind and using -vgc option of the compiler found the message: "using closure causes GC allocation" The question is: does the usage of the closure causes the GC allocation on every usage of the closure or only on creation/assigning of it? If the

array of delegates

2016-04-13 Thread Alex via Digitalmars-d-learn
Hi at all! Having read this: http://forum.dlang.org/post/mailman.2415.1354291433.5162.digitalmars-d-le...@puremagic.com still have a problem... Lets begin with what works: enum Props{p1, p2} class AA { int[] arr1; int[] arr2; this() { //arbitrary values... arr1

Re: Indexing with an arbitrary type

2016-08-01 Thread Alex via Digitalmars-d-learn
On Monday, 1 August 2016 at 13:52:56 UTC, Jonathan M Davis wrote: An array does not implement RandomAccessFinite, which is an interface that you created. So, a function that takes a RandomAccessFinite is not going to accept an array. A dynamic array will match isRandomAccessRange, but that has

Re: Indexing with an arbitrary type

2016-08-01 Thread Alex via Digitalmars-d-learn
On Monday, 1 August 2016 at 15:06:54 UTC, Jonathan M Davis wrote: If you want a template constraint that checks that a type works with the index operator on a type, and you're not restricting it to something like size_t, then you're just going to have to check whether the expression is going

Re: Indexing with an arbitrary type

2016-08-01 Thread Alex via Digitalmars-d-learn
On Monday, 1 August 2016 at 15:51:58 UTC, Jonathan M Davis wrote: On Monday, August 01, 2016 15:25:59 Alex via Digitalmars-d-learn wrote: On Monday, 1 August 2016 at 15:06:54 UTC, Jonathan M Davis wrote: > If you want a template constraint that checks that a type > works with the

Re: Indexing with an arbitrary type

2016-08-03 Thread Alex via Digitalmars-d-learn
On Monday, 1 August 2016 at 16:09:50 UTC, Alex wrote: On Monday, 1 August 2016 at 15:51:58 UTC, Jonathan M Davis wrote: template isIndexable(I, T) { enum isIndexable = __traits(compiles, T.init[I.init]); } As a last question afterwards: Is it possible to create such an isIndexable

Re: Indexing with an arbitrary type

2016-08-03 Thread Alex via Digitalmars-d-learn
On Wednesday, 3 August 2016 at 14:23:59 UTC, Jonathan M Davis wrote: On Wednesday, August 03, 2016 09:21:13 Alex via Digitalmars-d-learn wrote: On Monday, 1 August 2016 at 16:09:50 UTC, Alex wrote: > On Monday, 1 August 2016 at 15:51:58 UTC, Jonathan M Davis > wrote: > template isIndex

Re: Indexing with an arbitrary type

2016-08-03 Thread Alex via Digitalmars-d-learn
On Wednesday, 3 August 2016 at 14:46:25 UTC, Alex wrote: On Wednesday, 3 August 2016 at 14:23:59 UTC, Jonathan M Davis wrote: But it should. Just found this: https://www.sgi.com/tech/stl/StrictWeakOrdering.html which should be fulfilled by a type, which can be used as a key. So, in my

Re: Indexing with an arbitrary type

2016-08-04 Thread Alex via Digitalmars-d-learn
What I think about is something like this: https://dpaste.dzfl.pl/d37cfb8e513d

Re: Indexing with an arbitrary type

2016-08-06 Thread Alex via Digitalmars-d-learn
On Friday, 5 August 2016 at 16:37:14 UTC, Jonathan M Davis wrote: On Thursday, August 04, 2016 08:13:59 Alex via Digitalmars-d-learn wrote: What I think about is something like this: https://dpaste.dzfl.pl/d37cfb8e513d Okay, you have enum bool isKey(T) = is(typeof(T.init < T.init) : b

SortedRange.lowerBound from FrontTransversal

2016-08-06 Thread Alex via Digitalmars-d-learn
Hi all... a technical question from my side... why the last line of the following gives the error? import std.stdio; import std.range; import std.algorithm; void main() { size_t[][] darr; darr.length = 2; darr[0] = [0, 1, 2, 3]; darr[1] = [4, 5, 6]; auto fT =

Re: Indexing with an arbitrary type

2016-08-03 Thread Alex via Digitalmars-d-learn
On Wednesday, 3 August 2016 at 17:56:54 UTC, Jonathan M Davis wrote: int is comparable, but it's not going to index float[string]. Only a string is going to do that. Similarly, long is comparable, but on a 32-bit system, it won't index int[], because it's larger than size_t, which is the

Syntax of isExpression

2017-01-31 Thread Alex via Digitalmars-d-learn
Hey guys, could you help me understand the syntax of the isExpression? I have an example, leaned on documentation https://dlang.org/spec/expression.html#IsExpression case 7. // Code starts here // import std.stdio, std.typecons; alias Tup = Tuple!(int, string, bool); enum myType {a, b, c}

Re: Syntax of isExpression

2017-01-31 Thread Alex via Digitalmars-d-learn
On Tuesday, 31 January 2017 at 11:40:06 UTC, Ali Çehreli wrote: On 01/31/2017 02:49 AM, Alex wrote: > auto r = E!(int, myType.a, true)(); > static if (is(T : TX!TL, alias TX, TL...)) > { > writeln(is(TL[0] == int)); > writeln(typeid(TL[1])); >

Re: "template with auto ref" experiment

2017-02-04 Thread Alex via Digitalmars-d-learn
On Saturday, 4 February 2017 at 16:53:13 UTC, Ali Çehreli wrote: If you haven't already, you may want to read a recent thread as well: http://forum.dlang.org/post/jsksamnatzkshldnn...@forum.dlang.org Thanks for the instructive link...

Re: "template with auto ref" experiment

2017-02-04 Thread Alex via Digitalmars-d-learn
On Saturday, 4 February 2017 at 16:18:00 UTC, kinke wrote: It most likely only works because the dangling pointer points into yet untouched stack. Trying to öet a normal by-value parameter or local variable escape this way should produce an error, but apparently it's not done for `auto ref`

"template with auto ref" experiment

2017-02-04 Thread Alex via Digitalmars-d-learn
Having read this https://dlang.org/spec/template.html#auto-ref-parameters I tried to do something like this // Code starts here void main() { initStruct iSb; iSb.var = 3; A b = A(iSb); assert(*b.myVar == 3); // this works iSb.var = 4;

Re: Judy Arrays

2016-08-26 Thread Alex via Digitalmars-d-learn
On Thursday, 25 August 2016 at 20:43:19 UTC, Illuminati wrote: On Thursday, 25 August 2016 at 20:42:42 UTC, Illuminati wrote: http://judy.sourceforge.net/downloads/10minutes.htm Would be nice to have such an implementation. Supposedly one of the best all around data structures in existence?

Re: copy a JSONValue

2016-08-26 Thread Alex via Digitalmars-d-learn
On Friday, 26 August 2016 at 07:46:13 UTC, Daniel Kozak wrote: Another way is to implement deepCopy by yourself (something like below) import std.json; import std.stdio; JSONValue deepCopy(ref JSONValue val) { JSONValue newVal; switch(val.type) { case JSON_TYPE.STRING:

  1   2   3   4   5   6   >