D-style mixins in C#

2012-08-30 Thread Aleksandar Ružičić
Not really about D, but it's nice to see C# feature (although not 
official, and some may call it even a hack) inspired by D :)


http://blogs.jetbrains.com/dotnet/2012/08/resharper-sdk-adventures-part-5-%E2%80%94-d-style-mixins-in-c/

There's also a HN discussion: 
http://news.ycombinator.com/item?id=4455983


Re: [OT] Windows users: Are you happy with git?

2012-05-18 Thread Aleksandar Ružičić

On Friday, 18 May 2012 at 07:58:26 UTC, Lars T. Kyllingstad wrote:
I remember back when we were considering whether to move DMD, 
Phobos and druntime from SVN on DSource to Git on GitHub, there 
were some concerns about using Git on Windows.  People claimed 
that Git was a very Linux-centric tool, and that Windows 
support was buggy at best.


Still, we made the switch, and I haven't really registered that 
many complaints since.  So now I'm curious:  Windows users, 
have you just resigned, or did Git actually turn out to work 
well on Windows?  Specifically, is it usable from the CMD 
command line, and are graphical front-ends such as TortoiseGit 
any good?  (I know running it through Cygwin works well, but 
that doesn't count.)


-Lars


I'm using both, Linux and Windows, but I prefer working on 
Windows (I don't have X on my Linux installation, and it's not 
very cozy to spend all day in console). On Windows I have MSYS + 
Console2 setup, so I basically have nice looking (and more 
importantly functional) Linux console on my Windows.


Oh, and yes, git (msysgit actually) is working great on Windows 
(just a bit slower than Linux version, but still faster than svn).


Re: Do not write object file?

2012-05-17 Thread Aleksandar Ružičić

On Thursday, 17 May 2012 at 10:16:38 UTC, Andre Tampubolon wrote:

Every time I compile a D code, an .obj file is generated.
Is there any to prevent that?

I tried dmd -o- hello.d. Indeed there's no obj file. And no
executable, too.

Maybe this is a bug?


If you don't want object files to be generated (actually they 
must be generated in order for linker to build exe) compile with 
rdmd (it will put object files in a temp directory so your 
project folder is kept clean):


rdmd --build-only (dmd parameter here) main.d

also rdmd will take care of your dependencies so you just have to 
pass it your main file.


Re: What about x64 windows?

2012-04-11 Thread Aleksandar Ružičić

On Wednesday, 11 April 2012 at 12:45:08 UTC, Davita wrote:

Hi guys.
Is there a going development on x64 compiler for windows? Or D 
won't support x64 at all?


Thanks


As far as I know, optlink (linker used by dmd on windows) cannot 
output 64bit binaries, so until optlink gets upgraded (or until 
dmd switches to another linker, which I think all of us windows 
devs would really like to see) there will be no support for 64bit 
D applications on windows..


Re: Vote on std.regex (FReD)

2011-10-23 Thread Aleksandar Ružičić

Yes


Re: Proposal on improvement to deprecated

2011-10-03 Thread Aleksandar Ružičić

What about using an attribute for that?

deprecated(foo() is deprecated use bar()) void foo() {...}
@schedule deprecated(foo() is going to be deprecated as of -MM-DD, use 
bar() instead) void foo() {...}


First form will behave like just it does now, with optional message 
argument.
Second form would produce informational message instead of compile error 
(with line number where that symbol is accessed from).


Both forms would print nothing when using -d switch.

In case unavailable is required, another attribute could be used for that:

@removed deprecated(foo() was removed as of -MM-DD, use bar() 
instead.) void foo();


When @removed deprecated symbol is used compiler will abort with detailed 
error message (line number where symbol is accessed from) even if -d switch 
is used. This would be more convenient than just bailing out with message 
undefined symbol foo() because we can  use message parameter of deprecated 
to direct user where to look for replacement.


Of course @schedule and @removed names are just an example..


Jonathan M Davis  wrote in message 
news:mailman.29.1317612078.22016.digitalmar...@puremagic.com...


On Sunday, October 02, 2011 07:06:36 Michel Fortin wrote:

On 2011-10-02 05:24:36 +, Jonathan M Davis jmdavisp...@gmx.com said:
 deprecated(message, soft) void func1() {}
 deprecated(message, hard) void func2() {}

This soft/hard thing is a little obscure, no one will understand what
it means by looking a it. Why not have separated 'deprecated' and
'unavailable' states?


We could just do

deprecated(message);
deprecated(message, full);

Full deprecation should be clear enough, I would think. And for 
simplicity,

you just don't have any argument for partial deprecation.

- Jonathan M Davis 



Re: Versioned extern?

2011-07-29 Thread Aleksandar Ružičić
Ouh, haven't read that you don't want code to be mixed-in.. In that
case.. I dunno :)

2011/7/29 Aleksandar Ružičić ruzicic.aleksan...@gmail.com:
 If I'm not mistaken extern() accepts only Identifier, not expression.
 I'm not really sure what's the best way to do that but I belive this
 should work (haven't tested):

 enum code = q{

   void func() {
           // do something
   }
 };

 version (Windows) {
   extern (Windows) {
       mixin(code);
   }
 } else {
   extern (C) {
       mixin(code);
   }
 }

 On Sun, Jul 24, 2011 at 5:35 AM, Nick Sabalausky a@a.a wrote:
 Is there a way to have a section of code be extern(C) on one OS and
 extern(Windows) on another OS, without resorting making the code in question
 a mixin?

 These doesn't appear to work:

 --
 version(Windows)
 {
    enum callingConvention = Windows;
 }
 else
 {
    enum callingConvention = C;
 }

 extern(mixin(callingConvention ))
 {
    /+ ...code here... +/
 }
 --
 version(Windows)
 {
    extern(Windows):
 }
 else
 {
    extern(C):
 }

 /+ ...code here... +/

 extern(D):
 --








Re: ddoc patterns

2011-04-08 Thread Aleksandar Ružičić
On Fri, Apr 8, 2011 at 8:52 PM, spir denis.s...@gmail.com wrote:
 Right, but IIUC unlike pre there is no guarantee for code contents not
 to be interpreted further. It's a semantic hint to the rendering engine
 (which is often used to perform syntax highlighting).

AFAIK no major browser (A-grade browser) does nothing more with code
than making it have monospaced font (i.e. look at default styles for
all elements in webkit:
http://trac.webkit.org/browser/trunk/Source/WebCore/css/html.css,
you'll see code only has it's font-family defined, while pre has
few others more, most notably white-space: pre; and display: block).
And no browser supports rendering syntax highlighting (as I know of)
for any computer language (there are user scripts and maybe extensions
which does that but in no way is that default behavior).

It's true, code does have semantic hint, and that's hey anything
between code and /code is a computer code!, which is I believe
exact what you want - to display some code inline..


Re: ddoc patterns

2011-04-08 Thread Aleksandar Ružičić
On Fri, Apr 8, 2011 at 8:52 PM, spir denis.s...@gmail.com wrote:
 Yes:
        Macros:
            CODE = code$0/code

That's really nice! I might take a look at ddoc and try to write some
useful macros if it's expressive enough...


Re: std.string.indexOf with an optional start-at parameter?

2011-04-04 Thread Aleksandar Ružičić
On Mon, Apr 4, 2011 at 3:18 PM, Steven Schveighoffer
schvei...@yahoo.com wrote:
 On Sun, 03 Apr 2011 14:24:33 -0400, spir denis.s...@gmail.com wrote:
 Agreed this is a fairly standard param in other languages, but D easily
 (and rather cheaply) allows
     auto pos = indexOf(s[i..$], char);

 That doesn't work, because it gets you the position in relation to s[i..$],
 whereas you want the position in relation to s.


This works:
---
sizediff_t
indexOf(Char, T = sizediff_t)(in Char[] s, dchar c, T sp = 0)
if (isSomeChar!Char)
{
if (sp  0)
sp += s.length;

if (sp = 0  sp  s.length)
{
auto i = indexOf(s[sp..$], c);
if (i  -1)
return i + sp;
}
return -1;
}
---

And it doesn't require change of existing indexOf.


Re: Complete D grammar

2011-04-04 Thread Aleksandar Ružičić
On Mon, Apr 4, 2011 at 8:11 PM, Bruno Medeiros
brunodomedeiros+spam@com.gmail wrote:

 BTW, I wanna thank for this work (current and upcoming), it is likely useful
 for other IDE projects as well ;)


Ditto.

I have started work on D language support for NetBeans (IMHO it's MUCH
better editor than Eclipse) and started to write grammar for javaCC,
but since there is ongoing work on ANTLR parser I'll wait for that to
be done and integrate it into plugin I'm working on. :)


Re: New look feel for std.algorithm

2011-04-04 Thread Aleksandar Ružičić
This is much better than current style of documentation. But still I
find D (phobos) documentation hard to read because there are dozens
functions on one page.

I think that's ok for reference documentation, but I think that for
newcomers (myself included) is much easier to follow documentation in
form of a manual where every function has it's own page with more than
one example. Just like PHP Manual. I think their feature of user
submitted comments/examples per each function is great.

Ideally I would like to see both options, reference per module to
quickly find a function I need (just like what we have now) and
dedicated page for each function.

I know that this cannot be made by it self and that some men/hours
must be spent to make it happen, so I'm willing to offer my help to
build this (I'm professional web developer, with a skill set of
html\css\javascript\php\mysql and some basic photoshop know-how) if
there is any chance this proposal be accepted.

Regards,
Aleksandar


Re: Complete D grammar

2011-04-04 Thread Aleksandar Ružičić
On Mon, Apr 4, 2011 at 9:05 PM, Steven Schveighoffer
schvei...@yahoo.com wrote:
 On Mon, 04 Apr 2011 14:51:02 -0400, Aleksandar Ružičić
 ruzicic.aleksan...@gmail.com wrote:

 On Mon, Apr 4, 2011 at 8:11 PM, Bruno Medeiros
 brunodomedeiros+spam@com.gmail wrote:

 BTW, I wanna thank for this work (current and upcoming), it is likely
 useful
 for other IDE projects as well ;)


 Ditto.

 I have started work on D language support for NetBeans (IMHO it's MUCH
 better editor than Eclipse) and started to write grammar for javaCC,
 but since there is ongoing work on ANTLR parser I'll wait for that to
 be done and integrate it into plugin I'm working on. :)

 I would absolutely love NetBeans support for D.

 -Steve


Me too, so when I realized that no such project exists I've decided to
write it my self (after all I write Java for few year now so I feel
comfortable with it) but I knew that writing parser will take me most
time and effort so it's great to see someone decided to write
parser/grammar for ANTLR which can be used by other projects (in that
way few IDEs could share same parser and focus on other parts of an
IDE).


Re: Complete D grammar

2011-04-04 Thread Aleksandar Ružičić
On Mon, Apr 4, 2011 at 8:58 PM, Andrei Alexandrescu
seewebsiteforem...@erdani.org wrote:
 Aleksandar, would you be willing to work with the student working on ANTLR
 as a mentor? Please let me know and I'll send details about applying as a
 mentor.

Well, I'm also a student :)
So I'm not sure if I really can be a mentor (23yrs old), and I have
never worked with ANTLR before but language theory (grammars, parsers
and all that stuff) was always my favorite subject so I know a bit
about all that.

I'm willing to help in any way I can..


std.string.indexOf with an optional start-at parameter?

2011-04-03 Thread Aleksandar Ružičić
I needed std.string.indexOf to accept start position in the string to
start the search at. I was really surprised when I realized that this
(to me) standard parameter is missing (I'm used to indexOf in
javascript, strpos in php and equivalent methods in other languages,
which support start offset parameter).

There might be some other function (in some other module) that does
what I want but I wasn't able to find it (I find D's documentation not
easy to search and read), so I've copied indexOf to my module and
added wanted functionality:

https://gist.github.com/900589

now, I'm able to write, for example:

auto pos = indexOf(haystack, '$', 10); // will starts search at 11th
char in haystack

and

auto pos = indexOf(haystack, '$', -5); // will starts search at 5th
char from the end

My question is: is there a reason why there is no this functionality
in phobos (maybe there's some language feature I'm not aware of?) and
if no such reason exists, would it be possible to add it in future
version of phobos/dmd?


Re: std.string.indexOf with an optional start-at parameter?

2011-04-03 Thread Aleksandar Ružičić
I thought first of slicing, but isn't that making a copy of string?
And also, if I'm not mistaken if you slice out of range bounds (i.e.
haystack[5..$] when haystack.length  5) you'll get exception, right?

That's why I think this would be nice to have feature, so you don't
have to worry if start position is within the string bounds, and you
won't need to write this:

 auto pos = indexOf(haystack[$-5..$], '$') + haystack.length-5;

when you want to start search from the end (since it's somehow less
readable than indexOf(haystack, '$', -5)).

On Sun, Apr 3, 2011 at 7:55 PM, Robert Jacques sandf...@jhu.edu wrote:
 On Sun, 03 Apr 2011 13:39:40 -0400, Aleksandar Ružičić
 ruzicic.aleksan...@gmail.com wrote:

 I needed std.string.indexOf to accept start position in the string to
 start the search at. I was really surprised when I realized that this
 (to me) standard parameter is missing (I'm used to indexOf in
 javascript, strpos in php and equivalent methods in other languages,
 which support start offset parameter).

 There might be some other function (in some other module) that does
 what I want but I wasn't able to find it (I find D's documentation not
 easy to search and read), so I've copied indexOf to my module and
 added wanted functionality:

 https://gist.github.com/900589

 now, I'm able to write, for example:

 auto pos = indexOf(haystack, '$', 10); // will starts search at 11th
 char in haystack

 auto pos = indexOf(haystack[10..$], '$') + 10;

 and

 auto pos = indexOf(haystack, '$', -5); // will starts search at 5th
 char from the end

 auto pos = indexOf(haystack[$-5..$], '$') + haystack.length-5;

 My question is: is there a reason why there is no this functionality
 in phobos (maybe there's some language feature I'm not aware of?) and
 if no such reason exists, would it be possible to add it in future
 version of phobos/dmd?

 Yes, the language feature is called slicing. See above. Also, you may want
 to look at the various find methods in std.algorithm. Generally, it's better
 to work with ranges/slices than indexes due to UTF's encoding scheme.



Re: std.string.indexOf with an optional start-at parameter?

2011-04-03 Thread Aleksandar Ružičić
On Sun, Apr 3, 2011 at 8:16 PM, Andrei Alexandrescu
seewebsiteforem...@erdani.org wrote:
 It's not.

Seems I've missed that in the docs, I tought it will always make a copy :)

 I think that's a natural and simple improvement of indexOf. The one aspect
 that I'm unsure about is starting from the end for negative indices.

Negative indices might seem a bit odd but it's standard in other
languages (like javascript and php which I've already mentioned).
I would even like to see this in D:

array[-2];  // get 'a' from foobar

same for slicing:

array[-4..2];  // get ob from foobar

 Could you please submit an enhancement request to bugzilla?

sure!


Forking phobos

2011-04-03 Thread Aleksandar Ružičić
I want to fork Phobos and hack a bit on it (maybe even submit some
pull requests, someday), but I'm having trouble compiling it (on
windows).
This is what I've done:

 - forked phobos on github
 - cloned the fork to my machine
 - run make -f win32.mak

and make complained that it can't make druntime lib. So I've cloned
druntime in same directory where i have phobos (so I now have phobos
and druntime directories on same level),
Did make -f win32.mak clean and tried make again, but it still
complains about druntime:

cd ..\..\..
Error: don't know how to make '..\druntime\lib\druntime.lib'

What I'm I doing wrong? Am I missing some more components?
I just want to be able to edit phobos source, compile it to phobos.lib
and link it to my d program.

I have DMC, DMD and LINK on PATH, that's not the issue...


Thanks,
Aleksandar


Re: std.string.indexOf with an optional start-at parameter?

2011-04-03 Thread Aleksandar Ružičić
 You mean Python and Ruby.

  - Javascript does not support negative index. In fact, JS has no true
 arrays, it only has associative array.
  - PHP does not support negative index. http://ideone.com/8MZ2T

I was talking about javascript's String.prototype.indexOf () and php's
strpos functions, not about array indexing.
But even for that I wasn't correct :/. Negative start-at index is
avaliable for substr (both, in php and js), that's why I have confused
it with indexOf (I thought these things are consistent..)

And javascript _does_ have true arrays, but it _doesn't_ have true
associative arrays (those are object literals).

 This does not mean negative index is useless (I use it all the time when
 programming in Python), but D shouldn't add a feature just because other
 languages have it, or even you think that language had it.

I know, I was just expressing my opinion (what I would like to see in
a language, I never programmed in phyton or perl, so I was thinking
that negative indices for array indexing are not supported in any
language that I know of), I wasn't proposing a new feature :)


Re: std.string.indexOf with an optional start-at parameter?

2011-04-03 Thread Aleksandar Ružičić
On Sun, Apr 3, 2011 at 10:56 PM, KennyTM~ kenn...@gmail.com wrote:
 And javascript _does_ have true arrays, but it _doesn't_ have true
 associative arrays (those are object literals).


 I would not call it a true array if it is indexed by string internally.
 Anyway, this is not the main point.


You're right that JS arrays are not a point here, but I must again
disagree with you :)
I write Javascript code for living, so I think I know what I'm talking about:

var a = [foo, bar, baz];  // defining an array
a[0];// foo
a[0];  // this would also work, but only because JS casts 0 to
integer implicitly

there is no string indexing with arrays, only with objects
(associative arrays, maps, call it as you like):

var o = {foo: bar, 0: baz};  // defining an object (a.k.a AA)
o.foo;  // bar
o[foo];  // same, returns bar
o[0];   // baz   now, this just looks like indexing an array,
but it really ain't, it's property getter, but JS allows you have
numeric properties so it can be confusing, I admit.

That's all I have to say about JS arrays, won't be talking non-D anymore :)

Regards,
Aleksandar


Re: Forking phobos

2011-04-03 Thread Aleksandar Ružičić
Thanks! I've changed sc.ini, built druntime and then phobos successfully.

Now, I'm able to build phobos.lib but when I try to compile simple
hello world program and link it to that phobos.lib OPTLINK greets me
with this:

C:\dmd hello.d
OPTLINK (R) for Win32  Release 8.00.8
Copyright (C) Digital Mars 1989-2010  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
C:\Users\Aleksandar\Dropbox\Projects\phobos\phobos.lib(lifetime)
 Error 42: Symbol Undefined _D4core5bitop3bsrFNaNbkZi
C:\Users\Aleksandar\Dropbox\Projects\phobos\phobos.lib(gcx)
 Error 42: Symbol Undefined _D4core5bitop3bsfFNaNbkZi
C:\Users\Aleksandar\Dropbox\Projects\phobos\phobos.lib(gcx)
 Error 42: Symbol Undefined _D4core5bitop3btsFNbPkkZi
C:\Users\Aleksandar\Dropbox\Projects\phobos\phobos.lib(gcx)
 Error 42: Symbol Undefined _D4core5bitop3btrFNbPkkZi
--- errorlevel 4

this is my sc.ini:

[Version]
version=7.51 Build 020

[Environment]
LIB=C:\Users\Aleksandar\Dropbox\Projects\druntime\lib;C:\Users\Aleksandar\Dropbox\Projects\phobos\;C:\bin\dmd2\windows\lib;C:\bin\dm\lib
DFLAGS=-IC:\Users\Aleksandar\Dropbox\Projects\phobos\;C:\Users\Aleksandar\Dropbox\Projects\druntime\import
LINKCMD=%@P%\link.exe

Also, when i do make -f win32.mak unittest I get the same error:

 --- std.socket(316) broken test ---
 --- std.regex(3443) broken test ---
OPTLINK (R) for Win32  Release 8.00.8
Copyright (C) Digital Mars 1989-2010  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
unittest.obj(unittest)
 Error 42: Symbol Undefined _D4core5bitop3bsrFNaNbkZi
..\druntime\lib\druntime.lib(gcx)
 Error 42: Symbol Undefined _D4core5bitop3bsfFNaNbkZi
..\druntime\lib\druntime.lib(gcx)
 Error 42: Symbol Undefined _D4core5bitop3btsFNbPkkZi
..\druntime\lib\druntime.lib(gcx)
 Error 42: Symbol Undefined _D4core5bitop3btrFNbPkkZi
--- errorlevel 4

(plus 2 broken tests)

Do I need latest DMD from github?



On Sun, Apr 3, 2011 at 11:30 PM, Jonathan M Davis jmdavisp...@gmx.com wrote:
 On 2011-04-03 12:48, Aleksandar Ružičić wrote:
 I want to fork Phobos and hack a bit on it (maybe even submit some
 pull requests, someday), but I'm having trouble compiling it (on
 windows).
 This is what I've done:

  - forked phobos on github
  - cloned the fork to my machine
  - run make -f win32.mak

 and make complained that it can't make druntime lib. So I've cloned
 druntime in same directory where i have phobos (so I now have phobos
 and druntime directories on same level),
 Did make -f win32.mak clean and tried make again, but it still
 complains about druntime:

 cd ..\..\..
 Error: don't know how to make '..\druntime\lib\druntime.lib'

 What I'm I doing wrong? Am I missing some more components?
 I just want to be able to edit phobos source, compile it to phobos.lib
 and link it to my d program.

 I have DMC, DMD and LINK on PATH, that's not the issue...

 I believe that these are the correct steps:

 1. Make sure that druntime and phobos were both put at the same directory
 level. e.g. I have C:/github/druntime and C:/github/phobos.

 2. Adjust your sc.ini accordingly. e.g. Mine is

 =
 [Version]
 version=7.51 Build 020

 [Environment]
 LIB=c:\github\druntime\lib;c:\github\phobos\;c:\dmd2\windows\lib;c:
 \dm\lib
 DFLAGS=-Ic:\github\phobos\;c:\github\druntime\import
 LINKCMD=%@P%\link.exe
 =

 3. Build druntime by running make -f win32.mak in the druntime directory.

 4. Build Phobos by running make -f win32.mak in the phobos directory.

 - Jonathan M Davis



Re: Is the world coming to an end?

2011-04-02 Thread Aleksandar Ružičić
Nice to see awkward octal literal syntax being removed from Phobos! :)

On Sat, Apr 2, 2011 at 10:16 PM, Andrej Mitrovic n...@none.none wrote:
 https://github.com/D-Programming-Language/phobos/commit/83f99df573c089cc186ef370cb691c2f8a25c873
 https://github.com/D-Programming-Language/phobos/commit/88904f7795a94b23e750e10a2addc90783089de7

 If I didn't know it better I would think it's still April 1st. :D



Re: Asynchronicity in D

2011-03-31 Thread Aleksandar Ružičić
I really like design of node.js (http://nodejs.org) it's internally
based on libev and everything runs in a single-threaded event loop.
It's proven to be highly concurrent and memory efficient.

Maybe a wrapper around libev(ent) for D ala node.js would be good
solution for asynchronous API, other than thread approach (I always
like to have more than one option and choose one which suits better
for concrete task I'm dealing with).

Whatever solution to be chosen I'd like to have an API like this:

readTextAsync(filename, (string contents) {
  // do something with contents
});


Re: Asynchronicity in D

2011-03-31 Thread Aleksandar Ružičić
I really like design of node.js (http://nodejs.org) it's internally
based on libev and everything runs in a single-threaded event loop.
It's proven to be highly concurrent and memory efficient.

Maybe a wrapper around libev(ent) for D ala node.js would be good
solution for asynchronous API, other than thread approach (I always
like to have more than one option and choose one which suits better
for concrete task I'm dealing with).

Whatever solution to be chosen I'd like to have an API like this:

readTextAsync(filename, (string contents) {
   // do something with contents
});


On Thu, Mar 31, 2011 at 2:04 PM, Piotr Szturmaj bncr...@jadamspam.pl wrote:
 Max Klyga wrote:

 I've been thinking on things I can change in my GSoC proposal to make it
 stronger and noticed that currently Phobos does not address asynchronous
 I/O of any kind.

 A number of threads on thid newsgroup mentioned about this problem or
 shown ways other languages address asynchronicity.

 I want to ask D community about plans on asynchronicity in Phobos.
 Did somenone in Phobos team thought about possible design?
 How does asynchronicity stacks with ranges?
 What model should D adapt?
 etc.


 Yes, asynchronous networking API would be more scalable. If you're
 collecting information about async IO, please take a look at libevent and
 libev, also NT's completion ports, FreeBSD's kqueue and Linux epoll.

 Protocols implemented using event-driven APIs should scale to thousands of
 connections using few working threads. Moreover async protocols could be
 wrapped to be synchronous (but not other way around) and used just like well
 known blocking API's.

 Basically, while using async IO, you request some data to be written and
 then wait for completion event (usually by callback function). Then you
 request some allocated buffer to be read and then you wait until network
 stack fills it up. You do not wait for blocking operation like with using
 send() or recv(), instead you may do some useful processing between events.



Re: Using opDispatch as *magic* getter/setter. Possible or not?

2011-03-31 Thread Aleksandar Ružičić
On Thu, Mar 31, 2011 at 8:52 AM, Jacob Carlborg d...@me.com wrote:

 Or, I think this will work as well:

 @property ref ConfigSection opDispatch(string sectionName, Args ...)(Args
 args) if (Args.length == 0)
 {
 // getter
 }


 @property ref ConfigSection opDispatch(string sectionName, Args ...)(Args
 args) if (Args.length == 1)
 {
 // setter
 }
 }

 auto foo = new Foo;

 foo.bar; // works
 foo.bar = 3; // currently does not work, bug
 foo.bar(3); // works

 --
 /Jacob Carlborg


That's great! Thanks! If just the assignment worked thought, it would
be perfect..
Btw, do you know which issue # that is? I'd like to read more about
that bug but can't find it on bugzilla.


On Thu, Mar 31, 2011 at 3:50 AM, spir denis.s...@gmail.com wrote:

 Agreed. And I would really have an answer to your question, since I tried to
 do the same thing. Don't understand why D does not have an 'opMember' or
 'opDot'. Someone knows?
 This would be one of the first metamethods I would introduce in a language
 (definitely before operator overloading).


Yeah, opMember would be great, but it seems that we'll be able to use
opDispatch for that in a way Jacob described once the bugs are ironed
out..
But until then I'll have to live with ugly indexing sytnax...


Re: Using opDispatch as *magic* getter/setter. Possible or not?

2011-03-31 Thread Aleksandar Ružičić
On Thu, Mar 31, 2011 at 1:30 PM, Steven Schveighoffer
schvei...@yahoo.com wrote:

 or you can change the template parameters in the opDispatch setter:

 @property ref ConfigSection opDispatch(string sectionName, T : string)(T
 arg)

 -Steve


Thanks, that's much more readable I now have these templates:

// getter
@property ref ConfigEntry opDispatch(string entryName)() pure {
if (!(entryName in entries)) {
entries[entryName] = new ConfigEntry(config);
}
return entries[entryName];
}

// setter
@property void opDispatch(string entryName, T : string)(in T value) {

if (!(entryName in entries)) {
entries[entryName] = new ConfigEntry(config);
}

entries[entryName] = value;
}

And that compiles just fine (I dunno if it runs ok since I'm currently
on windows and I've been messing with my setup so optlink can't stop
complaining.. sigh..)

but due to bug not allowing foo.bar = abc; I've also added opIndex
and opIndexAssign (apparently you cannot only have opIndexAssign
defined) as temporary backup solution..


Non-Virtual Interfaces

2011-03-04 Thread Aleksandar Ružičić
I'm trying to use NVI idiom but i keep getting errors from dmd.

This is my setup:

module test;

import std.stdio;

interface IBase {
void foo();
void bar();
}

interface IBar : IBase {
final void bar() {
writefln(IBar.bar());
}
}

class Foo : IBar {

void foo() {
writefln(Foo.foo());
}
}

void main() {

Foo foo = new Foo();
foo.foo();
}

When I try to compile it i get test.d(16): Error: class test.Foo
interface function IBar.bar isn't implemented

And if I try to define bar() in Foo i receive test.d(22): Error:
function test.Foo.bar cannot override final function
IBar.test.IBar.bar
which is expected since IBar.bar() is final.

So, am I missing some point about NVIs here or is it just not yet
implemented in dmd?


Re: Non-Virtual Interfaces

2011-03-04 Thread Aleksandar Ružičić

 What you may want to consider is an abstract class instead of NVI, as long
 as you don't need multiple inheritance, it should be fine.

 -Steve


Well, I've decided to give NVI a try just because multiple inheritance
would be best way to do what I want (aldo I hate that feature of C++
and just don't use it) but it seems I can't do it with a NVI either...
So back to the drawing board for me :)

thanks for reply

- Aleksandar


Re: Non-Virtual Interfaces

2011-03-04 Thread Aleksandar Ružičić

 In D, the public function would have to be final to make it non-virtual/non-
 overridable, and the function it calls would have to be protected, since you
 can't override private functions (
 http://d.puremagic.com/issues/show_bug.cgi?id=4542 ). In this case, you're
 trying to override final functions, which doens't work at all.


Well I don't try to override final function, I know it cannot be done :)
I've just tried to override bar() in Foo when compiler told me that I
don't have that function implemented and I received message that it
cannot be overriden, as I've expected..

 However, if you're not trying to do anything other than call the implemented
 function (you're certainly not here), then there's no point to NVI. Just use a
 normal, public interface function or make the base class of your class 
 abstract
 and put the function's declaration there.

 - Jonathan M Davis


That was just an example, what was my goal was is to have setup like this:

interface IEvent {
   EventType type();
}

interface IEventListener {
   void handle(IEvent event);
}

class MyEvent : IEvent {

   this(bool flag) {
 this.flag = flag;
   }

   EventType type() {
 return EventType.MyEvent;
   }

   bool isFlag() {
 return flag;
   }

   private:
  bool flag;
}

interface IMyEventListener : IEventListener {
void onFlag(MyEvent event);
void onNotFlag(MyEvent event);

final void handle(IEvent event) {

   MyEvent e = cast(MyEvent) event;

   if (e !is null) {
 if (e.isFlag()) {
onFlag(e);
 } else {
onNotFlag(e);
 }
   }
}
}

which would allow me to have a class that can listen for different
events at the same time, but it seems that to be able to do that I'd
have to move handling routine into the event class..


std.algorithm.remove using SwapStrategy.unstable doesn't works

2010-11-16 Thread Aleksandar Ružičić
I'm trying to use remove() from std.algorithm to remove item from an
array and when I tried to use SwapStrategy.unstable (as I don't need
to maintain order of items in array and I want to optimize where ever
I can) I came to surprising results. In the example below one would
expect that item at index 2 (number 3 in example) will be removed but
instead item at index 0 is removed from array.

Is this a bug or I'm missing a point?

-

import std.stdio, std.algorithm;

void main(string[] args) {

auto a = [1,2,3,4];

foreach (e; a) writef(%s , e); writefln((%s), a.length); // 1 2 3 4 
(4)

auto i = a.indexOf(3);

writefln(%s, i);  // 2

if (i  -1) {
a = remove!(SwapStrategy.unstable)(a, i);
}

foreach (e; a) writef(%s , e); writefln((%s), a.length); // 4 2 3 
(3) !?!
}

-

thx in advance,
Aleksandar


Re: std.algorithm.remove using SwapStrategy.unstable doesn't works

2010-11-16 Thread Aleksandar Ružičić
No problem, just to isolate the code and to confirm it's not something
to other parts of my code (but I'm pretty sure it's not).

On Tue, Nov 16, 2010 at 7:03 PM, Andrei Alexandrescu
seewebsiteforem...@erdani.org wrote:
 On 11/16/10 4:24 AM, Aleksandar Ružičić wrote:

 I'm trying to use remove() from std.algorithm to remove item from an
 array and when I tried to use SwapStrategy.unstable (as I don't need
 to maintain order of items in array and I want to optimize where ever
 I can) I came to surprising results. In the example below one would
 expect that item at index 2 (number 3 in example) will be removed but
 instead item at index 0 is removed from array.

 Is this a bug or I'm missing a point?

 -

 import std.stdio, std.algorithm;

 void main(string[] args) {

         auto a = [1,2,3,4];

        foreach (e; a) writef(%s , e); writefln((%s), a.length); // 1 2
 3 4 (4)

        auto i = a.indexOf(3);

        writefln(%s, i);      // 2

        if (i  -1) {
                a = remove!(SwapStrategy.unstable)(a, i);
        }

        foreach (e; a) writef(%s , e); writefln((%s), a.length); // 4 2
 3 (3) !?!
 }

 -

 thx in advance,
 Aleksandar

 Looks like a bug. Could you please file it to bugzilla?

 Thanks,

 Andrei



Re: std.algorithm.remove using SwapStrategy.unstable doesn't works

2010-11-16 Thread Aleksandar Ružičić
filed as Issue #5224 - http://d.puremagic.com/issues/show_bug.cgi?id=5224

regards,
Aleksandar

2010/11/16 Aleksandar Ružičić ruzicic.aleksan...@gmail.com:
 No problem, just to isolate the code and to confirm it's not something
 to other parts of my code (but I'm pretty sure it's not).

 On Tue, Nov 16, 2010 at 7:03 PM, Andrei Alexandrescu
 seewebsiteforem...@erdani.org wrote:
 On 11/16/10 4:24 AM, Aleksandar Ružičić wrote:

 I'm trying to use remove() from std.algorithm to remove item from an
 array and when I tried to use SwapStrategy.unstable (as I don't need
 to maintain order of items in array and I want to optimize where ever
 I can) I came to surprising results. In the example below one would
 expect that item at index 2 (number 3 in example) will be removed but
 instead item at index 0 is removed from array.

 Is this a bug or I'm missing a point?

 -

 import std.stdio, std.algorithm;

 void main(string[] args) {

         auto a = [1,2,3,4];

        foreach (e; a) writef(%s , e); writefln((%s), a.length); // 1 2
 3 4 (4)

        auto i = a.indexOf(3);

        writefln(%s, i);      // 2

        if (i  -1) {
                a = remove!(SwapStrategy.unstable)(a, i);
        }

        foreach (e; a) writef(%s , e); writefln((%s), a.length); // 4 2
 3 (3) !?!
 }

 -

 thx in advance,
 Aleksandar

 Looks like a bug. Could you please file it to bugzilla?

 Thanks,

 Andrei