problems with mixins and non-ascii characters

2014-01-22 Thread Uplink_Coder

Hi,
When I try to define an Enum with an umlaut like ä

enum test2 {
l,
ä
}
I get  Error: basic type expected, not \u00e4
and Error: type only allowed if anonymous enum and no enum 
type


is there any workaround for this ?


Re: shared methods

2014-01-22 Thread Benjamin Thaut

Am 22.01.2014 06:16, schrieb unknown soldier:

I'm confused by shared and how to use it.

import std.stdio;
class Foo {
 File logFile;
 void log(in string line) shared {
   synchronized(this){
 logFile.writeln(line);
   }
 }
}

This (or the equivalent code in my full size program) won't
compile:

source/log.d(256): Error: template std.stdio.File.writeln does
not match any function template declaration. Candidates are:
/usr/include/dmd/phobos/std/stdio.d(781):
std.stdio.File.writeln(S...)(S args)
source/log.d(256): Error: template std.stdio.File.writeln(S...)(S
args) cannot deduce template function from argument types
!()(const(immutable(char)[])) shared

Why is logFile suddenly being treated as shared? This does not
make sense to me. As a programmer I have acknowledged that log()
is a shared function in the declaration 'void log(in string line)
shared', so isn't it up to me to ensure that I do proper
synchronization within the function? Why is the compiler trying
to ensure that all functions called within log() are also marked
shared?
What is the right thing to do here?

Note that I can't just mark log() as not shared; log() must be
shared because elsewhere I have:

shared Foo sfoo = ...
sfoo.log(...)


For a shared method the this pointer is also shared. That means that you 
have to tell the compiler (manually) that it is now safe to use 
non-shared code. You usually do this by casting the this pointer to a 
unshared type.


class Foo {
 File logFile;
 void log(in string line) shared {
   synchronized(this){
 // safe from here on because synchronized
 auto self = cast(Foo)this;
 self.logFile.writeln(line);
   }
 }
}

The compiler does not do this for you, because it can not know if 
accessing any member is truly thread-safe. You might share the logFile 
with other instances of Foo. This would be a case where the compiler 
would wrongly remove the shared from this, if it would do so 
automatically inside synchronized blocks.





Re: problems with mixins and non-ascii characters

2014-01-22 Thread Benjamin Thaut

Am 22.01.2014 11:46, schrieb bearophile:

Uplink_Coder:


is there any workaround for this ?


For me this is a feature, not a bug.

Bye,
bearophile


Why that? D is supposed to support unicode identifiers, and in this case 
it cleary does not?


Re: problems with mixins and non-ascii characters

2014-01-22 Thread bearophile

Uplink_Coder:


is there any workaround for this ?


For me this is a feature, not a bug.

Bye,
bearophile


Re: problems with mixins and non-ascii characters

2014-01-22 Thread Uplink_Coder

On Wednesday, 22 January 2014 at 10:46:30 UTC, bearophile wrote:

Uplink_Coder:


is there any workaround for this ?


For me this is a feature, not a bug.

Bye,
bearophile


I never said bug :D
just I thoght UniCode should make this a non-issue ...



Re: problems with mixins and non-ascii characters

2014-01-22 Thread monarch_dodra

On Wednesday, 22 January 2014 at 10:51:54 UTC, Uplink_Coder wrote:

On Wednesday, 22 January 2014 at 10:46:30 UTC, bearophile wrote:

Uplink_Coder:


is there any workaround for this ?


For me this is a feature, not a bug.

Bye,
bearophile


I never said bug :D
just I thoght UniCode should make this a non-issue ...


It's a bug. ä is a valid identifier.


Any library with OAuth support?

2014-01-22 Thread ilya-stromberg

Do you know any library with OAuth support?


Re: problems with mixins and non-ascii characters

2014-01-22 Thread Uplink_Coder
 Strange this bug seems to manifest itself only in some 
situations

enum ä {ä = ä}
does not work in dpaste but suddenly it works on my local 
enviorment (Windows-Mono-d,dmd 2.064.2)


it seems to have something todo with the abscence of a BOM header 
...


Re: Any library with OAuth support?

2014-01-22 Thread Rikki Cattermole
On Wednesday, 22 January 2014 at 11:14:22 UTC, ilya-stromberg 
wrote:

Do you know any library with OAuth support?


Not currently.
But I can add it to my todo list for Cmsed[0].

[0] https://github.com/rikkimax/Cmsed


Algorithm remove Tid

2014-01-22 Thread Casper Færgemand

import std.algorithm;
import std.concurrency;

void main() {
Tid[] tids = [];
Tid tid = thisTid;
tids ~= tid;
tids.remove(tid);
}

Why does this not compile?


Re: [Windows DMD] No callstack when crash with Access violation reading location 0x00000000

2014-01-22 Thread Flamaros
On Wednesday, 22 January 2014 at 02:11:02 UTC, TheFlyingFiddle 
wrote:
On Saturday, 18 January 2014 at 19:40:38 UTC, Xavier Bigand 
wrote:
I am not sure the issue come really from my code, cause it 
just works fine on ATI cards, I do something Nvidia drivers 
dislike.


I tried to replace GL_LINE_LOOP by triangles, increase buffer 
size, put the GL_ELEMENT_ARRAY_BUFFER buffer type bind right 
before glDrawElements without success.


Crash only append when I fill text mesh before those ones. So 
I need dig more.


From what i saw in your code you are not using Vertex Array 
Objects. I have had similar problems that code ran fine on ATI 
but crashed on nvidia. The problem went away for me when i just 
created and bound a global VAO just after context creation.


Also i would recommend calling glGetError after every call, it 
helps finding errors. Here is a simple trick to do this 
automatically.


static gl
{

  static ref auto opDispatch(string name, Args...)(Args args)
  {
enum glName = gl ~ name[0].toUpper.to!string ~ name[1 .. 
$];


debug scope(exit) checkGLError(); //Do glGetError and log 
it or something.

mixin(return  ~ glName ~ (args););
  }
}


After this simply change all glFunctionName(args) to 
gl.functionName or gl.functionName.


I will try the global VAO.

I already check glError with checkgl! function.


Re: Algorithm remove Tid

2014-01-22 Thread monarch_dodra
On Wednesday, 22 January 2014 at 12:11:22 UTC, Casper Færgemand 
wrote:

import std.algorithm;
import std.concurrency;

void main() {
Tid[] tids = [];
Tid tid = thisTid;
tids ~= tid;
tids.remove(tid);
}

Why does this not compile?


Because remove takes an offset as an argument, not an element.

To remove an element, I *think* you do it this way:

tids = tids.remove!(a=a == tid)();


Re: Algorithm remove Tid

2014-01-22 Thread Casper Færgemand
On Wednesday, 22 January 2014 at 13:16:18 UTC, monarch_dodra 
wrote:
Because remove takes an offset as an argument, not an 
element.


To remove an element, I *think* you do it this way:

tids = tids.remove!(a=a == tid)();


Thanks a lot. I was trying to get that part to work, but I had a 
hard time realizing that = was a lambda and not a =. x.x


Re: Algorithm remove Tid

2014-01-22 Thread bearophile

Casper Færgemand:


To remove an element, I *think* you do it this way:

tids = tids.remove!(a=a == tid)();


is that removing only 0 or 1 items?

Bye,
bearophile


Re: Algorithm remove Tid

2014-01-22 Thread Casper Færgemand

On Wednesday, 22 January 2014 at 13:51:51 UTC, bearophile wrote:

Casper Færgemand:


To remove an element, I *think* you do it this way:

tids = tids.remove!(a=a == tid)();


is that removing only 0 or 1 items?

Bye,
bearophile


It removes all items that match the tid.


Re: Any library with OAuth support?

2014-01-22 Thread Adam D. Ruppe
On Wednesday, 22 January 2014 at 11:14:22 UTC, ilya-stromberg 
wrote:

Do you know any library with OAuth support?


I did one extremely biased toward what I needed to do:

https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff/blob/master/oauth.d

also requires cgi.d and curl.d from my same repo. I believe this 
also uses the free library mhash so you'll need that installed on 
your system too.



The basic way it works is you put the params into an struct. I 
already filled in twitter and some others.


Then to get a token, you can call authorizeStepOne and later, 
authorizeStepTwo. Then use curlOauth with your tokens to do 
requests. At the bottom, there's also some signature checking 
things for doing an OAuth server.



But since it is pretty well tied into my cgi.d and is written 
just for what I needed, it might be a pain to use...


Re: Algorithm remove Tid

2014-01-22 Thread monarch_dodra

On Wednesday, 22 January 2014 at 13:51:51 UTC, bearophile wrote:

Casper Færgemand:


To remove an element, I *think* you do it this way:

tids = tids.remove!(a=a == tid)();


is that removing only 0 or 1 items?

Bye,
bearophile


Maybe you confusing the new style lambda for a greater equal 
operator? I can't make sense of your question any other way.


Re: Any library with OAuth support?

2014-01-22 Thread ilya-stromberg
On Wednesday, 22 January 2014 at 14:54:00 UTC, Adam D. Ruppe 
wrote:
On Wednesday, 22 January 2014 at 11:14:22 UTC, ilya-stromberg 
wrote:

Do you know any library with OAuth support?


I did one extremely biased toward what I needed to do:


Do you have OAuth server implementation?


Re: Any library with OAuth support?

2014-01-22 Thread Adam D. Ruppe
On Wednesday, 22 January 2014 at 15:29:26 UTC, ilya-stromberg 
wrote:

Do you have OAuth server implementation?


Sort of:

https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff/blob/master/oauth.d#L448

I've never really used it, so it is probably buggy, but I'm 
pretty sure it covers the bases.


Again, it uses my cgi.d, but only a few pieces: get current 
complete url, POST array, and authorization header, so probably 
not too hard to rip that out.


The four functions are:

isOAuthRequest /// true iff authorization is OAuth

getApiKeyFromRequest // gets the user-provided api key (use to 
find the shared secret for the app in your database)


getTokenFromRequest // gets the user-provided user token (again, 
get the shared secret, this time for the user)


isSignatureValid // tests the provided signature against the 
other params


Re: Algorithm remove Tid

2014-01-22 Thread bearophile

monarch_dodra:

Maybe you confusing the new style lambda for a greater equal 
operator? I can't make sense of your question any other way.


My point was that the shown code doesn't remove only one item in 
presence of duplicated ones. In this case tid are unique, but in 
general using that code to remove one item is not a good idea.


Bye,
bearophile


Re: Algorithm remove Tid

2014-01-22 Thread monarch_dodra

On Wednesday, 22 January 2014 at 15:41:58 UTC, bearophile wrote:

monarch_dodra:

Maybe you confusing the new style lambda for a greater equal 
operator? I can't make sense of your question any other way.


My point was that the shown code doesn't remove only one item 
in presence of duplicated ones. In this case tid are unique, 
but in general using that code to remove one item is not a good 
idea.


Bye,
bearophile


Ah... I see. Yeah, this will remove *all* items that match the 
TID. I'm not sure that's a problem in this context, but I you did 
want to remove at most 1 item, then this isn't the correct 
solution.


There's no phobos solution for that, but I guess it would be 
written something like:


template removeOne(alias pred, SwapStrategy s = 
SwapStrategy.stable)

{
Range removeOne(Range)(Range range)
{
auto result = range.save;
auto f = find!pred(range);
if (f.empty) return result;

static if (s == SwapStrategy.stable)
{
auto ff = f.save;
f.popFront();
ff.popBack;
for ( ; !f.empty; f.popFront(), ff.popFront())
moveFront(f, ff);
}
else
{
move(find.back, find.front);
}
result.popBack();
return result;
}
}

Disclaimer: Not actually tested. May also horribly fail on 
non-reference ranges.


Re: Algorithm remove Tid

2014-01-22 Thread bearophile

monarch_dodra:


There's no phobos solution for that,


There will be.

In the meantime use:
items = items.remove(items.countUntil(needle));

See also:
https://d.puremagic.com/issues/show_bug.cgi?id=10959

Bye,
bearophile


extern(C) function literals for stubs

2014-01-22 Thread Marco Leise
Can I define them somehow? The use case is defining extern C
functions that contain code to load the real thing from a
library.

  nothrow extern(C) void function(int) someFunc = ???

-- 
Marco



Re: Algorithm remove Tid

2014-01-22 Thread monarch_dodra

On Wednesday, 22 January 2014 at 16:48:45 UTC, bearophile wrote:

monarch_dodra:


There's no phobos solution for that,


There will be.

In the meantime use:
items = items.remove(items.countUntil(needle));


Hum... that requires iterating the range twice for a non-RA 
range. And you forgot a save:


items = items.remove(items.save.countUntil(needle));

But it *is* much simpler.


See also:
https://d.puremagic.com/issues/show_bug.cgi?id=10959


Thx.


Bye,
bearophile




Re: extern(C) function literals for stubs

2014-01-22 Thread bearophile

Marco Leise:


Can I define them somehow? The use case is defining extern C
functions that contain code to load the real thing from a
library.

  nothrow extern(C) void function(int) someFunc = ???


Perhaps you want:

extern(C) nothrow void someFunc(int someArg);

Bye,
bearophile


Re: extern(C) function literals for stubs

2014-01-22 Thread Marco Leise
Am Wed, 22 Jan 2014 17:52:03 +
schrieb bearophile bearophileh...@lycos.com:

 Marco Leise:
 
  Can I define them somehow? The use case is defining extern C
  functions that contain code to load the real thing from a
  library.
 
nothrow extern(C) void function(int) someFunc = ???
 
 Perhaps you want:
 
 extern(C) nothrow void someFunc(int someArg);
 
 Bye,
 bearophile

Thanks, but I want it to be a function pointer so I can swap
it from within the function literal in the fashion of 

  nothrow extern(C) void function(int) someFunc = (int arg) {
  someFunc = GetProcAddress(someFunc);
  someFunc(arg);
  }

-- 
Marco



Re: extern(C) function literals for stubs

2014-01-22 Thread Marco Leise
Am Wed, 22 Jan 2014 17:52:03 +
schrieb bearophile bearophileh...@lycos.com:

 Marco Leise:
 
  Can I define them somehow? The use case is defining extern C
  functions that contain code to load the real thing from a
  library.
 
nothrow extern(C) void function(int) someFunc = ???
 
 Perhaps you want:
 
 extern(C) nothrow void someFunc(int someArg);
 
 Bye,
 bearophile

Got it now. By declaring the literal stub function in a
template instead I can use the normal function declaration
syntax without introducing a new symbol at the definition site:

{
  ...
  nothrow extern(C) void function(int) someFunc = Stub!someFunc;
  ...
}

nothrow extern(C) auto Stub(alias func)(ParameterTypeTuple!func args)
{
debug printf(Loading %s...\n, func.stringof.ptr);
return (func = impl)(args);
}


-- 
Marco



Re: shared methods

2014-01-22 Thread unknown soldier
The compiler does not do this for you, because it can not know 
if accessing any member is truly thread-safe. You might share 
the logFile with other instances of Foo. This would be a case 
where the compiler would wrongly remove the shared from this, 
if it would do so automatically inside synchronized blocks.


Makes sense; thank you!


Re: Why is string.front dchar?

2014-01-22 Thread Timon Gehr

On 01/16/2014 06:56 AM, Jakob Ovrum wrote:


Note that the Unicode definition of an unqualified character is the
translation of a code *point*, which is very different from a *glyph*,
which is what people generally associate the word character with.
Thus, `string` is not an array of characters (i.e. an array where each
element is a character), but `dstring` can be said to be.


A character can be made of more than one dchar. (There are also more 
exotic examples, eg. IIRC there are cases where three dchars make 
approximately two characters.)


Re: Why is string.front dchar?

2014-01-22 Thread Jakob Ovrum

On Thursday, 23 January 2014 at 01:17:19 UTC, Timon Gehr wrote:

On 01/16/2014 06:56 AM, Jakob Ovrum wrote:


Note that the Unicode definition of an unqualified character 
is the
translation of a code *point*, which is very different from a 
*glyph*,
which is what people generally associate the word character 
with.
Thus, `string` is not an array of characters (i.e. an array 
where each

element is a character), but `dstring` can be said to be.


A character can be made of more than one dchar. (There are also 
more exotic examples, eg. IIRC there are cases where three 
dchars make approximately two characters.)


No, I believe you are thinking of graphemes.