Re: Gtkd questions

2024-09-22 Thread Dejan Lekic via Digitalmars-d-learn

On Sunday, 22 September 2024 at 15:44:17 UTC, Ian wrote:
Ron Tarrant for gtkcoding.com by the way!) Is there a place 
where I can ask specific Gtkd questions? I came across some


For many years this has been the main place to ask GtkD-related 
questions: https://forum.gtkd.org/groups/GtkD/


Re: What's the latest GDC stable release version?

2024-06-17 Thread Dejan Lekic via Digitalmars-d-learn

On Sunday, 16 June 2024 at 16:26:08 UTC, mw wrote:

Hi,

What's the latest GDC stable release version?


Stable release version is the same as stable GCC release version. 
Find it here: https://gcc.gnu.org/


(GDC is part of the GCC project for years)


Re: Feedback request from production of the usage of DWT

2024-06-13 Thread Dejan Lekic via Digitalmars-d-learn
On Thursday, 13 June 2024 at 06:59:49 UTC, Menjanahary R. R. 
wrote:

 How important is its adoption?

Is GUI App in D frequent?


There are quite few D GUI projects we are aware of, Tilix being 
one of the popular ones. I have few personal projects that are 
based, like Tilix, on GtkD (https://gtkd.org). I never tried DWT.


Re: How to use eventcore write an echo server?

2024-03-14 Thread Dejan Lekic via Digitalmars-d-learn

On Tuesday, 12 March 2024 at 05:13:26 UTC, zoujiaqing wrote:

How to fix it? than you ;)


Try the following:

```
class Connection
{
StreamSocketFD client;

ubyte[1024] buf = void;

// Add these two lines before the constructor:
nothrow:
@safe:

this(StreamSocketFD client)
```

Also you will need to either comment out calls to writeln() or 
surround them in try/catch as writeln() may throw so it can't 
really be called in nothrow code... For starters just comment all 
calls to writeln() out to make it compile, and then move from 
there.


Re: C to D: please help translate this weird macro

2023-09-20 Thread Dejan Lekic via Digitalmars-d-learn

On Wednesday, 20 September 2023 at 13:55:14 UTC, Ki Rill wrote:

On Wednesday, 20 September 2023 at 13:53:08 UTC, Ki Rill wrote:

Here is the macro:

```C
#define NK_CONTAINER_OF(ptr,type,member)\
(type*)((void*)((char*)(1 ? (ptr): &((type*)0)->member) - 
NK_OFFSETOF(type, member)))

```

I'm trying to translate the Nuklear GUI library to D 
[here](https://github.com/rillki/nuklear-d/tree/nuklear-d-translation).


Here is how `NK_OFFSETOF` is defined:
```c
#define NK_OFFSETOF(st,m) ((nk_ptr)&(((st*)0)->m))
```


NK_OFFSETOF is the same as D's struct `.offsetof` attribute.

NK_CONTAINER_OF should probably be translated to:

`cast(T*)((cast(void*)ptr - __traits(getMember, T, 
member).offsetof))`


PS. I did not invent this. My original idea was far worse than 
this. - It was suggested on IRC by a much cleverer D programmer 
than myself - Herringway@IRC


Re: C to D: please help translate this weird macro

2023-09-20 Thread Dejan Lekic via Digitalmars-d-learn

On Wednesday, 20 September 2023 at 13:55:14 UTC, Ki Rill wrote:

On Wednesday, 20 September 2023 at 13:53:08 UTC, Ki Rill wrote:

Here is the macro:

```C
#define NK_CONTAINER_OF(ptr,type,member)\
(type*)((void*)((char*)(1 ? (ptr): &((type*)0)->member) - 
NK_OFFSETOF(type, member)))

```

I'm trying to translate the Nuklear GUI library to D 
[here](https://github.com/rillki/nuklear-d/tree/nuklear-d-translation).


Here is how `NK_OFFSETOF` is defined:
```c
#define NK_OFFSETOF(st,m) ((nk_ptr)&(((st*)0)->m))
```


Looks like you are not the only one who has issue with them:

https://github.com/Immediate-Mode-UI/Nuklear/issues/94

https://github.com/Immediate-Mode-UI/Nuklear/pull/309


Re: Writing a simple text editor in D using a C tutorial

2023-08-29 Thread Dejan Lekic via Digitalmars-d-learn

On Tuesday, 29 August 2023 at 16:17:56 UTC, Răzvan Birișan wrote:
Is there a better way to use `termios.h` inside D? Am I missing 
the point and there is a way to set these flags in D without 
using C libraries?


I would try to use termios from druntime instead.

Try: import core.sys.posix.termios;


Re: wanting to try a GUI toolkit: needing some advice on which one to choose

2021-05-27 Thread Dejan Lekic via Digitalmars-d-learn

On Thursday, 27 May 2021 at 01:17:44 UTC, someone wrote:

Yes, I know this is a question lacking a straightforward answer.

Requirements:

[...]


I humbly believe the most complete one is GtKD.

https://gtkdcoding.com/
https://gtkd.org

We all wish there was a STANDARD D GUI library out there, but 
that is a huge effort one or two individuals can't do by 
themselves (that is why all such efforts failed in the past)...


Re: dmd memory usage

2019-11-18 Thread Dejan Lekic via Digitalmars-d-learn
On Monday, 18 November 2019 at 00:20:12 UTC, Steven Schveighoffer 
wrote:
I'm fighting some out of memory problems using DMD and some 
super-template heavy code.


I have ideas on how to improve the situation, but it involves 
redesigning a large portion of the design. I want to do it 
incrementally, but I need to see things improving.


Is there a straightforward way to figure out how much memory 
the compiler uses during compilation? I though maybe 
/usr/bin/time, but I feel like I don't trust the output to be 
the true max resident size to be what I'm looking for (or that 
it's 100% accurate). Is there a sure-fire way to have DMD print 
it's footprint?


-Steve


You can wrap the whole thing in a shell script that takes PID of 
the compiler, and uses psrecord [1] Python tool to give you CPU 
and memory chart.


[1] https://pypi.org/project/psrecord/


Re: SendMessageTimeoutW requires casting string to uint?

2019-07-09 Thread Dejan Lekic via Digitalmars-d-learn

On Tuesday, 9 July 2019 at 10:34:54 UTC, BoQsc wrote:


All I know that there was toString16z function from tango 
project, that made it all work.




Now that I browsed the std.utf more, I realised what fits your 
need best is the https://dlang.org/phobos/std_utf.html#toUTF16z


Re: SendMessageTimeoutW requires casting string to uint?

2019-07-09 Thread Dejan Lekic via Digitalmars-d-learn

On Tuesday, 9 July 2019 at 10:34:54 UTC, BoQsc wrote:
I'm quite new to the programming, and I'm getting unsure how to 
make SendMessageTimeoutW to work with D lang.


Most of my attention right now resides around the Argument of 
the SendMessageTimeoutW function:

"Environment",


It seems that SendMessageTimeoutW  accepts only uint type, and 
string can't be directly used.


I think that I have to convert string characters to "C-style 0 
terminated string".

And everything should work? But I'm unsure how to do that.


All I know that there was toString16z function from tango 
project, that made it all work.




std.utf module has all encoding/decoding you need (in this case 
UTF-16). I guess You need to convert your string using toUTF16 ( 
https://dlang.org/phobos/std_utf.html#toUTF16 ). I do not do 
Windows programming so I am not 100% sure whether this will work 
or not. Give it a try.


Re: SendMessageTimeoutW requires casting string to uint?

2019-07-09 Thread Dejan Lekic via Digitalmars-d-learn

On Tuesday, 9 July 2019 at 11:06:54 UTC, Dejan Lekic wrote:


std.utf module has all encoding/decoding you need (in this case 
UTF-16). I guess You need to convert your string using toUTF16 
( https://dlang.org/phobos/std_utf.html#toUTF16 ). I do not do 
Windows programming so I am not 100% sure whether this will 
work or not. Give it a try.


Maybe even the straightforward to!wchar will work!?


Re: Singleton in Action?

2019-02-03 Thread Dejan Lekic via Digitalmars-d-learn

On Saturday, 2 February 2019 at 16:56:45 UTC, Ron Tarrant wrote:

Hi guys,

I ran into another snag this morning while trying to implement 
a singleton. I found all kinds of examples of singleton 
definitions, but nothing about how to put them into practice.


Can someone show me a code example for how one would actually 
use a singleton pattern in D? When I did the same thing in PHP, 
it took me forever to wrap my brain around it, so I'm hoping to 
get there a little faster this time.


I strongly suggest you find the thread started by Andrej Mitrovic 
many years ago. He compared several implementations of 
(thread-safe) singletons. I it an extremely helpful stuff, IMHO.


Re: Optional parameters?

2018-04-04 Thread Dejan Lekic via Digitalmars-d-learn
On Sunday, 1 April 2018 at 15:54:16 UTC, Steven Schveighoffer 
wrote:
I currently have a situation where I want to have a function 
that accepts a parameter optionally.


This is what function overloading and/or default values are for, 
right?




Re: ndslice summary please

2017-04-13 Thread Dejan Lekic via Digitalmars-d-learn

On Thursday, 13 April 2017 at 10:00:43 UTC, 9il wrote:

On Thursday, 13 April 2017 at 08:47:16 UTC, Ali Çehreli wrote:
I haven't played with ndslice nor followed its deprecation 
discussions. Could someone summarize it for us please. Also, 
is it still used outside Phobos or is Ilya or someone else 
rewriting it?


Ali


The reasons to use mir-algorithm instead of std.range, 
std.algorithm, std.functional (when applicable):


1. It allows easily construct one and multidimensional random 
access ranges. You may compare `bitwise` implementation in 
mir-algorithm and Phobos. Mir's version few times smaller and 
do not have Phobos bugs like non mutable `front`. See also 
`bitpack`.

2. Mir devs are very cary about BetterC
3. Slice is universal, full featured, and multidimensional 
random access range. All RARs can be expressed through generic 
Slice struct.

4. It is faster to compile and generates less templates bloat.
For example:

slice.map!fun1.map!fun2

is the same as

slice.map!(pipe!(fun1, fun2))

`map` and `pipe` are from mir-algorithm.


It is all good, but I am sure many D programmers, myself 
included, would appreciate if shortcomings of Phobos are fixed 
instead of having a completely separate package with set of 
features that overlap... I understand ndslice was at some point 
in the `experimental` package, but again - it would be good if 
you improve existing Phobos stuff instead of providing a separate 
library that provides better implementation(s).


Re: Using Dub

2017-01-16 Thread Dejan Lekic via Digitalmars-d-learn

On Monday, 16 January 2017 at 09:40:55 UTC, Russel Winder wrote:
On the one hand Cargo works wonderfully with Rust so I had 
hoped Dub would work wonderfully with D.  Sadly I am finding it 
doesn't. Possibly my fault, but still annoying.


Cargo does not have multiple Rust compilers as an option. Dub 
could look to find for compiler if it is not set, but that may 
disappoint users who have multiple compilers installed (myself 
included)...


Re: [Semi-OT] I don't want to leave this language!

2016-12-07 Thread Dejan Lekic via Digitalmars-d-learn

On Monday, 5 December 2016 at 20:25:00 UTC, Ilya Yaroshenko wrote:
Good D code should be nothrow, @nogc, and betterC. BetterC 
means that it must not require DRuntime to link and to start. I 
started Mir as scientific/numeric project, but it is going to 
be a replacement for Phobos to use D instead/with of C/C++.


Yes, perhaps it is so in your world...
In my world I have absolutely no need for this. In fact we are 
perfectly happy with Java runtime which is many times bigger than 
druntime!


Re: Build a SysTime from a string

2016-07-06 Thread Dejan Lekic via Digitalmars-d-learn

On Wednesday, 6 July 2016 at 14:15:22 UTC, Andrea Fontana wrote:
My problem is that from documentation I can't understand how to 
set +01:00 timezone on systime. I guess I'm missing something...


As far as I know, you can't do that.

Quote from the documentation:
"""
Unlike DateTime, the time zone is an integral part of SysTime 
(though for local time applications, time zones can

"""

It does make sense, right? SysTime is object representing your 
system's time, and naturally it already has timezone set to the 
right (system) value.


Re: What's the secret to static class members

2016-06-30 Thread Dejan Lekic via Digitalmars-d-learn

On Thursday, 30 June 2016 at 01:11:09 UTC, Mike Parker wrote:


I think it's safe to say this guy is just trolling and we can 
ignore him.


I was about to say the same, Mike. He is either trolling, or 
genuinely did not even bother to learn some language basics...


Re: improve concurrent queue

2016-06-03 Thread Dejan Lekic via Digitalmars-d-learn

On Tuesday, 27 August 2013 at 17:35:13 UTC, qznc wrote:


I can recommand this paper (paywalled though):
http://dl.acm.org/citation.cfm?id=248106



The research paper can actually be freely downloaded from 
http://www.dtic.mil/cgi-bin/GetTRDoc?AD=ADA309412 . Good article, 
thanks!


Re: print function

2016-02-04 Thread Dejan Lekic via Digitalmars-d-learn

On Thursday, 4 February 2016 at 00:23:07 UTC, ixid wrote:
It would be nice to have a simple writeln that adds spaces 
automatically like Python's 'print' in std.stdio, perhaps 
called print.


There are many implementations of string interpolation in D (that 
is what you want, basically). One of them is given in Phillipe's 
excellent book about templates: 
https://github.com/PhilippeSigaud/D-templates-tutorial/blob/master/D-templates-tutorial.md#simple-string-interpolation .


Re: Setting native OS thread name (eg, via prctl)

2015-12-22 Thread Dejan Lekic via Digitalmars-d-learn

Arun, isn't that what the 'name' property is there for?


Re: __traits(allMembers) and aliases

2015-08-25 Thread Dejan Lekic via Digitalmars-d-learn
It is off-topic (sorry for that), but how you grab only those 
(say functions) in a module that are annotated with @ChoseMe ?? 
allMembers trait gives bunch of strings, and I could not find a 
way to use them with hasUDA template...


Re: New to D - playing with Thread and false Sharing

2015-08-20 Thread Dejan Lekic via Digitalmars-d-learn

Keep in mind that in D everything is thread-local by default! :)
For shared resources use __gshared or shared (although I do not 
know for sure whether shared works or not).


Re: How to use Fiber?

2015-02-25 Thread Dejan Lekic via Digitalmars-d-learn

On Tuesday, 24 February 2015 at 10:15:29 UTC, FrankLike wrote:

There is a int[] ,how to use the Fiber execute it ?
Such as :

import std.stdio;
import core.thread;


class DerivedFiber : Fiber
{
this()
{
super( &run );
}

private :
void run()
{
printf( "Derived fiber running.\n" );
faa();
}
}

int[] v;

 void ftread()
{
DerivedFiber work = new DerivedFiber();
writeln( " will call " );
work.call();
writeln( " stop call " );
}
void faa()
{
writeln( " start " );
//Fiber.yield();
writeln( " start yield " );
foreach(c;v)
{
writeln( " current n is ",c );
}
}
void main()
{
int n=1;
while(n<=10_001)
{
v~=n;
n+=5000;
}
printf( "Execution returned to calling context.\n" );
  ftread();
}
-end

I dont's think it's a good work.
How about you?

Thank you.


On the "Articles" page on D Wiki ( http://wiki.dlang.org/Articles 
) you have this link: 
http://octarineparrot.com/article/view/getting-more-fiber-in-your-diet


It is probably the best article about using fibers in D that I 
have seen so far.


Re: Beginner ?. Why does D suggest to learn java

2014-10-22 Thread Dejan Lekic via Digitalmars-d-learn

On Thursday, 16 October 2014 at 22:26:51 UTC, RBfromME wrote:
I'm a newbie to programming and have been looking into the D 
lang as a general purposing language to learn, yet the D 
overview indicates that java would be a better language to 
learn for your first programming language. Why?  Looks like D 
is easier than Java...


D is far more complex programming language than Java. I do D 
programming for over decade, and Java for ~9 years (before I was 
a C++ programmmer). Just take a look at number of types you have 
in D, storage classes, pointers, modules (that will soon come to 
Java too), etc... D generics are superior to Java. However, Java 
generics are superasy.


Java is designed to be an easy programming language, D is 
designed to be pragmatic. If people new to programming were about 
to start with D as the first language, I suggest them to start 
with an easy subset of it, and I humbly believe that subset will 
look very, very similar to Java.


PS. this is not Java advocacy here, I am just trying to be fair 
and realistic. I just love D but if I said D is as easy as Java, 
that would be a lie.


Re: Installing LDC on Windows

2014-09-09 Thread Dejan Lekic via Digitalmars-d-learn
On Saturday, 6 September 2014 at 11:13:20 UTC, Russel Winder via 
Digitalmars-d-learn wrote:
OK I installed LDC pre-built on MinGW for Windows on Windows 
and then

Installed MinGW for Windows but when I run ldc2 it tells me
libgcc_s_dw2-1.dll is missing.

Is this problem soluble by any means other than destruction of 
Windows?


My first guess is that you do not use 32bit MinGW.

Here is what I got inside MSYS2 (MSYS2 rocks btw!):

$ find . -name libgcc*
./mingw32/bin/libgcc_s_dw2-1.dll
./mingw64/bin/libgcc_s_seh-1.dll


Re: ini library in OSX

2014-09-09 Thread Dejan Lekic via Digitalmars-d-learn


Or this one: http://dpaste.dzfl.pl/1b29ef20#


Re: ini library in OSX

2014-09-09 Thread Dejan Lekic via Digitalmars-d-learn

On Monday, 8 September 2014 at 06:32:52 UTC, Joel wrote:

Is there any ini library that works in OSX?

I've tried the ones I found. I think they have the same issue.

Joels-MacBook-Pro:ChrisMill joelcnz$ dmd ini -unittest
ini.d(330): Error: cannot pass dynamic arrays to extern(C) 
vararg functions
ini.d(387): Error: undefined identifier 'replace', did you mean 
'template replace(E, R1, R2)(E[] subject, R1 from, R2 to) if 
(isDynamicArray!(E[]) && isForwardRange!R1 && isForwardRange!R2 
&& (hasLength!R2 || isSomeString!R2))'?
ini.d(495): Error: cannot pass dynamic arrays to extern(C) 
vararg functions
ini.d(571): Error: cannot pass dynamic arrays to extern(C) 
vararg functions
ini.d(571): Error: cannot pass dynamic arrays to extern(C) 
vararg functions

Joels-MacBook-Pro:ChrisMill joelcnz$


You have a pretty functional INI parser here: 
http://forum.dlang.org/thread/1329910543.20062.9.camel@jonathan


Re: Allowing Expressions such as (low < value < high)

2014-09-09 Thread Dejan Lekic via Digitalmars-d-learn

On Thursday, 4 September 2014 at 20:03:57 UTC, Nordlöw wrote:
Are there any programming languages that extend the behaviour 
of comparison operators to allow expressions such as


if (low < value < high)

?

This syntax is currently disallowed by DMD.

I'm aware of the risk of a programmer misinterpreting this as

if ((low < value) < high)


It is not just that... Imagine this (nothing prevents you from 
doing it):


   if (foo < bar < baz < trt < mrt < frt /* etc */) {}


Re: dmd with shared lib

2014-05-26 Thread Dejan Lekic via Digitalmars-d-learn
bioinfornatics wrote:

> Hi, after building and installing dmd i fail to use generated
> executable because they are an undefined symbol.
> 
> 
> $ /opt/dmd/bin/dmd -L-lcurl testDelegate.d
> 
> $ ./testDelegate
> ./testDelegate: symbol lookup error:
> /opt/dmd/lib/libphobos2.so.0.66: undefined symbol:
> curl_version_info
> 
> $ ldd ./testDelegate
> linux-vdso.so.1 =>  (0x7fff2d4e8000)
> libcurl.so.4 => /opt/dmd/lib/libcurl.so.4 (0x7f82fd06)
> libdl.so.2 => /lib64/libdl.so.2 (0x7f82fce58000)
> libphobos2.so.0.66 => /opt/dmd/lib/libphobos2.so.0.66
> (0x7f82fc81)
> libpthread.so.0 => /lib64/libpthread.so.0 (0x7f82fc5f)
> libm.so.6 => /lib64/libm.so.6 (0x7f82fc2e8000)
> librt.so.1 => /lib64/librt.so.1 (0x7f82fc0e)
> libc.so.6 => /lib64/libc.so.6 (0x7f82fbd2)
> /lib64/ld-linux-x86-64.so.2 (0x7f82fd288000)
> 
> given executable is link with libcurl provided by dmd
> 
> when i look into these curl lib they are any curl_version_info
> symbol
> 
> # readelf -Ws /opt/dmd/lib/libcurl.so.4 | grep curl_version_info
> 
> # readelf -Ws /opt/dmd/lib/libcurl_stub.so | grep
> curl_version_info
> 
> while this symbol exist on libcurl provided by my fedora
> 
> #  readelf -Ws /usr/lib64/libcurl.so.4| grep curl_version_info
>346: 00023f20   140 FUNCGLOBAL DEFAULT   11
> curl_version_info

You are probably using DMD provided @ dlang.org... That one has issues 
(curl) on Fedora. DMD built with my SPEC from 
https://www.gitorious.org/dejan-fedora/dejan-fedora does not have these 
problems as far as I know.

-- 
http://dejan.lekic.org


Re: Any chance to avoid monitor field in my class?

2014-05-14 Thread Dejan Lekic via Digitalmars-d-learn

On Tuesday, 13 May 2014 at 17:41:42 UTC, Yuriy wrote:

On Tuesday, 13 May 2014 at 17:09:01 UTC, Daniel Murphy wrote:

What exactly is the mangling problem with extern(C++) classes?

Can't use D arrays (and strings) as function argument types.
Can't use D array types as template arguments.

extern (C++) MyClass(T)
{

}

MyClass!string a; // Mangling error


that should not compile at all. Perhaps you thought extern(C++) 
interface MyClass(T) ?


Re: DFL is the best UIcontrols for D,compare it to dwt, tkd,dtk,dlangui,anchovy......

2014-05-14 Thread Dejan Lekic via Digitalmars-d-learn


Although DFL not use on Linux or Mac os X,it's easy to do for 
high level Software Engineer.


Well, go ahead and do it!



Re: A lot of people want to use D,but they only know MS SQL Server,what will help them to Learn D?

2014-04-14 Thread Dejan Lekic

On Monday, 14 April 2014 at 15:21:33 UTC, FrankLike wrote:

Hello,everyone:

A lot of people want to use D,but they only know MS SQL 
Server,what will help them to Learn D?


So lots of people want to use D,who can help them?
They want to connect MS SQL Server in D,then they will connect 
other DataBase,
because it's a good idea that nice thing come from the small 
and familiar things always.

Sql driver or ODBC driver, for win7 in D,
who can help them?

Thank you,everyone.


First thing a D programmer MUST do is

1) To port FreeTDS to D, or write a binding/wrapper for it 
(should not be too difficult).


or

2) Use ODBC directly, or maybe also write some wrapper around it.

or

3) Implement D connector to MS SQL server directly (I would 
advise against that, such project would probably be 10x bigger 
than the DMD project itself)


My advice - use ODBC, it is the fastest way you may connect to 
the SQL server, and you already have everything you need for 
that. :)


Regards


Re: D project structure

2014-03-28 Thread Dejan Lekic

On Wednesday, 26 March 2014 at 16:13:15 UTC, Russel Winder wrote:
Is it the case that the Dub recommended project structure is in 
fact the

canonical D project structure?

The Dub recommended structure doesn't mention test code as 
opposed to
application/library source code, is it the case that the 
assumption is
that all tests are in the modules using built-in unittest and 
that there

are never any external tests?

What about integration and system testing?

cf. The canonical jvm language project structure is

src/main/
src/test/
src/integtest/

Thanks.


I use precisely the same structure as my Maven projects. It does 
make sense to me, as some of the projects I worked on mix 
languages (D with C, C++ and/or Java).


Re: Template mixins - why only declarations

2014-03-06 Thread Dejan Lekic

Template mixins can't contain statements, only declarations, because they 
(template mixins) are a way to inject code into the context.

Therefore it makes sense to forbid statements, as they can't appear in ANY 
context.

-- 
http://dejan.lekic.org


Re: D alternative for C/C++ -Dfoo=42

2014-02-25 Thread Dejan Lekic


I don't like it. I would prefer a CTFE-able counter part to 
boost::program_options that generates thouse enums from a 
config file.


If you want a config file, you do not need -D args. You simply 
import() it. Right?


Re: D alternative for C/C++ -Dfoo=42

2014-02-25 Thread Dejan Lekic

On Tuesday, 25 February 2014 at 13:21:38 UTC, bearophile wrote:

Dejan Lekic:

And yes, if someone builds multiple modules, he/she would have 
to use fully-qualified name. Example: dmd foo.d bar.d 
-Dfoo.var1=5 -Dbar.var4=walter


If you are interested in such things I suggest you to take a 
look at how the Fortress language does them.


Bye,
bearophile


No, I am not interested, but thanks. I am interested how D does 
them, or better say how it may do them...


Re: D alternative for C/C++ -Dfoo=42

2014-02-25 Thread Dejan Lekic

On Tuesday, 25 February 2014 at 12:45:06 UTC, Cherry wrote:

Hello

I want to define an enum int, but I want to make it possible to 
set its value when I run dmd from the command line. Is it 
possible in D?


Regards
Cherry


D offers version blocks: http://dlang.org/version.html#version

It would be great if D compiler had a way to substitute enums 
with given values. (This is a nice candidate for a DIP)


Imagine you have a code like this:

module myproggy;
import std.stdio;
enum foo = 5;
enum bar = "walter";

int main() {
  writeln(bar);
  return foo;
}

... and you call compiler like:
  dmd myproggy.d -Dfoo=42 -Dbar=hello

smart, new D compiler would replace enums (iff they exist in the 
source code) with the given arguments, so when you run myproggy, 
you get "walter" as output, and the exit code is 42.


Re: D alternative for C/C++ -Dfoo=42

2014-02-25 Thread Dejan Lekic

On Tuesday, 25 February 2014 at 12:57:51 UTC, Dejan Lekic wrote:

On Tuesday, 25 February 2014 at 12:45:06 UTC, Cherry wrote:

Hello

I want to define an enum int, but I want to make it possible 
to set its value when I run dmd from the command line. Is it 
possible in D?


Regards
Cherry


D offers version blocks: http://dlang.org/version.html#version

It would be great if D compiler had a way to substitute enums 
with given values. (This is a nice candidate for a DIP)


Imagine you have a code like this:

module myproggy;
import std.stdio;
enum foo = 5;
enum bar = "walter";

int main() {
  writeln(bar);
  return foo;
}

... and you call compiler like:
  dmd myproggy.d -Dfoo=42 -Dbar=hello

smart, new D compiler would replace enums (iff they exist in 
the source code) with the given arguments, so when you run 
myproggy, you get "walter" as output, and the exit code is 42.


And yes, if someone builds multiple modules, he/she would have to 
use fully-qualified name. Example: dmd foo.d bar.d -Dfoo.var1=5 
-Dbar.var4=walter


Re: What does q{...} mean?

2014-02-24 Thread Dejan Lekic
Gary Willoughby wrote:

> I keep seeing this syntax used a bit and i'm stumped to what it
> means. What is it?
> 
> enum foo = q{
> // ???
> };

q{} string literals (so-called "token strings") are a nice D feature - D 
garantees that tokens in between brackets are valid D tokens. This makes 
them perfect for storing D source code. They are quite useful for string 
mixins for an example.

-- 
http://dejan.lekic.org


Re: Timer

2014-02-17 Thread Dejan Lekic

On Monday, 17 February 2014 at 11:08:16 UTC, Chris wrote:
The D way of implementing a timer? I need to (automatically) 
execute a function that performs a clean up, say every hour.


if (file.older than 1 hour) {
remove;
}


Here is a quick timer implementation that you can improve 
yourself:


import std.stdio;
import core.thread;

class ChrisTimer : Thread {
private void delegate() funcToRun;
private long timeToWait;
private bool done = false;
private int noSheep;
private Duration howLong;

// We could make any function a parameter to ChrisTimer if we 
had a

// constructor like:
// this(void delegate() dg, long ms) {

this(long ms) {
funcToRun = &doSomething;
timeToWait = ms;
howLong = dur!("msecs")(timeToWait);
funcToRun = &doSomething;
super(&run);
}

private void run() {
while (isRunning && !done) {
funcToRun();
sleep(howLong);
}
}

// Example function that is just going to count sheep (up to 
10).

public void doSomething() {
++noSheep;
writeln("Counted ", noSheep, " sheep.");
if (noSheep >= 10) {
done = true;
}
}

} // ChrisThread class

int main(string[] args) {
auto ct = new ChrisTimer(2000);
ct.start();

return 0;
}


Re: fibers/coroutines tutorial?

2014-01-24 Thread Dejan Lekic

On Friday, 24 January 2014 at 16:02:27 UTC, Hasan wrote:
Is there a quick tutorial/intro for what D offers as an 
equivalent or alternative to "goroutines"?


I've seen the concurrency link on the homepage .. and umm .. 
call me lazy but I don't feel like reading through all that 
just to see what D's alternative to goroutines looks like ..


Yes, and it is listed on http://wiki.dlang.org . Please go to 
articles/tutorials part of that web-site and enjoy really good 
reads.


Re: What's the D way of application version numbers?

2014-01-13 Thread Dejan Lekic

On Sunday, 12 January 2014 at 18:36:19 UTC, Russel Winder wrote:
With C++ and Python, it is idiomatic to put the application 
version
number in a separate file that can then be processed by the 
build
system. For C++ a config file is constructed defining a macro 
that is
then used in the rest of the course. For Python the file is 
read at
runtime to define a variable. The build system itself uses the 
version

number for creating deb, RPM, egg, wheel, etc. packages.

D has no macro processing so C++ idioms are not useful. D does 
create a
standalone executable and so the Python approach of reading the 
file at

initialization time seems inappropriate.

Is there a known D idiom for this?

Thanks.


I simply define version in my main module (module which contains 
the main() function). I am planning to submit a DIP about 
something that is related to this. - I think we really need a way 
to specify version of package, and maybe even version of a module 
(similar to how the new Java module system works - see project 
Jigsaw). D does not offer this. I humbly believe it should be 
part of the language as it could be used also for building 
versions of dynamic libraries.


Anyway, back to the topic.
Say my main() function is in the org.dlang.myapp module.
If I want to have information about version of the artifact, my 
myapp.d starts with the following two lines of D code:

module org.dlang.myapp;
version = 1_3_21_4; // major_minor_micro_qualifier

Naturally, build tool looks for the version line when I need it.


Re: Learning D as main systems programming language

2014-01-10 Thread Dejan Lekic

On Friday, 10 January 2014 at 00:05:35 UTC, Goran Petrevski wrote:
You might want to look into XOmB: 
https://github.com/xomboverlord/xomb


Isn't it written in D1? Not sure about that...


So what if it is written in D1? :) It should not be a big problem 
to "port" it to D2.
Second interesting project that is kinda related to the topic: 
https://bitbucket.org/timosi/minlibd .


More: http://wiki.dlang.org/Other_Dev_Tools


Re: std.xml

2014-01-10 Thread Dejan Lekic
On Friday, 10 January 2014 at 00:02:14 UTC, Ola Fosheim Grøstad 
wrote:
The std.xml documentation states "This module is considered 
out-dated and not up to Phobos' current standards."


Does this mean that there is some other module I should use for 
xml parsing? Maybe one that is not in the standard distribution 
yet because it is beta?


I'd like to convert a xml-based tool I have written in another 
language to D as an experiment, but I'd like to use libraries 
that are likely to stay up to date.


Bascally it entails:
- reading a xml file
- build a dom for it
- optimize it
- write it back to another xml file

What options do I have in terms of actively maintained 
libraries that are suitable for this kind of utility? Beta 
quality is ok.


Here is one of the alternatives: 
https://github.com/opticron/kxml/blob/master/source/kxml/xml.d


Re: Are modules analogous to namespaces in C# or packages in Java?

2014-01-02 Thread Dejan Lekic

On Wednesday, 1 January 2014 at 17:43:54 UTC, Afshin wrote:

Modules confuse me as a way to organize code.

If a module is composed of multiple classes, it seems that the 
module semantics in D encourages putting all those classes in 
one file.


Can someone explain how to organize a set of classes into a 
module (or namespace, or package) so that each class can have 
their own file?


Java is not (yet) truly modular programming language. Java 8 is 
supposed to include Jigsaw (module system for Java). More about 
it: http://openjdk.java.net/projects/jigsaw/


Packages in D are similar to packages in Java.
Concept of modules as I wrote above, does not yet exist in Java.


Re: My first D module - Critiques welcome.

2013-12-25 Thread Dejan Lekic
> You could also do some neat stuff with opDispatch.  Someone
> actually
> wrote an article about using it with roman numerals:
> http://idorobots.org/2012/03/04/romans-rubies-and-the-d/

The idea is actually brilliant. :)
I think I may use it in the future when I need to deal with roman numbers.

-- 
Dejan Lekic
dejan.lekic (a) gmail.com
http://dejan.lekic.org


Re: stdout - autoflushing

2013-12-06 Thread Dejan Lekic
Benji wrote:

> Hello,
> in order to have correctly displayed output (before reading
> something from stdin),
> I must call stdout.flush().
> Sometimes, it's really annoying, especially when it is necessarry
> to call it 10 times.
> 
> For example:
> write("Enter some string: ");
> stdout.flush();
> string a = readln();
> write("And again please: ");
> stdout.flush();
> string b = readln();
> ...
> 
> Is there any way to prevent this?

I doubt. Your IDE is buffering application's streams.

-- 
Dejan Lekic
dejan.lekic (a) gmail.com
http://dejan.lekic.org


Re: How to install dmd2 in centos 5.3 x64

2013-12-03 Thread Dejan Lekic

On Tuesday, 3 December 2013 at 10:43:06 UTC, Puming wrote:

Hi:

I followed the steps in http://dlang.org/dmd-linux.html, but 
when I build a simple hello world program with:


rdmd hello.d

I get the following error:

rdmd hello.d
/usr/bin/ld: cannot find -l:libphobos2.a

I have copied dmd2/linux/lib64/libphobos2.a to /usr/lib64, but 
ld still can't find it.


Now I really wish all our servers are using ubuntu server..

Could anybody shed some light on where the problem is? I don't 
have much experience in linux except using apt-get in ubuntu.


Thanks.

Puming.


What architecture that CentOS box is, and give us your 
/etc/dmd.conf please.


Re: Composing features at compile time

2013-11-24 Thread Dejan Lekic
Jacob Carlborg wrote:

> Does anyone know a good way of composing features at compile time? Say I
> have a struct or class that I want to support different features that
> are configurable at compile time. One way would be to just pass in a
> couple of boolean flags and use static-if, like this:
> 
> class Foo (bool logging, bool events)
> {
>  static if (logging)
>  Logger logger;
> 
>  this ()
>  {
>  static if (logging)
>  logger = new Logger;
>  }
> 
>  void action ()
>  {
>  static if (logging)
>  logger.info("performing action");
>  // perform action
>  }
> }
> 
> Using this approach I get the feeling that there will quickly become a
> big nest of static-ifs. Does anyone have any better ideas?
> 

Jakob, whenever I need something like you describe, I do more/less the same 
what 
is described on this Wikipedia page: 
http://en.wikipedia.org/wiki/Composition_over_inheritance . C# example is 
exactly how I do this (in Java and D).

-- 
Dejan Lekic
dejan.lekic (a) gmail.com
http://dejan.lekic.org


Re: undefined reference to `_D16TypeInfo_HAyayAa6__initZ'

2013-11-24 Thread Dejan Lekic
On Saturday, 23 November 2013 at 23:47:11 UTC, Adam D. Ruppe 
wrote:
On Saturday, 23 November 2013 at 23:30:09 UTC, Jeroen Bollen 
wrote:
I added the code to my GitHub repo; there don't seem to be any 
uncommon associative arrays:


Yea, it is the immutable string[string], I used the same 
pattern in my cgi.d and saw that too (sometimes, like I said, 
it is randomly there or not. it seems to be the outer immutable 
that triggers the problem.


BTW, my cgi.d has fastcgi support too
https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff/blob/master/cgi.d

compile with -version=fastcgi. It uses the C libfcgi in that 
mode. Feel free to copy any of my code you want if it is 
helpful to you.


Adam, does it support multiplexing? Looks like people do not care 
much about that FastCGI feature... :(


Re: T[] (array of generic type)

2013-11-19 Thread Dejan Lekic
On Mon, 18 Nov 2013 21:32:11 +0100, Philippe Sigaud wrote:

> On Mon, Nov 18, 2013 at 9:20 PM, seany  wrote:
>> I read that book, but dont find this constructtion, that is why the
>> question.
> 
> IIRC I talk a bit about function templates in my tutorial. JR gave the
> link (thanks!), another, more direct way is to directly download the
> pdf:
> 
> https://github.com/PhilippeSigaud/D-templates-tutorial/blob/master/D-
templates-tutorial.pdf
> 
> (click on `view raw` to download)
> Try p. 28 and following.
> 
> 
> And I really should take the time to write this thing again...

Philippe, i wonder whether you plan on generating ePUB file out of those 
TeX files? :)


Re: std.concurrency : sending immutable classes

2013-11-11 Thread Dejan Lekic
On Tue, 12 Nov 2013 00:37:30 +0100, Dicebot wrote:

> Minimized repro:
> 
> import std.variant;
> 
> class A {}
> 
> void main()
> {
>  Variant v = new immutable A();
>  auto x = v.get!(immutable A)();  // triggers assert
> }
> 
> One simple question - did this ever work? :) Because passing immutable
> aggregate messages is sometimes sold as one of "proper"
> usage scenario of std.concurrency and if it was never actually
> implemented, that is damn sad. I have started to investigate this
> scenario because of question on topic in #d @ freenode.

Looks like Variant works only with implicitly convertible types.

In this case this fails:
assert(isImplicitlyConvertible!(immutable(A), A));


Re: std.concurrency : sending immutable classes

2013-11-11 Thread Dejan Lekic

Could it be something changed in DMD recently, as in my case (DMD64 D 
Compiler v2.063.2, on Fedora GNU/Linux) it obviously picks Variant. Why 
it does not pick the immutable instance of A is beyond me. If we reverse 
the order of arguments in the receive(), we will get the "function with 
arguments (VariantN!(32LU)) occludes successive function" error...


Re: std.concurrency : sending immutable classes

2013-11-11 Thread Dejan Lekic

When I run this program, I get a runtime error which gives me a headache:
http://codepad.org/vKJl11cO


Re: Embed JavaScript into D

2013-11-04 Thread Dejan Lekic
On Mon, 04 Nov 2013 20:35:53 +0100, Jeroen Bollen wrote:

> Is there a way I can embed javascript into my D application? I basically
> want to create a modular application which allows adding and removing
> plugins by dragging and dropping them into a folder. I love the idea of
> them being editable on the fly.

Check out this presentation: http://dconf.org/2013/talks/
chevalier_boisvert.html

Source code: https://github.com/maximecb/Higgs

Also, there is the DMScript project at DSource: http://dsource.org/
projects/dmdscript-2/


Re: fedora libcurl-gnutls issue

2013-09-27 Thread Dejan Lekic

On Friday, 27 September 2013 at 16:41:42 UTC, Joshua Niehus wrote:

http://d.puremagic.com/issues/show_bug.cgi?id=10710

Does anyone know if there is there a workaround for this issue?
Unfortunately Im stuck with fedora and cant jump to another 
OS...


Thanks


Option 1: Rebuild curl RPM with GnuTLS enabled.

Option 2: Build Fedora DMD RPM on a Fedora box. Do not use the 
one from the web-site...


Re: Module to work with environment variables

2013-09-14 Thread Dejan Lekic
On Sat, 14 Sep 2013 19:23:31 +0200, FreeSlave wrote:

> As I remember there was module to work with environment variables in
> standard library. But now I can't find it. Was it removed or merged with
> some other module?
> 
> Another question: I see some of modules are "considered out-dated and
> not up to Phobos' current standards". Can I make attempt to rewrite them
> so new versions will be included in standard library? But what are
> "Phobos' current standards"? Are they described somewhere?

It took few seconds to go to http://dlang.org, library reference, type 
"env" in the search box, and press enter. One of the first links you get 
is:

http://dlang.org/phobos/std_process.html


Re: [OT] Job postings

2013-09-14 Thread Dejan Lekic
On Fri, 13 Sep 2013 15:20:47 +0200, Joseph Rushton Wakeling wrote:

> Hello all,
> 
> OT question -- is there an etiquette/standard accepted practice for
> posting news of job openings to the D community?  I wouldn't normally do
> this, but in this case it's on behalf of friends for whom I have a very
> great deal of respect and who I think would be very exciting to work
> for.
> 
> Sad to say they're not D-related positions (I keep lobbying them,
> though:-) but I imagine there are people in this community who would
> make an excellent fit for the company in question.
> 
> Anyway, let me know what the accepted form is (even if it's "Don't do
> it!").
> 
> Thanks & best wishes,
> 
>  -- Joe

There is a DDN - D Developer Network on LinkedIn . Link to it is listed 
on http://wiki.dlang.org.


Re: Communication between Java and D application

2013-09-14 Thread Dejan Lekic
On Fri, 13 Sep 2013 22:04:24 +0200, Anton Alexeev wrote:

> I have a method in a D program which I want to call from a Java program.
> What is the best way to do this?

What you need is Java JNI: http://en.wikipedia.org/wiki/
Java_Native_Interface . There are many examples how to do this in C or C+
+. It should not be any different in D.


Re: enum and tuples

2013-08-10 Thread Dejan Lekic

On Friday, 9 August 2013 at 21:24:30 UTC, Ali Çehreli wrote:

On 08/09/2013 12:41 PM, captaindet wrote:

> On 2013-08-09 11:36, Ali Çehreli wrote:
>> as I am in the process of revising and translating a Tuples
chapter.

> as a matter of fact, i am checking your website regularly,
eagerly
> awaiting the translations of the tuples chapter. and the
__traits and
> the template chapter too ;)

I am very happy to hear that. It also makes me sad because I 
have been very slow this summer. :-/ In fact, I was in the 
middle of translating the "More Templates" chapter that I 
realized I should move tuples before that one.


I further realized that TypeTuple deserves more information 
than a couple of paragraphs and a trivial use in a unittest. ;) 
And that's when I realized that TypeTuple is a very strange 
beast indeed.


Ali


I could not agree more. TypeTuple is IMHO one of the coolest 
features that is so  underrated! Btw, Ali, everybody loves your 
book anyway. I recommend the section about Ranges to everyone. :D 
Keep up with the good work!


Re: D is totally useless

2013-05-01 Thread Dejan Lekic
Temtaime wrote:

> I had investigate a little more in it.
> Thanks to Jack Applegame, we made a copy of gl/gl.h and
> opengl32.lib for DMD.
> 
> http://acomirei.ru/u/gl.d
> http://acomirei.ru/u/opengl32.lib
> 
> I hope it will be included in DMD, now it's first draft of our
> work.

Why on the Earth would you include opengl32 in the DMD package??

-- 
Dejan Lekic
dejan.lekic (a) gmail.com
http://dejan.lekic.org


Re: How to read fastly files ( I/O operation)

2013-02-04 Thread Dejan Lekic
FG wrote:

> On 2013-02-04 15:04, bioinfornatics wrote:
>> I am looking to parse efficiently huge file but i think D lacking for this
>> purpose. To parse 12 Go i need 11 minutes wheras fastxtoolkit (written in c++
>> ) need 2 min.
>>
>> My code is maybe not easy as is not easy to parse a fastq file and is more
>> harder when using memory mapped file.
> 
> Why are you using mmap? Don't you just go through the file sequentially?
> In that case it should be faster to read in chunks:
> 
>  foreach (ubyte[] buffer; file.byChunk(chunkSize)) { ... }

I would go even further, and organise the file so N Data objects fit one page, 
and read the file page by page. The page-size can easily be obtained from the 
system. IMHO that would beat this fastxtoolkit. :)

-- 
Dejan Lekic
dejan.lekic (a) gmail.com
http://dejan.lekic.org


Re: Is there a portable way to limit memory/cpu usage of a D application?

2012-11-29 Thread Dejan Lekic

On Thursday, 29 November 2012 at 04:44:34 UTC, Mike Young wrote:
On Wednesday, 9 November 2011 at 17:13:14 UTC, Dejan Lekic 
wrote:

Sure
nothing prevents me from using setrlimit() in my D app, but 
perhaps it is

something to think about a portable way of doing that.


I know I'm over a year late coming in on this conversation, but 
how would you use setrlimit() in your D app at all?  I can't 
seem to figure out what the correct library is to include in my 
program to be able to call set/getrlimit in any manner.  Thanks!


Well, if it is not in the posix module, then you simply use it by 
declaring "extern(C) int setrlimit(int resource, const void* 
rlim);" or something similar if you define the rlimit struct 
somewhere.
Remember, you can call C functions from your D code anytime, 
anywhere.


Re: Using MinGW DLL with DMD?

2012-08-09 Thread Dejan Lekic

On Thursday, 9 August 2012 at 13:48:14 UTC, Adam D. Ruppe wrote:
On Thursday, 9 August 2012 at 13:43:18 UTC, Jacob Carlborg 
wrote:

Is it possible to link a DLL compiled for MinGW with DMD?


Yeah, I've use dlls made in gcc with dmd. You need to run implib
over the dll to get a .lib and then it works pretty easily.

implib /s mydll.lib mydll.dll


implib can be found in the basic utilities package at digital
mars.

http://www.digitalmars.com/download/freecompiler.html


Yes, this works in most cases, but when it does not, then you 
have to use DEF files and modify/add symbols. It is not 
complicated, just time-consuming...


Re: Using MinGW DLL with DMD?

2012-08-09 Thread Dejan Lekic

On Thursday, 9 August 2012 at 13:43:18 UTC, Jacob Carlborg wrote:

Is it possible to link a DLL compiled for MinGW with DMD?


Yes, it is possible.

Long ago i have dealt with this almost on a daily basis (we used 
Borland C++ Builder on Windows in the former company I worked 
for).


The easiest method is to use DEF files to create the import 
library. If you do not have it, you can use some tool that will 
analyse the DLL, make the DEF file for you, and then you modify 
it to your needs, and then create the import library for your 
target toolchain.


This article explains everything you need to know: 
http://wyw.dcweb.cn/stdcall.htm


Regards


Re: foreach syntax

2012-06-29 Thread Dejan Lekic
On Fri, 29 Jun 2012 12:47:28 +0200, Namespace wrote:

> A friend of mine ask me why D's foreach isn't like C#
> 
> Means, why is it like int[] arr = [1, 2, 3];
> 
> foreach (int val; arr) {
> 
> and not foreach (int val in arr) {
> 
> which it is more intuitive.
> 
> I could give him no clever answer to, so maybe someone here knows the
> reasons.


Because
1) "in" is a D keyword
2) D has even shorter syntax: foreach(val; arr) {}


-- 
Dejan Lekic
  mailto:dejan.lekic(a)gmail.com
  http://dejan.lekic.org 


Re: Concurrency in D

2012-06-29 Thread Dejan Lekic
On Thu, 28 Jun 2012 00:34:50 +0200, Minas Mina wrote:

> 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 one favoured over the other? I guess std.concurrency would be,
> because it uses messages (and I recently read somewhere that
> immutability + message passing = good thing). Well, my problem about is,
> how can send mutable data to another thread? _Can_ I do it? If not, how
> am I supposed to share data between them? Not everything can be
> immutable right? 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 the end.
> 
> 2) What about core.thread? To do proper sync between threads in
> core.thread, semaphore, mutexes and stuff like that are needed. Are
> those "good practice" in D?
> 
> 3) I have also read a bit about syncronized classes and shared
> classes/structs, altough I didn't understand it too much (well I didn't
> try too much to be honest).
> 
> For all those appoaches, which is the preffered?
> For all those appoaches, which is the preffered for game programming?
> 
> Thank you.


Both std.concurrency and std.parallelism need core.thread in order to do 
what they do...


-- 
Dejan Lekic
  mailto:dejan.lekic(a)gmail.com
  http://dejan.lekic.org 


Re: Does D have high-performance sockets

2012-06-13 Thread Dejan Lekic

On Wednesday, 13 June 2012 at 15:53:15 UTC, Jarl André wrote:

On Wednesday, 13 June 2012 at 10:24:58 UTC, Dmitry Olshansky
wrote:

On 13.06.2012 1:29, D Day wrote:

Are there any implementations of this anywhere for D?

I really only care about the windows platform - and have 
considered
writing this myself with IOCP and std.socket, but I figure 
someone else

must have already done something similar?


Take a look at vibe.d. While it looks like framework it could 
be used as library just as easy.

http://vibed.org/


My solution might be too simple. I made a simple socket server
that is single threaded, based on std.socket. Its really neat as
a need to have socket server library but I wouldn't recommend
using it in high performance applications. It imitates actually
QuickServer in Java, and the code shows clearly that I come from
a Java background

https://github.com/jarlah/d2-simple-socket-server


There is also this nice project: https://github.com/meh/nucular



Re: Segmentation fault hell in D

2012-06-09 Thread Dejan Lekic
On Fri, 08 Jun 2012 19:57:47 -0700, Andrew Wiley wrote:

> On Fri, Jun 8, 2012 at 11:29 AM, Jonathan M Davis
> wrote:
> 
>> On Friday, June 08, 2012 19:30:57 Jarl André"
>> @puremagic.com wrote:
>> > Evry single time I encounter them I yawn. It means using the next
>> > frickin hour to comment away code, add more log statements and try to
>> > eleminate whats creating the hell of bugz, segmantation fault. Why
>> > can't the compiler tell me anything else than the fact that i have
>> > referenced data that does not exist? Thanks I knew that. Now, please
>> > tell me where the error occured Jeezes.
>>
>> Turn on core dumps and use gdb. It'll give a backtrace and allow you to
>> look
>> at the state of the program when the segfault occured. That's pretty
>> much the
>> standard way to figure out what happened when a segfault occurs.
>>
>>
> And use GDC because DMD's debug symbols on Linux are broken enough to
> crash GDB at times. GDC is generally flawless.  class="gmail_quote">On Fri, Jun 8, 2012 at 11:29 AM, Jonathan M Davis
> <mailto:jmdavisp...@gmx.com";
> target="_blank">jmdavisp...@gmx.com> wrote: class="gmail_quote" style="margin:0px 0px 0px
> 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-
width:1px;border-left-style:solid">
> 
> 
> On Friday, June 08, 2012 19:30:57 Jarl André" < href="mailto:jarl.an...@gmail.com";
> target="_blank">jarl.an...@gmail.com>@ href="http://puremagic.com"; target="_blank">puremagic.com wrote:
> > Evry single time I encounter them I yawn. It means using the
> next > frickin hour to comment away code, add more log statements
> and > try to eleminate whats creating the hell of bugz,
> segmantation > fault. Why can't the compiler tell me anything
> else than the fact > that i have referenced data that does not
> exist? Thanks I knew > that. Now, please tell me where the error
> occured Jeezes. 
> Turn on core dumps and use gdb. It'll give a backtrace
> and allow you to look at the state of the program when the segfault
> occured. That's pretty much the standard way to figure out what
> happened when a segfault occurs.  And
> use GDC because DMD's debug symbols on Linux are broken enough to
> crash GDB at times. GDC is generally flawless. 

Ah noes, HTML code again...



-- 
Dejan Lekic
  mailto:dejan.lekic(a)gmail.com
  http://dejan.lekic.org 


Re: Simplified socket creation and handling

2012-05-30 Thread Dejan Lekic

On Friday, 18 May 2012 at 06:35:59 UTC, Jarl André wrote:
I am a Java developer who is tired of java.nio and similar 
complex socket libraries.


In Java you got QuickServer, the ultimate protocol creation 
centered socket library. You don't have to write any channels 
and readers and what not. You just instantiate a server, 
configures the handlers (fill in classes that extends a handler 
interface) and there you go.


Shouldn't there exist a similar library in any programming 
language? Not doing so is assuming that developers always need 
control of the lower layers. Its not true. I care about 
protocol. Not sockets.


Is there any abstraction layers in phobos? Or is everything 
just as complex as before?


I use QuickServer myself, and was thinking about creating 
something like that in D for quite some time...


Re: Build / Package system

2012-05-30 Thread Dejan Lekic

On Wednesday, 30 May 2012 at 08:13:34 UTC, Sputnik wrote:

There is a build and/or package managment system for D2 that is
working?
I googled, and I only can find things like dsss or cmaked that
don't get updated from a long time ago.

I really need to manage to get a project to compile in Windows
and Linux. Actually the code not have any OS dependence, so the
real diferences in each OS are the linking to gtkd and how and
where install the project. Actually I'm using a makfile in Linux
that works well, but I can't use it in windows for thing like
pkg-config.


You can. I use pkg-config on Windows inside the MSYS environment.


Re: state of web programming

2012-05-25 Thread Dejan Lekic
bioinfornatics wrote:

> it is a list of project lo look if yo want create a web application in D
> - https://github.com/mrmonday/serenity
> -
> https://github.com/adamdruppe/misc-stuff-including-D-programming-language-
web-stuff
> - https://github.com/Aatch/dfcgi
> - https://github.com/rejectedsoftware/vibe.d
> 
> Add yours, tell which is better ...

http://vibed.org

-- 
http://dejan.lekic.org


Re: unsynchronized access to primitive variables

2012-05-20 Thread Dejan Lekic

On Saturday, 19 May 2012 at 08:16:39 UTC, luka8088 wrote:

Hello to all,

I would like to know if D guarantees that access to primitive 
variable is atomic ?


I was looking for any source of information that says anything 
about unsynchronized access to primitive variables. What I want 
to know is if it is possible (in any way and any OS / hardware) 
for the following code to output anything other then 1 or 2:


import std.stdio;
import core.thread;

void main () {
  int value = 1;
  (new Thread({ value = 2; })).start();
  writeln(value);
}

Thanks !


This proggy will always print "1" because writeln() prints the 
value from the main thread. Spawned thread will have own value. 
Remember TLS is the default storage.


Re: Malloc in D

2012-04-27 Thread Dejan Lekic

On Friday, 27 April 2012 at 09:05:12 UTC, Marcin wrote:

Hi!
I find code:
[code]
import c.stdlib;
import c.stdlib;
import std.outofmemory;

class Foo{
static void[] buffer;
static int bufindex;
static const int bufsize = 100;
static this(){
void *p;
p = malloc(bufsize);
if (!p)
throw new OutOfMemory;
gc.addRange(p, p + bufsize);
buffer = p[0 .. bufsize];
}
static ~this(){
if (buffer.length){
gc.removeRange(buffer);
free(buffer);
buffer = null;
}
}
new(uint sz){
void *p;
p = &buffer[bufindex];
bufindex += sz;
if (bufindex > buffer.length)
throw new OutOfMemory;
return p;
}
delete(void* p){
assert(0);
}
static int mark(){
return bufindex;
}

static void release(int i){
bufindex = i;
}
}
void test(){
int m = Foo.mark();
Foo f1 = new Foo; // allocate
Foo f2 = new Foo; // allocate
Foo.release(m); // deallocate f1 and f2
}
[/code]
When I try compile i have some error:[code]
vander@vander-VirtualBox:~/Pulpit/D$ gdc Memory.d -o Memory
Memory.d:1: Error: module stdlib is in file 'c/stdlib.d' which 
cannot be read
import path[0] = 
/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.4.5/../../../../../include/d/4.4.5/i686-linux-gnu
import path[1] = 
/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.4.5/../../../../../include/d/4.4.5

vander@vander-VirtualBox:~/Pulpit/D$[/code]
When i comment import c.stdlib;
I have error
[code]
vander@vander-VirtualBox:~/Pulpit/D$ gdc Memory.d -o Memory
Memory.d:11: Error: undefined identifier malloc
Memory.d:11: Error: function expected before (), not __error of 
type _error_

Memory.d:13: Error: identifier 'OutOfMemory' is not defined
Memory.d:13: Error: OutOfMemory is used as a type
Memory.d:13: Error: new can only create structs, dynamic arrays 
or class objects, not void's

Memory.d:13: Error: can only throw class objects, not type void*
Memory.d:14: Error: undefined identifier gc, did you mean 
static import gcc?

Error: no property 'addRange' for type 'TOK149'
Memory.d:14: Error: function expected before (), not __error of 
type TOK149
Memory.d:19: Error: undefined identifier gc, did you mean 
static import gcc?

Error: no property 'removeRange' for type 'TOK149'
Memory.d:19: Error: function expected before (), not __error of 
type TOK149
Memory.d:20: Error: undefined identifier free, did you mean 
function fread?
Memory.d:20: Error: function expected before (), not __error of 
type _error_

Memory.d:29: Error: identifier 'OutOfMemory' is not defined
Memory.d:29: Error: OutOfMemory is used as a type
Memory.d:29: Error: new can only create structs, dynamic arrays 
or class objects, not void's

Memory.d:29: Error: can only throw class objects, not type void*
vander@vander-VirtualBox:~/Pulpit/D$
[/code]
What's can be wrong?


You probably have a very old GDC...

1) GC is a Struct inside core.memory so you need a line:

  GC gc;

2) You need to throw OutOfMemoryError which is defined in 
core.exception.


3) You need const(void*) pointers for GC methods.

So I first recommend you install latest GDC, and then modify your 
code to be more up-to-date.


I hope this helps.

Regards :)


Re: Object Serialization?

2012-04-27 Thread Dejan Lekic
dcoder wrote:

> Hello.
> 
> I'm probably not looking hard enough, but Do we have any
> standard d-library for serializing an object/object tree into
> -for example- an xml file?
> 
> thanks.

You have following
- Orange
- Thrift implementation
- BSON (http://vibed.org)

Probably wrappers or bindings to (all) other serialisation libraries as 
well.

Regards


Re: Aquivalent References as in C++?

2012-04-17 Thread Dejan Lekic

On Tuesday, 17 April 2012 at 09:39:10 UTC, Namespace wrote:

On Tuesday, 17 April 2012 at 08:02:02 UTC, Namespace wrote:
Now i have something like this. It works and manipulates 
lvalues so that i can pass my objects by ref to except null.


But is this smart?

class Bar {
public:
int x;

static ref Bar opCall(int x) {
static Bar b;

b = new Bar(x);

return b;
}

this(int x) {
this.x = x;
}
}

class Foo {
private:
Bar _bar;

public:
int y;

this() { }

this(ref Bar b) {
//assert(b !is null);

writefln("B.x %d", b.x);
}
}

Bar b = new Bar(42);

new Foo(b); // works
new Foo(null); // compiler error
new Foo(Bar(23)); // works
new Foo(Bar(25)); // works



But if I write

Bar bn;
new Foo(bn);

it works also and doesn't throw a compiler error.
To avoid this, I have to write an assert(obj !is null); again.
This really sucks. If anybody else works with my Code and puts 
a null reference to any method he gets no compiler error and 
wonder why he gets a runtime error instead.

Thats very annoying...


For that, you have static if contitions, and indeed you can make 
it a compile-time error.


Re: "shared" status

2012-04-17 Thread Dejan Lekic
On Saturday, 14 April 2012 at 10:48:16 UTC, Luis Panadero 
Guardeño wrote:

What is the status of "shared" types ?

I try it with gdmd v4.6.3
And I not get any warring/error when I do anything over a 
shared variable

without using atomicOp. It's normal ?

shared ushort ram[ram_size];


ram[i] = cast(ushort) (bytes[0] | bytes[1] << 8);


Shared is crucial for concurrency/parallelism since the switch to 
the thread local storage as default storage.


Immutable values are IMPLICITLY SHARED while for your mutable 
data you have to explicitly use "shared" keyword.


This basically means that SHARED data are used everywhere in D 
applications nowadays.


Re: Templates in classes => what is wrong?

2012-04-17 Thread Dejan Lekic

On Tuesday, 17 April 2012 at 14:57:18 UTC, Xan wrote:

On Tuesday, 17 April 2012 at 01:31:43 UTC, Kenji Hara wrote:

On Monday, 16 April 2012 at 18:48:52 UTC, Xan wrote:

On Sunday, 15 April 2012 at 19:30:27 UTC, Ali Çehreli wrote:

On 04/15/2012 11:39 AM, Xan wrote:
> On Sunday, 15 April 2012 at 11:23:37 UTC, John Chapman 
> wrote:

>> On Sunday, 15 April 2012 at 11:16:43 UTC, Xan wrote:
>>>
>>> int main(string [] args)
>>> {
>>> auto alg = Algorisme!(int,int);
>>
>> Should be:
>> auto alg = new Algorisme!(int, int);
>>
>>> alg.nom = "Doblar";
>>> alg.versio = 1;
>>> alg.funcio = (int a) {return 2*a};
>>
>> Should be:
>> alg.funcio = (int a) { return 2 * a; };
>> or:
>> alg.funcio = a => 2 * a;
>>
>>> }
>
>
> It does not work:
>
> $ gdmd-4.6 algorisme.d
> algorisme.d:18: Error: variable algorisme.main.alg voids 
> have

no value
> algorisme.d:18: Error: expression class Algorisme is void 
> and

has no value
>
> with the code https://gist.github.com/2394274
>
> What fails now?
>
> Thanks,
> Xan.

Your code is still missing 'new':

auto alg = new Algorisme!(int, int);


With only this change, I receive this error:

$ gdmd-4.6 algorisme.d
algorisme.d:21: Error: cannot implicitly convert expression 
(__dgliteral1) of type int delegate(int a) pure nothrow to 
int function(int)




Unrelated recommendations:

- Return 0 from main() for successful exit, anything else by 
convention means some sort of error.


- Take advantage of constructors (and 'alias') to simplify 
syntax and risk of bugs:


import std.conv, std.stdio, std.stream, std.string;
import std.socket, std.socketstream;
import std.datetime;

class Algorisme(U,V) {
 string nom;
 uint versio;
 alias V function (U) Funcio;
 Funcio funcio;

 this(string nom, uint versio, Funcio funcio)
 {
 this.nom = nom;
 this.versio = versio;
 this.funcio = funcio;
 }
}

int main(string [] args)
{
 alias Algorisme!(int, int) MeuAlgorism;
 auto alg = new MeuAlgorism("Doblar", 1,
(int a) { return 2 * a; });

 return 0;
}

Ali


With all of your suggestion 
[https://gist.github.com/2394274], I get:


$ gdmd-4.6 algorisme.d
algorisme.d:30: Error: constructor 
algorisme.Algorisme!(int,int).Algorisme.this (string nom, 
uint versio, int function(int) funcio) is not callable using 
argument types (string,int,int delegate(int a) pure nothrow)
algorisme.d:30: Error: cannot implicitly convert expression 
(__dgliteral1) of type int delegate(int a) pure nothrow to 
int function(int)
algorisme.d:27: Error: function D main has no return 
statement, but is expected to return a value of type int



What fails?

PS: Thanks for your recommendations...
PPS: By the other hand, I see you have learned catalan 
("MeuAlgorisme"?) ;-)


Problem may be here:


alg.funcio = (int a) { return 2 * a; };


2.057 and earlier (You may use gdc 2.057 and command line 
wrapper gdmd), function literal always deduced as 'delegate'. 
So this expression raises an error about type mismatching Lhs 
of 'int function(int)' and  Rhs of 'int delegate(int) pure 
nothrow'.


Then, specifying explicit 'function' will resolve issue:

 alg.funcio = function(int a) { return 2 * a; };

Bye.

Kenji Hara


Thanks, Kenji. If I change function to delegate in declaration 
of field, it works too. What do you recommend to have delegates 
or functions? What are the benefits and ...


Thanks,
Xan.


For an example, you can't use function-pointer to access 
non-static methods, while with delegates you can. You can see 
some examples on http://www.dlang.org (Languate Reference).


Re: KeyType, ValueType traits for hashes

2012-01-24 Thread Dejan Lekic

Andrej, I agree, they should be in std.traits .



Re: floating-WTF

2012-01-24 Thread Dejan Lekic

No, it is not a bug.

Here is a hint:

import std.stdio;

int main() {
 float f;
 writeln(f);
 return 0;
}

/+--- output --+
nan
+--- end of output ---+/



Re: Calling a C++ Object from D

2012-01-24 Thread Dejan Lekic
Unfortunately, you cant use C++ namespaces. More about 
interfacing to C++ here: http://www.dlang.org/cpp_interface.html .


The easiest way to solve this is to write a C function that will 
glue your code with the C++ library.


Re: learn D & TDPL

2012-01-24 Thread Dejan Lekic
Many things changed since the book has been released. I is 
strange that you did not see the link to the TDLP errata 
(http://erdani.com/tdpl/errata/) by now. :)






Re: actors library?

2012-01-24 Thread Dejan Lekic
Xan, read this article please: 
http://www.informit.com/articles/article.aspx?p=1609144


You have exactly what you are looking for in the D runtime and 
standard library.


Re: C++ vs D aggregates

2011-12-07 Thread Dejan Lekic

What does not?

Yes, that kind of struct will work. :) Try to add a constructor...


Is D associative array thread safe, and will it relocate memory when add or delete a value?

2011-12-07 Thread Dejan Lekic

On 2011-Dec-07 02:17:17+00:00, raojm wrote:

Is D associative array  thread safe, and  will it relocate memory when
add or delete a value?
Where I can find the implemention.

Phobos and druntime are on GitHub, you can always check out the source...


C++ vs D aggregates

2011-12-03 Thread Dejan Lekic
I recently stumbled on this thread: http://stackoverflow.com/
questions/5666321/what-is-assignment-via-curly-braces-called-and-can-it-
be-controlled

The important part is this:

 8< - begin -
The Standard says in section §8.5.1/1,

An aggregate is an array or a class (clause 9) with no user-declared 
constructors (12.1), no private or protected non-static data members 
(clause 11), no base classes (clause 10), and no virtual functions (10.3).

And then it says in §8.5.1/2 that,

When an aggregate is initialized the initializer can contain an 
initializer-clause consisting of a brace-enclosed, comma-separated list 
of initializer-clauses for the members of the aggregate, written in 
increasing subscript or member order. If the aggregate contains 
subaggregates, this rule applies recursively to the members of the 
subaggregate.
 >8 - end -

Do D2 aggregates behave the same, or are there notable differences?


Re: Compile time metaprogramming

2011-12-03 Thread Dejan Lekic
David, to be frank, your code is already useful! Something is better than 
*nothing*! I hope you or someone else will continue with these two modules, 
and include them in Phobos.


Re: piping processes

2011-12-01 Thread Dejan Lekic

We talked about that too on IRC - the conclusion was - we should have 
std.pipe module with (at least) AnonymousPipe, and NamedPipe classes.


Re: piping processes

2011-12-01 Thread Dejan Lekic
NMS wrote:

> Is there a cross-platform way to create a new process and get its i/o
> streams? Like java.lang.Process?

I doubt. However, you can use platform-specific popen() (POSIX) and _popen() 
(Windows) for that. I recently talked about this on IRC. At the moment 
Phobos uses system() , redirects the output of a command to a temp file, and 
reads the file (that is how the shell() is implemented on Windows). My 
question was - why not using _popen() ???


Re: [OT] For Andrej Mitrovic, Cairo OpenGL and Windows...

2011-11-25 Thread Dejan Lekic

I was always under the impression that Cairo has transparent OpenGL support 
if Glitz is enabled. Is that correct?


Re: Fields size property

2011-11-22 Thread Dejan Lekic

This one is not good either because it does not include TypeInfo, etc...

__traits(classInstanceSize, T)) is better choice, as Ali said... :)


Re: DFastCGI

2011-11-22 Thread Dejan Lekic
Good news! This should be a part of the Deimos organisation. :)
Also, the post should be in the D.announce newsgroup. :)

Well-done!



Re: Fields size property

2011-11-18 Thread Dejan Lekic
Andrej Mitrovic wrote:

> .sizeof on a struct works nicely since it's a POD, but this can't work
> on classes since it just returns the pointer size.
> 
> I don't know whether this is useful all that much, but I'm curious how
> large my classes are. Anyway, since I couldn't find anything in Phobos
> I've got this working:
> 
> import std.traits;
> 
> auto getFieldsSizeOf(T)() {
> size_t result;
> foreach (type; RepresentationTypeTuple!Foo) {
> result += type.sizeof;
> }
> return result;
> }
> 
> template fieldsSizeOf(T) {
> enum size_t fieldsSizeOf = getFieldsSizeOf!T();
> }
> 
> class Foo { int x, y; }
> static assert(fieldsSizeOf!Foo == 8);
> void main() { }

Sure it can be useful sometimes to know (roughly) the size of your classes.
I modified the function to:

auto getFieldsSizeOf(T)() {
  size_t result;
  foreach (type; RepresentationTypeTuple!T) {
static if (is(type == class) ) {
  result += getFieldsSizeOf!type();
} else {
  result += type.sizeof;
}
  }
  return result;
}

As you can see, it goes little bit deeper so code like this:
class Bar { int x, y; Foo f; }
writeln(fieldsSizeOf!Bar);
gives us 16 as output not 8.



Re: Generic array

2011-11-16 Thread Dejan Lekic
RenatoL wrote:

> ##[3] arr = [0, "aa", 2.4];
> 
> What can i put instead of ##?
> 
> In C#, just for example, i can write:
> 
> object[] ar1 = new object[3];
> ar1[0] = 1;
> ar1[1] = "hello";
> ar1[2] = 'a';
> 
> and it works. But in D
> 
> Object[3] arr0 = [0, "aa", 2.4];
> 
> and  compiler complains

In D, the equivalent would be:

Variant[] arr = variantArray(0, "aa", 2.4);


Re: Mutable enums

2011-11-14 Thread Dejan Lekic
so wrote:

> 
> immutable a;
> sort(a);
> 
> But with current design you can do:
> 
> enum a;
> sort(a);
> 
> Which is to me, quite wrong.

It is not wrong at all.


Re: Database API

2011-11-10 Thread Dejan Lekic
Somedude wrote:

> Hello,
> 
> what is the currently DB API considered usable today ?
> 
> http://prowiki.org/wiki4d/wiki.cgi?DatabaseBindings#ODBC
> 
> d-dbapi looked quite decent, but the source code is no longer available :(
> 
> Thank you
> 
> Dude

Try this alternative - http://www.dsource.org/projects/ddbi/ - I remember 
brainstorming DDBI with its author some 6-7 years ago on the 
irc://irc.freenode.org/d channel. :) Then Lars took over the project so I 
believe it is becoming better and better.




Is there a portable way to limit memory/cpu usage of a D application?

2011-11-09 Thread Dejan Lekic
I would be satisfied with something like POSIX.1-2001 setrlimit() . Sure 
nothing prevents me from using setrlimit() in my D app, but perhaps it is 
something to think about a portable way of doing that.

One thing I like about my Java apps is that I can always specify (in the 
argument list) how much memory I want to allocate for them). Yes, it is a 
JVM specific thing, but perhaps a GC should have options to set at least the 
memory limit?

Kind regards


Re: web development in D programming

2011-11-09 Thread Dejan Lekic
bioinfornatics wrote:

> 
> I am a little disapointed, so if you have many request for a web page
> this lib  http://arsdnet.net/dcode/ is usable or not ?
> 

I am developing an implementation of the FastCGI protocol 
(http://www.fastcgi.com) in D2 with the main goal go have multiplexing 
support. However the development is slow due to the lack of time.

I believe a good http server implementation would be appreciated by the 
community, but FastCGI server will make it possible to create a highly-
scalable web applications using some of the well-known web servers (I use 
Lighttpd for an example).

Your code is usable, but not production-ready.



  1   2   >