Re: Writing .di files

2012-06-22 Thread Minas Mina
I'm sorry, what I meant was "how to interface to C code". Sorry for writing it in a bad way. Do I just declare the C code as extern and then link together with the C .lib/.o/.so file? (I'm in Ubuntu) What about the stuff that is in header files?

Re: Strange exception using threads

2012-06-23 Thread Minas Mina
Thank you very much :) I like the "you are done :)" approach!

Removing from SList (std.container)...

2012-06-27 Thread Minas Mina
How can I do that? Why not list.remove(x); like in STL?

Re: Removing from SList (std.container)...

2012-06-27 Thread Minas Mina
On Wednesday, 27 June 2012 at 09:52:14 UTC, Tobias Pankrath wrote: On Wednesday, 27 June 2012 at 09:37:01 UTC, Minas Mina wrote: How can I do that? Why not list.remove(x); like in STL? std.container encodes the complexity of operations in the method names. There is no way to remove a range

Re: Removing from SList (std.container)...

2012-06-27 Thread Minas Mina
Thank you for your reply. Yes, std.container really sucks. Anyway, I made my program using C++ and STL

Re: Removing from SList (std.container)...

2012-06-27 Thread Minas Mina
Doesn't Andrei plan to do something about this module?

Concurrency in D

2012-06-27 Thread Minas Mina
I have been "playing" latetly with std.concurrency and core.thread. I like both, but they are entirely different approaches to concurrency. std.concurrency: Uses message passing. Does not allow passing of mutable types. core.thread: Essentially the same as the approach taken by Java. 1) Is o

Re: Concurrency in D

2012-06-27 Thread Minas Mina
You all helped, thank you :) I will read the concurrency part tomorrow!

Re: Concurrency in D

2012-06-28 Thread Minas Mina
On Wednesday, 27 June 2012 at 23:50:17 UTC, Ali Çehreli wrote: On 06/27/2012 04:05 PM, Adam Burton wrote: >> For example I would like to >> have a thread calculate the sum of the first half of an array >> while another thread would calculate the other half, and I could >> add the two results at

immutability and constness

2012-07-11 Thread Minas Mina
I'm fairly new to D, but I have been using C++ for a while now (about 5 years, selftaught). From what I have learned, const in C++ is inconsistent. For example: int main() { const int x = 0; // could be placed in ROM because it's known at compile time } void f(int x) { const int y = x

Re: immutability and constness

2012-07-12 Thread Minas Mina
On Thursday, 12 July 2012 at 14:42:17 UTC, Ali Çehreli wrote: On 07/12/2012 07:13 AM, Minas wrote: Thanks a lot! So what is the problem with (logical)const? Is it needed that much? And why some methods (toString(), toHash()) HAVE to be const? I mean, what's the problem if they aren't? Here is

Re: Immutable array initialization in shared static this

2012-07-13 Thread Minas Mina
I guess it's because you have an array of constants (immutables). The array is not immutable though. I could be wrong, I'm not an expert or D syntax :)

Creating a shared reference type

2012-07-13 Thread Minas Mina
I'm want to "play" a bit with thread syncronization... So this is a (big) part of my code. The other is the imports, the thread starting and the printing of x. shared int x; shared Semaphore sema; void main(string[] args) { auto t1 = new Thread(&f); auto t2 = new Thread(&g);

Re: Creating a shared reference type

2012-07-14 Thread Minas Mina
Thanks, I've got another problem: void f() { sema.wait(); ++x; sema.notify(); } sema is the global shared Semaphore (as above) main.d(29): Error: function core.sync.semaphore.Semaphore.wait () is not callable using argument types () shared main.d(29):

Re: Creating a shared reference type

2012-07-14 Thread Minas Mina
On Saturday, 14 July 2012 at 09:21:27 UTC, David Nadlinger wrote: On Saturday, 14 July 2012 at 09:15:55 UTC, Minas Mina wrote: Isn't this the way shared is used (or should be used)? Should be used: probably yes. But functions/methods which are able to act on shared data must be marke

Re: deimos libX11 undefined reference

2012-07-14 Thread Minas Mina
Try -L-lX11

profiling with -profile

2012-07-26 Thread Minas Mina
I have this code: import std.stdio; void main() { f(); g(); } void f() { writeln("f()"); } void g() { writeln("g()"); } I compile with the command: dmd test.d -profile Then I execute it. It prints: f() g() as expected. Shouldn't it print profiling informatio

Re: profiling with -profile

2012-07-26 Thread Minas Mina
Sorry, I just saw the generated file... :p

Implementing a Monitor

2012-07-27 Thread Minas Mina
I'm using condition variables to implement a monitor that simulates the producer-consumer(unbounded buffer) scenario. Note: monitor is __gshared and is initialized in main(). Then the other threads are created and run. There is one producer thread, and 5 consumer threads. void producer() {

Is "delete" really going away?

2012-07-29 Thread Minas Mina
I think having the delete keyword for classes was a very good thing, altough I don't know the problems it has for the GC and probably other things. Consider this scenario: class Base { // ... } class Derived : Base { // ... FILE *f; this()

Re: Is "delete" really going away?

2012-07-29 Thread Minas Mina
Thanks for the answers. So clear() or destroy() in 2.060 be used to call the destructor, but the actual memory of the object won't be freed, right? Is this is true, why wasn't "delete" changed to behave like destroy()?

How to define a constructor in a struct?

2012-08-05 Thread Minas Mina
I want to make a struct that defines a constructor: struct Point { this() { } } However I get a compiler error: "constructor main.Point.this default constructor for structs only allowed with @disable and no body" I wrote a @disable next to it but same error. I don't u

Re: How to define a constructor in a struct?

2012-08-05 Thread Minas Mina
Thank you. Is it the way it is to have compatibility with C structs?

Re: How to define a constructor in a struct?

2012-08-05 Thread Minas Mina
On Sunday, 5 August 2012 at 16:42:16 UTC, Adam D. Ruppe wrote: On Sunday, 5 August 2012 at 16:30:48 UTC, Minas Mina wrote: Thank you. Is it the way it is to have compatibility with C structs? I'm not sure... I think so in part, but I think another part of it is to make sure that s

Function that calculates in compile time when it can

2012-08-06 Thread Minas Mina
I want to write a fibonacci(n) function that calculates the result. a) if n is known at compile time, use a template b) if not, use a normal function I know how to write a template version: template fib(ulong n) { static if( n < 2 ) const fib = n; else

Re: Error while trying to allocate memory (malloc)

2012-08-06 Thread Minas Mina
Maybe you need a cast before malloc to convert it to a "s_blockInfo*"?

Re: Function that calculates in compile time when it can

2012-08-06 Thread Minas Mina
Something like this: template fib(ulong n) { static if( n < 2 ) const fib = n; else const fib = fib!(n-1) + fib!(n-2); if( n < 2) return n; return fib(n-1) + fib(n-2); } It doesn't work of course, as I am in

Re: Function that calculates in compile time when it can

2012-08-06 Thread Minas Mina
On Monday, 6 August 2012 at 14:25:29 UTC, Eyyub wrote: On Monday, 6 August 2012 at 13:46:14 UTC, Tobias Pankrath wrote: You can check for compile time with static if(__ctfe) No, you can't. __ctfe is a "CTFE-ed"(?) value. But you can do something like that : http://dpaste.dzfl.pl/e3f26239

Re: Function that calculates in compile time when it can

2012-08-06 Thread Minas Mina
On Monday, 6 August 2012 at 15:21:38 UTC, Philippe Sigaud wrote: On Mon, Aug 6, 2012 at 3:54 PM, Minas Mina wrote: Something like this: template fib(ulong n) { static if( n < 2 ) const fib = n; else const fib = fib!(n-1) + fib!(

Re: Function that calculates in compile time when it can

2012-08-06 Thread Minas Mina
On Monday, 6 August 2012 at 15:21:38 UTC, Philippe Sigaud wrote: On Mon, Aug 6, 2012 at 3:54 PM, Minas Mina wrote: Something like this: template fib(ulong n) { static if( n < 2 ) const fib = n; else const fib = fib!(n-1) + fib!(

Re: Function that calculates in compile time when it can

2012-08-06 Thread Minas Mina
On Monday, 6 August 2012 at 15:56:52 UTC, Namespace wrote: Take a look into std.math: https://github.com/D-Programming-Language/phobos/blob/master/std/math.d I found this: real sin(real x) @safe pure nothrow; /* intrinsic */ And these: creal sin(creal z) @safe pure nothrow { creal cs =

Re: Link .s file with dmd?

2012-08-13 Thread Minas Mina
On Monday, 13 August 2012 at 22:06:08 UTC, Namespace wrote: Can i link an assembler file .s with dmd like gcc with "gcc out.s any.c -o out.exe"? If so, how? .s, .c, .d files (source files), are not linked. What is linked, are object files (.obj or .o). GCC either compiles the .s file to an o

Re: stdlib.exit()

2012-08-19 Thread Minas Mina
That's what I do: import std.c.stdlib; void main(string[] args) { if( args.length == 1 ) { writeln("Some arguments, please!"); exit(-1); } }

Re: stdlib.exit()

2012-08-19 Thread Minas Mina
On Sunday, 19 August 2012 at 23:48:01 UTC, Minas Mina wrote: That's what I do: import std.c.stdlib; void main(string[] args) { if( args.length == 1 ) { writeln("Some arguments, please!"); exit(-1); } } Sorry, forgot to import std.stdio.

struct with @disable(d) default constructor doesn't work with arrays?

2012-08-22 Thread Minas Mina
I have this struct: struct S { int[] t; @disable this(); this(int sz) { t = new int[sz]; t[] = 1; } S opCall(int sz) { S s = S(sz); return s;

types of ranges

2012-08-24 Thread Minas Mina
Is there n article that explains the different types of Ranges? (InputRange, ForwardRange, etc) and their usage?

Re: Check for ctfe

2012-08-25 Thread Minas Mina
Why is it "if( __ctfe )" and not static if.. ?

Re: Static compiling with dmd

2012-12-12 Thread Minas Mina
On Wednesday, 12 December 2012 at 14:28:48 UTC, Zardoz wrote: How I can compile with static linking with dmd ? I try with dmd -L-static but i get this error : /usr/bin/ld: cannot find -lgcc_s I used before gdc with -static options and owrked well on it, but I need to use now dmd. Try usi

Re: Passing rvalues to functions expecting const ref

2012-12-23 Thread Minas Mina
On Sunday, 23 December 2012 at 12:08:47 UTC, Namespace wrote: As long as you use structs this should work, as you can see here: http://dpaste.dzfl.pl/03adf3d1 But if you use classes, it does not work anymore. So I like it a lot, that it works with structs. :) Thank you. I had forgotten to supp

Re: Passing rvalues to functions expecting const ref

2012-12-23 Thread Minas Mina
On Sunday, 23 December 2012 at 20:40:09 UTC, Namespace wrote: Minas Mina: Show me the whole code, I think that your opBinary functions returns rvalues. This would be a good and important case for "auto ref". But until now it is only for template paramters... struct Vector3 {

Re: structs are now lvalues - what is with "auto ref"?

2012-12-24 Thread Minas Mina
On Sunday, 23 December 2012 at 23:59:55 UTC, Jonathan M Davis wrote: On Monday, December 24, 2012 00:48:01 Namespace wrote: but Andrei is dead set against - Jonathan M Davis Why?

Re: structs are now lvalues - what is with "auto ref"?

2012-12-28 Thread Minas Mina
On Friday, 28 December 2012 at 12:47:03 UTC, Namespace wrote: On Friday, 28 December 2012 at 12:28:01 UTC, bearophile wrote: Namespace: How likely is it that "auto ref" will implemented in this release? Walter wants to release 2.061 "soon". So maybe that's for the successive (unstable?) ver

Re: structs are now lvalues - what is with "auto ref"?

2012-12-29 Thread Minas Mina
So when it will be fixed I will be able to write: void foo(auto ref Vector3 v); and it will pass copies or references depending on the situation?

Re: tiny std.datetime question

2013-01-16 Thread Minas Mina
On Wednesday, 16 January 2013 at 14:15:46 UTC, n00b wrote: Nevermind, found it myself. SysTime* sys = new SysTime(standardTime, UTC()); sys.hour; Le 16/01/2013 08:07, n00b a écrit : Hello, I'm kinda ashamed to ask that here, but std.datetime documentation is so complex... I only want to get h

Segfault in "_d_dynamic_cast ()"

2013-01-24 Thread Minas Mina
I am trying to create a BVH tree structure to speed up raytracing. So far it has been fine. I have created the BVH tree. It works for 202 triangles/spheres. However, when the scene has more spheres/triangles, I get a segmentation fault when the rays are traces, not when the tree is being buil

Re: Segfault in "_d_dynamic_cast ()"

2013-01-24 Thread Minas Mina
On Thursday, 24 January 2013 at 13:22:20 UTC, Maxim Fomin wrote: On Thursday, 24 January 2013 at 10:14:29 UTC, Minas Mina wrote: I am trying to create a BVH tree structure to speed up raytracing. So far it has been fine. I have created the BVH tree. It works for 202 triangles/spheres

Re: Segfault in "_d_dynamic_cast ()"

2013-01-25 Thread Minas Mina
I found what the root of all evil was - The GC. After disabling it, the program runs fine.

Re: Segfault in "_d_dynamic_cast ()"

2013-01-25 Thread Minas Mina
Maybe. I am re-writing the code in C++ to see, and also to compare the performance.

Re: Segfault in "_d_dynamic_cast ()"

2013-01-25 Thread Minas Mina
On Friday, 25 January 2013 at 16:19:15 UTC, Maxim Fomin wrote: On Friday, 25 January 2013 at 15:15:32 UTC, Minas Mina wrote: I found what the root of all evil was - The GC. After disabling it, the program runs fine. Perhaps you was working with C code, GC + legacy code sometimes lead to

Re: Question about auto ref

2013-03-26 Thread Minas Mina
Why is "const ref" not a good choice?

Re: Question about auto ref

2013-03-27 Thread Minas Mina
auto in? in ref?

operator +=

2013-04-08 Thread Minas Mina
How can I define operator += for a struct?

Re: operator +=

2013-04-08 Thread Minas Mina
On Monday, 8 April 2013 at 12:37:34 UTC, Simen Kjaeraas wrote: On 2013-04-08, 14:23, Minas Mina wrote: How can I define operator += for a struct? http://dlang.org/operatoroverloading.html In short: struct S { auto opOpAssign( string op : "+" )( S other ) { // Do

Re: Direlect3 with Mono-D

2013-04-21 Thread Minas Mina
On Saturday, 20 April 2013 at 15:49:47 UTC, Dementor561 wrote: I have all the needed files to use Direlect3, and I have Mono-D installed on Xamarin, I was wondering how I could put it all together in a project. 1) Do you use windows or linux? 2) Have you built derelict3? 3) If you are using li

Re: Direlect3 with Mono-D

2013-04-22 Thread Minas Mina
If you aren't comfortable with either C++ or D I would suggest to do the tutorials with C++, as there are no OpenGL tutorials for D. Don't try to learn two things at the same time.

Re: immutable string

2013-04-27 Thread Minas Mina
On Saturday, 27 April 2013 at 18:14:11 UTC, Michael wrote: According to http://dlang.org/const3.html The simplest immutable declarations use it as a storage class. It can be used to declare manifest constants. So, immutable string s = "..."; should be a manifest constant. If it is a constant

Re: Deallocate array?

2013-05-08 Thread Minas Mina
On Tuesday, 7 May 2013 at 23:09:29 UTC, Matic Kukovec wrote: Hi I'm running Windows Vista 64 with dmd 2.062. I have a simple program: import std.stdio, core.memory, std.cstream; void main() { string[] temp_array; for(int i=0;i<500;i++) { ++temp_arra

Re: and/or/not/xor operators

2013-05-31 Thread Minas Mina
On Thursday, 30 May 2013 at 16:48:33 UTC, bearophile wrote: Shriramana Sharma: Hello. I have always loved the readability of C++'s and/or/not/xor word-like logical operators but It doesn't seem to be available in D. and/or/not are less visually noisy, they look better than the ugly &&/||/!

Re: Most performant way of converting int to string

2015-12-23 Thread Minas Mina via Digitalmars-d-learn
On Wednesday, 23 December 2015 at 22:29:31 UTC, Andrew Chapman wrote: On Wednesday, 23 December 2015 at 11:46:37 UTC, Jakob Ovrum wrote: On Wednesday, 23 December 2015 at 11:21:32 UTC, Jakob Ovrum wrote: Dynamic memory allocation is expensive. If the string is short-lived, allocate it on the st

Re: Proper Use of Assert and Enforce

2016-02-05 Thread Minas Mina via Digitalmars-d-learn
On Wednesday, 14 March 2012 at 05:44:24 UTC, Chris Pons wrote: I'm new, and trying to incorporate assert and enforce into my program properly. My question revolves around, the fact that assert is only evaluated when using the debug switch. I read that assert throws a more serious exception th

Re: is increment on shared ulong atomic operation?

2016-02-07 Thread Minas Mina via Digitalmars-d-learn
On Sunday, 7 February 2016 at 19:43:23 UTC, rsw0x wrote: On Sunday, 7 February 2016 at 19:39:27 UTC, rsw0x wrote: On Sunday, 7 February 2016 at 19:27:19 UTC, Charles Hixson wrote: If I define a shared ulong variable, is increment an atomic operation? E.g. shared ulong t; ... t++; It seems

std.experimental.logger.Logger writeLogMsg is @safe?

2016-02-22 Thread Minas Mina via Digitalmars-d-learn
I'm trying to inherit from Logger, and I my custom logger to print to stdout using writeln(). But I can't because writeLogMsg is @safe, whereas writeln() is @system. Why is writeLogMsg @safe? This is too restrictive.

Re: std.experimental.logger.Logger writeLogMsg is @safe?

2016-02-22 Thread Minas Mina via Digitalmars-d-learn
On Monday, 22 February 2016 at 23:03:38 UTC, Jonathan M Davis wrote: On Monday, February 22, 2016 22:22:01 Minas Mina via Digitalmars-d-learn wrote: [...] Short answer: [...] Great, thanks.

Trouble installing DCD on Windows

2016-02-27 Thread Minas Mina via Digitalmars-d-learn
Hello. I'm trying to install DCD on windows 8.1 using DUB but I get an error. When executing "dub build --build=release --config=client" I get the following error: => Root package dcd contains reference to invalid package libdparse >=0.5.0 <0.6.0 <=

Re: efficient and safe way to iterate on associative array?

2016-03-04 Thread Minas Mina via Digitalmars-d-learn
On Friday, 4 March 2016 at 13:53:22 UTC, aki wrote: Is it okay to modify associative array while iterating it? import std.stdio; void main() { string[string] hash = [ "k1":"v1", "k2":"v2" ]; auto r = hash.byKeyValue(); while(!r.empty) { auto key = r.front

Application with WinMain does not start

2016-03-05 Thread Minas Mina via Digitalmars-d-learn
I added a WinMain function to my application because I don't want it to open a console when running on windows. But now it doesn't even start... extern (Windows) int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { bool b = true; while

Re: Application with WinMain does not start

2016-03-05 Thread Minas Mina via Digitalmars-d-learn
On Saturday, 5 March 2016 at 14:08:28 UTC, Mike Parker wrote: On Saturday, 5 March 2016 at 14:01:11 UTC, Mike Parker wrote: If you use WinMain, you do not need that flag. Actually, I need to amend that. It isn't needed with WinMain when using the Microsoft linker, but it is when using OPTLIN

Cannot compile program with DMD built from source

2016-03-09 Thread Minas Mina via Digitalmars-d-learn
Hello, I have followed the instructions here (http://wiki.dlang.org/Starting_as_a_Contributor#POSIX) to install DMD, druntime and phobos from source. My platform is Ubuntu 15.10 x64. This is the error I get: http://pastebin.com/kWCv0ymn

Re: Cannot compile program with DMD built from source

2016-03-09 Thread Minas Mina via Digitalmars-d-learn
On Wednesday, 9 March 2016 at 16:13:38 UTC, Minas Mina wrote: Hello, I have followed the instructions here (http://wiki.dlang.org/Starting_as_a_Contributor#POSIX) to install DMD, druntime and phobos from source. My platform is Ubuntu 15.10 x64. This is the error I get: http://pastebin.com

Re: Global const variables

2014-10-21 Thread Minas Mina via Digitalmars-d-learn
On Tuesday, 21 October 2014 at 08:02:52 UTC, bearophile wrote: Currently this code gets rejected: const int[] a = [1]; void main() pure { auto y = a[0]; } test2.d(3,14): Error: pure function 'D main' cannot access mutable static data 'a' test2.d(3,14): Error: pure function 'D main' cannot

How do I use dub?

2014-10-24 Thread Minas Mina via Digitalmars-d-learn
I intent to use D to make a small 2D game. I have downloaded eclipse, DDT plugin and dub. I also set the path to dub in eclipse. So I made a new project, tested a writeln and it worked. The next step was to add some dependencies for derelict. I need SFML for now (and DerelictUtils of course).

Re: How do I use dub?

2014-10-24 Thread Minas Mina via Digitalmars-d-learn
Oh and another thing: The program compiles right now but I can't execute it because for some reason: Failed to create a child process. Cannot run program "/home/minas/Projects/eclipse_workspace/DTest/dtest" (in directory "/home/minas/Projects/eclipse_workspace/DTest"): error=13, Permission den

Using executeShell in multiple thread causes access violation error

2015-07-13 Thread Minas Mina via Digitalmars-d-learn
I have written a script that visits all directories in the current directory and executes a command. In my case, "git pull". When running the script serially, everything is fine. All git repositories are pulled. But I'd like to pull multiple repositories in parallel to speed things up. So I

Re: Using executeShell in multiple thread causes access violation error

2015-07-17 Thread Minas Mina via Digitalmars-d-learn
bump