Re: HTML Parsing lib

2014-10-26 Thread Suliman via Digitalmars-d-learn

Unfortunately that library has no dub package.
But you can include it in your project.

See info here http://code.dlang.org/package-format


I can't understand how to set in dub that I need to to include in 
compilation process other files... Could you help me?




Re: Generating code based on UDA

2014-10-26 Thread Rares Pop via Digitalmars-d-learn

I have found the problem.
It was the nested mixin that was causing the scope degradation 
(not sure if that is intended behaviour).


The correct way to iterate through members and get their 
attribute is  like this:


foreach(member; __traits(allMembers,T))
{   
enum fullName = format(%s.%s, T.stringof, member);
pragma(msg, member: , fullName);
		foreach(attr; __traits(getAttributes, __traits(getMember, T, 
member)))

{





Re: HTML Parsing lib

2014-10-26 Thread yazd via Digitalmars-d-learn

On Saturday, 25 October 2014 at 19:44:25 UTC, Suliman wrote:

I found only https://github.com/Bystroushaak/DHTMLParser

But I can't get it work:
C:\Users\Dima\Downloads\DHTMLParser-master\DHTMLParser-masterdmd 
find_links.d

OPTLINK (R) for Win32  Release 8.00.15
Copyright (C) Digital Mars 1989-2013  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
find_links.obj(find_links)
 Error 42: Symbol Undefined 
_D11dhtmlparser11parseStringFAyaZC11dhtmlparser11HTM

LElement
find_links.obj(find_links)
 Error 42: Symbol Undefined _D11dhtmlparser12__ModuleInfoZ
--- errorlevel 2

Is there any other HTML parsing lib, or maybe someone do know 
how to get it's work. Look like it's not compatible with 
current version of DMD


You can try https://github.com/bakkdoor/gumbo-d


specializing template with string variable in CTFE

2014-10-26 Thread ketmar via Digitalmars-d-learn
Hello.

the following code is not working:

  template prstr(string s) {
enum prstr = write(~s.stringof~);\n;
  }

  string buildWriter() (string fmt) {
return prstr!(fmt[0..$-1]);
  }

  string writer(string fmt) () {
enum s = buildWriter(fmt);
return s;
  }

  void main () {
import std.stdio;
writeln(writer!str());
  }

  z40.d(6): Error: variable fmt cannot be read at compile time
  z40.d(10): Error: template instance z40.buildWriter!() error instantiating
  z40.d(16):instantiated from here: writer!str

but why? fmt is known in CTFE and compiler can use it as string literal
for instantiating `prstr`.

please, don't mind the idiocity of the code: this is just a sample to
show what confuses me. i know about possibility of moving `fmt` to
template argument, but i need it as function argument, 'cause
`buildWriter()` actually does string processing and i want to
instantiate `prstr` with the part of the string. and this processing
cannot be done in 'foreach'.

and writing everything in functional style sux: it leads to explosive
growing of the number of arguments passed to templates.


signature.asc
Description: PGP signature


Re: specializing template with string variable in CTFE

2014-10-26 Thread via Digitalmars-d-learn
On Sunday, 26 October 2014 at 10:48:46 UTC, ketmar via 
Digitalmars-d-learn wrote:

Hello.

the following code is not working:

  template prstr(string s) {
enum prstr = write(~s.stringof~);\n;
  }

  string buildWriter() (string fmt) {
return prstr!(fmt[0..$-1]);
  }


Your passing the runtime parameter `fmt` as template argument. 
Try this:


string buildWriter(string fmt)() {
  return prstr!(fmt[0..$-1]);
}



  string writer(string fmt) () {
enum s = buildWriter(fmt);


and this:
  enum s = buildWriter!(fmt);


return s;
  }

  void main () {
import std.stdio;
writeln(writer!str());
  }

  z40.d(6): Error: variable fmt cannot be read at compile time
  z40.d(10): Error: template instance z40.buildWriter!() error 
instantiating

  z40.d(16):instantiated from here: writer!str

but why? fmt is known in CTFE and compiler can use it as string 
literal

for instantiating `prstr`.

please, don't mind the idiocity of the code: this is just a 
sample to
show what confuses me. i know about possibility of moving `fmt` 
to

template argument, but i need it as function argument, 'cause
`buildWriter()` actually does string processing and i want to
instantiate `prstr` with the part of the string. and this 
processing

cannot be done in 'foreach'.

and writing everything in functional style sux: it leads to 
explosive

growing of the number of arguments passed to templates.




Re: specializing template with string variable in CTFE

2014-10-26 Thread via Digitalmars-d-learn

On Sunday, 26 October 2014 at 12:27:55 UTC, Marc Schütz wrote:
On Sunday, 26 October 2014 at 10:48:46 UTC, ketmar via 
Digitalmars-d-learn wrote:

Hello.

the following code is not working:

 template prstr(string s) {
   enum prstr = write(~s.stringof~);\n;
 }

 string buildWriter() (string fmt) {
   return prstr!(fmt[0..$-1]);
 }


Your passing the runtime parameter `fmt` as template argument. 
Try this:


string buildWriter(string fmt)() {
  return prstr!(fmt[0..$-1]);
}



 string writer(string fmt) () {
   enum s = buildWriter(fmt);


and this:
  enum s = buildWriter!(fmt);


   return s;
 }

 void main () {
   import std.stdio;
   writeln(writer!str());
 }

 z40.d(6): Error: variable fmt cannot be read at compile time
 z40.d(10): Error: template instance z40.buildWriter!() error 
instantiating

 z40.d(16):instantiated from here: writer!str

but why? fmt is known in CTFE and compiler can use it as 
string literal

for instantiating `prstr`.

please, don't mind the idiocity of the code: this is just a 
sample to
show what confuses me. i know about possibility of moving 
`fmt` to

template argument, but i need it as function argument, 'cause
`buildWriter()` actually does string processing and i want to
instantiate `prstr` with the part of the string. and this 
processing

cannot be done in 'foreach'.

and writing everything in functional style sux: it leads to 
explosive

growing of the number of arguments passed to templates.


Sorry, didn't read the rest of your post before replying :-P


Re: specializing template with string variable in CTFE

2014-10-26 Thread via Digitalmars-d-learn
On Sunday, 26 October 2014 at 10:48:46 UTC, ketmar via 
Digitalmars-d-learn wrote:

Hello.

the following code is not working:

  template prstr(string s) {
enum prstr = write(~s.stringof~);\n;
  }

  string buildWriter() (string fmt) {
return prstr!(fmt[0..$-1]);
  }

  string writer(string fmt) () {
enum s = buildWriter(fmt);
return s;
  }

  void main () {
import std.stdio;
writeln(writer!str());
  }

  z40.d(6): Error: variable fmt cannot be read at compile time
  z40.d(10): Error: template instance z40.buildWriter!() error 
instantiating

  z40.d(16):instantiated from here: writer!str

but why? fmt is known in CTFE and compiler can use it as string 
literal

for instantiating `prstr`.

please, don't mind the idiocity of the code: this is just a 
sample to
show what confuses me. i know about possibility of moving `fmt` 
to

template argument, but i need it as function argument, 'cause
`buildWriter()` actually does string processing and i want to
instantiate `prstr` with the part of the string. and this 
processing

cannot be done in 'foreach'.

and writing everything in functional style sux: it leads to 
explosive

growing of the number of arguments passed to templates.


Ok, I see two possibilities. The first is to make `prstr` into a 
normal function. You cannot use `stringof` then, but need to 
escape the string yourself. Luckily, std.format provides 
functionality for this already, albeit a bit hidden:


private auto escapeStringLiteral(string s) {
import std.format : formatElement, FormatSpec;
import std.range : appender;

auto app = appender!string;
FormatSpec!char f;
formatElement(app, s, f);

return app.data;
}

The second possibility doesn't exist right now. The core problem 
is that the compiler needs to be able to generate runtime code 
for `buildWriter()`, because it's just a function after all. But 
there have been calls for compile-time only functions, or 
something along the lines of `static if(__ctfe)` (which doesn't 
work currently and was recently made an error). In this case, 
there might be a chance to allow what you want.


Re: Pragma mangle and D shared objects

2014-10-26 Thread Etienne Cimon via Digitalmars-d-learn

On 2014-10-25 23:31, H. S. Teoh via Digitalmars-d-learn wrote:

Hmm. You can probably use __traits(getAllMembers...) to introspect a
library module at compile-time and build a hash based on that, so that
it's completely automated. If you have this available as a mixin, you
could just mixin(exportLibrarySymbols()) in your module to produce the
hash.


Exactly, or I could also make it export specific functions into the 
hashmap, a little like a router. It seems like a very decent option.




Re: specializing template with string variable in CTFE

2014-10-26 Thread ketmar via Digitalmars-d-learn
On Sun, 26 Oct 2014 12:46:06 +
via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote:

 The second possibility doesn't exist right now. The core problem 
 is that the compiler needs to be able to generate runtime code 
 for `buildWriter()`, because it's just a function after all.
but it's templated function, and it's never called in runtime, so
compiler never needs to generate code for it. seems that semantic
analysis prohibits such code before CTFE, and semantic analyser is
completely wrong here, 'case `fmt` *can* be read in compile-time.

actually, semantic analiser is wrong for any CTFE-able function in this
case, and it emits completely wrong error message (compile time
variable can't be read in compile time? how this can be true?).

i understand that it can be hard to fix semantic analyser though. ah,
but this limitation is so... limiting!

not sure if it worth the ER though. people seems to not write alot of
complex CTFE code anyway.


signature.asc
Description: PGP signature


Re: specializing template with string variable in CTFE

2014-10-26 Thread ketmar via Digitalmars-d-learn
On Sun, 26 Oct 2014 12:46:06 +
via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote:

 Ok, I see two possibilities. The first is to make `prstr` into a 
 normal function. You cannot use `stringof` then, but need to 
 escape the string yourself. Luckily, std.format provides 
 functionality for this already, albeit a bit hidden:
 
  private auto escapeStringLiteral(string s) {
  import std.format : formatElement, FormatSpec;
  import std.range : appender;
 
  auto app = appender!string;
  FormatSpec!char f;
  formatElement(app, s, f);
 
  return app.data;
  }
thank you, this is very handy. yet my desire to instantiate template
with compile-time variable still remains. ;-)


signature.asc
Description: PGP signature


Re: specializing template with string variable in CTFE

2014-10-26 Thread via Digitalmars-d-learn
On Sunday, 26 October 2014 at 19:32:28 UTC, ketmar via 
Digitalmars-d-learn wrote:

On Sun, 26 Oct 2014 12:46:06 +
via Digitalmars-d-learn digitalmars-d-learn@puremagic.com 
wrote:


The second possibility doesn't exist right now. The core 
problem is that the compiler needs to be able to generate 
runtime code for `buildWriter()`, because it's just a function 
after all.
but it's templated function, and it's never called in runtime, 
so

compiler never needs to generate code for it.


The documentation specifically says that:
Any functions that execute at compile time must also be 
executable at run time. [...] This means that the semantics of a 
function cannot depend on compile time values of the function.


http://dlang.org/function.html

I can imagine it would be difficult to implement it differently, 
because in effect the compiler would need to create a new 
instance of the function for every call, with each instance 
potentially being completely different (consider `static if` over 
CTFE runtime parameters).


Re: specializing template with string variable in CTFE

2014-10-26 Thread ketmar via Digitalmars-d-learn
On Sun, 26 Oct 2014 20:16:18 +
via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote:

 The documentation specifically says that:
 Any functions that execute at compile time must also be 
 executable at run time. [...] This means that the semantics of a 
 function cannot depend on compile time values of the function.
 
 http://dlang.org/function.html
 
 I can imagine it would be difficult to implement it differently, 
 because in effect the compiler would need to create a new 
 instance of the function for every call, with each instance 
 potentially being completely different (consider `static if` over 
 CTFE runtime parameters).
leaving away technical complexities for compiler writers, i like to say
that restrictions for templated functions can be relaxed. maybe by
marking some templates/functions as CTFE-only. or just fix semantic
analyser to allow some more things in CTFE. such template will never
instantiates successfully for run-time code, and it still can be used
in metaprogramming.

writing purely functional templates really sux. i made a simple
writef-like module which parses it's format string in compile time and
i must admit that some templates has 10+ arguments and keep growing as
i adding features. either this, or even more convoluted hacks.

alas, i'm still don't understand compiler code deep enough to see how
hard this will be to implement.


signature.asc
Description: PGP signature


Re: Reflections on isPalindrome

2014-10-26 Thread Nordlöw

On Friday, 24 October 2014 at 22:29:12 UTC, Peter Alexander wrote:
Further, I would like to extend isPalindrome() with a minimum 
length argument minLength that for string and wstring does


I extended my algorithm with a minLength argument 
https://github.com/nordlow/justd/blob/master/algorithm_ex.d#L774


Problems with Mutex

2014-10-26 Thread Neven via Digitalmars-d-learn
I'm trying to use Mutex from core.sync.mutex; but when I try to 
initialize it at compile time this error pops up:


Error: constructor core.sync.mutex.Mutex.this 
core.sync.mutex.Mutex cannot be constructed at compile time, 
because the constructor has no available source code


So I try to initialize it at run time but whenever I use that 
mutex in code (via synchronized blocks) I get segmetation faults 
(SIGSEGV).


Code here: http://pastebin.com/Z8Yj2kwY


Re: Problems with Mutex

2014-10-26 Thread Damian via Digitalmars-d-learn

On Sunday, 26 October 2014 at 22:14:25 UTC, Neven wrote:
I'm trying to use Mutex from core.sync.mutex; but when I try to 
initialize it at compile time this error pops up:


Error: constructor core.sync.mutex.Mutex.this 
core.sync.mutex.Mutex cannot be constructed at compile time, 
because the constructor has no available source code


So I try to initialize it at run time but whenever I use that 
mutex in code (via synchronized blocks) I get segmetation 
faults (SIGSEGV).


Code here: http://pastebin.com/Z8Yj2kwY


Try
__gshared Mutex mutex;


Re: Problems with Mutex

2014-10-26 Thread Neven via Digitalmars-d-learn

On Sunday, 26 October 2014 at 22:21:17 UTC, Damian wrote:

On Sunday, 26 October 2014 at 22:14:25 UTC, Neven wrote:
I'm trying to use Mutex from core.sync.mutex; but when I try 
to initialize it at compile time this error pops up:


Error: constructor core.sync.mutex.Mutex.this 
core.sync.mutex.Mutex cannot be constructed at compile time, 
because the constructor has no available source code


So I try to initialize it at run time but whenever I use that 
mutex in code (via synchronized blocks) I get segmetation 
faults (SIGSEGV).


Code here: http://pastebin.com/Z8Yj2kwY


Try
__gshared Mutex mutex;


Thanks, that works now; but why?

Why cannot I globally have auto mutex = new Mutex? And why it 
works now when I put __gshared?


Re: Problems with Mutex

2014-10-26 Thread Damian via Digitalmars-d-learn

On Sunday, 26 October 2014 at 22:53:09 UTC, Neven wrote:

On Sunday, 26 October 2014 at 22:21:17 UTC, Damian wrote:

On Sunday, 26 October 2014 at 22:14:25 UTC, Neven wrote:
I'm trying to use Mutex from core.sync.mutex; but when I try 
to initialize it at compile time this error pops up:


Error: constructor core.sync.mutex.Mutex.this 
core.sync.mutex.Mutex cannot be constructed at compile time, 
because the constructor has no available source code


So I try to initialize it at run time but whenever I use that 
mutex in code (via synchronized blocks) I get segmetation 
faults (SIGSEGV).


Code here: http://pastebin.com/Z8Yj2kwY


Try
__gshared Mutex mutex;


Thanks, that works now; but why?

Why cannot I globally have auto mutex = new Mutex? And why it 
works now when I put __gshared?


You can use auto mutex = cast(shared)(new Mutex());


Re: Problems with Mutex

2014-10-26 Thread Damian via Digitalmars-d-learn

On Sunday, 26 October 2014 at 22:53:09 UTC, Neven wrote:

On Sunday, 26 October 2014 at 22:21:17 UTC, Damian wrote:

On Sunday, 26 October 2014 at 22:14:25 UTC, Neven wrote:
I'm trying to use Mutex from core.sync.mutex; but when I try 
to initialize it at compile time this error pops up:


Error: constructor core.sync.mutex.Mutex.this 
core.sync.mutex.Mutex cannot be constructed at compile time, 
because the constructor has no available source code


So I try to initialize it at run time but whenever I use that 
mutex in code (via synchronized blocks) I get segmetation 
faults (SIGSEGV).


Code here: http://pastebin.com/Z8Yj2kwY


Try
__gshared Mutex mutex;


Thanks, that works now; but why?

Why cannot I globally have auto mutex = new Mutex? And why it 
works now when I put __gshared?


Globally you can use:

Mutex mutex;

static this()
{
  mutex = new Mutex();
}


Re: Problems with Mutex

2014-10-26 Thread ketmar via Digitalmars-d-learn
On Sun, 26 Oct 2014 22:53:07 +
Neven via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote:

 Why cannot I globally have auto mutex = new Mutex? And why it 
 works now when I put __gshared?
this is because 'auto mutex = new Mutex' is not a global declaration,
it's thread-local declaration. all D variables are thread-locals by
default.

i.e. you have one indepented Mutex for each thread. and you initialized
it only in one thread, all other threads got unitialized Mutex objects.

having thread-locals instead of globals by default can be confusing if
you missed that in documentation. just use 'shared' or '__gshared' to
get real globals.


signature.asc
Description: PGP signature


Re: Problems with Mutex

2014-10-26 Thread Neven via Digitalmars-d-learn

@Damian

You can use auto mutex = cast(shared)(new Mutex());


Not working;  Error: constructor core.sync.mutex.Mutex.this 
core.sync.mutex.Mutex cannot be constructed at compile time, 
because the constructor has no available source code



Mutex mutex;
static this()
{
 mutex = new Mutex();
}


I have synchronization problems with this one. Even when I 
prepend __gshared Mutex mutex in this case.


Changed code: http://pastebin.com/KmxCemn3
Output: http://pastebin.com/zFFLnCTD
As you can see beginning is not what I expect to get.

@ketmar
having thread-locals instead of globals by default can be 
confusing if
you missed that in documentation. just use 'shared' or 
'__gshared' to

get real globals.

Thank you for clearing this up. If I understand correctly, 
__gshared is more of a hack to get C-like global variables, 
whilst shared is typed shared variable and more preferred?


forum.dlang.org open source?

2014-10-26 Thread Mike via Digitalmars-d-learn
Does forum.dlang.org have an open source repository somewhere 
that we can contribute pull requests to, or are bug reports to 
recommended procedure.


I see that the left navigation menu needs updating, and I think 
we can wordsmith the forum descriptions a little to make it 
clearer where to post things.


Some other nice features like backtick(`) markup and the ability 
to collapse/expand threads are also on my mind at the moment.


Thanks for the support,

Mike


Re: Problems with Mutex

2014-10-26 Thread ketmar via Digitalmars-d-learn
On Sun, 26 Oct 2014 23:37:25 +
Neven via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote:

 Mutex mutex;
 static this()
 {
   mutex = new Mutex();
 }
 
 I have synchronization problems with this one. Even when I 
 prepend __gshared Mutex mutex in this case.
ah, there is another subtle thing. 'static this()' will be called for
each new thread, so what you actually doing is creating new mutex
object when each thread started. it's the same thing as with globals vs
thread-locals. what you really want in this case is 'global
initializer', which will be called once on program startup. to achieve
this you have to write:

  shared static this () {
mutex = new Mutex();
  }

'shared static this()' will be called only once.

 Thank you for clearing this up. If I understand correctly, 
 __gshared is more of a hack to get C-like global variables, 
 whilst shared is typed shared variable and more preferred?
yes and no. 'shared' is the part of the type, while '__gshared' is not.
i.e.

  shared int a;
  pragma(msg, typeof(a)); // this will print shared(int)

  __gshared int b;
  pragma(msg, typeof(b)); // this will print int

you can't freely mix shared and non-shared types, so you must cast
'shared' away on occasion and cast it back when necessary. this is not
safe and error-prone.

'__gshared', for the other side, doesn't influence the type, so you can
have global variable which can be passed to other functions without
casting.

but yes, generally this is a hack, and you'd better avoid '__gshared'
in idiomatic D code unless you are really really know what you are
doing and what consequences it may have. ;-)


signature.asc
Description: PGP signature


Re: forum.dlang.org open source?

2014-10-26 Thread anonymous via Digitalmars-d-learn

On Sunday, 26 October 2014 at 23:57:41 UTC, Mike wrote:
Does forum.dlang.org have an open source repository somewhere 
that we can contribute pull requests to, or are bug reports to 
recommended procedure.


http://forum.dlang.org/help#contributing


Re: Problems with Mutex

2014-10-26 Thread ketmar via Digitalmars-d-learn
On Mon, 27 Oct 2014 02:07:09 +0200
ketmar via Digitalmars-d-learn digitalmars-d-learn@puremagic.com
wrote:

  Thank you for clearing this up. If I understand correctly, 
  __gshared is more of a hack to get C-like global variables, 
  whilst shared is typed shared variable and more preferred?
 yes and no. 'shared' is the part of the type, while '__gshared' is
 not. i.e.
 
   shared int a;
   pragma(msg, typeof(a)); // this will print shared(int)
 
   __gshared int b;
   pragma(msg, typeof(b)); // this will print int
 
 you can't freely mix shared and non-shared types, so you must cast
 'shared' away on occasion and cast it back when necessary. this is not
 safe and error-prone.
 
 '__gshared', for the other side, doesn't influence the type, so you
 can have global variable which can be passed to other functions
 without casting.
 
 but yes, generally this is a hack, and you'd better avoid '__gshared'
 in idiomatic D code unless you are really really know what you are
 doing and what consequences it may have. ;-)
here is some silly code to show you some difference between 'shared'
and '__gshared':

  void foo (ref int i) {}

  int a;
  shared int b;
  __gshared int c;

  void main () {
foo(a); // this compiles
foo(b); // this will not compile (see below)
foo(c); // this compiles too
  }

`foo(b);` will not compile, compiler emits error:
Error: function y01.foo (ref int i) is not callable using argument
types (shared(int))

if you'll change `foo` to `void foo (ref shared int i) {}`, you'll get
the opposite: `foo(a)` and `foo(c)` will be refused by compiler.


signature.asc
Description: PGP signature


passing non-dynamic arrays to variadic functions

2014-10-26 Thread ketmar via Digitalmars-d-learn
Hello.

let's assume we have this code:

  void doWrite(A...) (A args) {
import std.stdio;
import std.conv;
writeln(to!string(args[0]));
  }

  void main () {
char[3] a0 = abc;
char[3] a1 = ['a', 'b', 'c'];
doWrite(a0);
doWrite(a1);
  }

i don't know why, but this code prints complete garbage each time i run
it. yet if i'll change `doWrite()` invocations to this:

doWrite(a0[]);
doWrite(a1[]);

everything is working fine.

am i doing something wrong in the first sample and missed the relevat
part of documentation, or this is a bug? and do we have workaround for
this?


signature.asc
Description: PGP signature


Re: passing non-dynamic arrays to variadic functions

2014-10-26 Thread ketmar via Digitalmars-d-learn
On Mon, 27 Oct 2014 02:25:50 +0200
ketmar via Digitalmars-d-learn digitalmars-d-learn@puremagic.com
wrote:

p.s. i know how to block using non-dynamic arrays in this case, but i
don't want to. i found this when writing writef-like function with CTFE
parsing of formatting string and spent alot of time looking for bug in
my code. ;-)


signature.asc
Description: PGP signature


Re: passing non-dynamic arrays to variadic functions

2014-10-26 Thread anonymous via Digitalmars-d-learn

On Monday, 27 October 2014 at 00:26:00 UTC, ketmar via
Digitalmars-d-learn wrote:

Hello.

let's assume we have this code:

  void doWrite(A...) (A args) {
import std.stdio;
import std.conv;
writeln(to!string(args[0]));
  }

  void main () {
char[3] a0 = abc;
char[3] a1 = ['a', 'b', 'c'];
doWrite(a0);
doWrite(a1);
  }

i don't know why, but this code prints complete garbage each 
time i run


Prints
abc
abc
for me.


Re: passing non-dynamic arrays to variadic functions

2014-10-26 Thread ketmar via Digitalmars-d-learn
On Mon, 27 Oct 2014 00:33:13 +
anonymous via Digitalmars-d-learn digitalmars-d-learn@puremagic.com
wrote:

 On Monday, 27 October 2014 at 00:26:00 UTC, ketmar via
 Digitalmars-d-learn wrote:
  Hello.
 
  let's assume we have this code:
 
void doWrite(A...) (A args) {
  import std.stdio;
  import std.conv;
  writeln(to!string(args[0]));
}
 
void main () {
  char[3] a0 = abc;
  char[3] a1 = ['a', 'b', 'c'];
  doWrite(a0);
  doWrite(a1);
}
 
  i don't know why, but this code prints complete garbage each 
  time i run
 
 Prints
 abc
 abc
 for me.
ah, i forgot to specify my system:
GNU/Linux, x86, DMD git head. could you please test this with current
git?

it seems to work with GDC, which is 2.065 for now. seems that this is a
regression.


signature.asc
Description: PGP signature


Re: passing non-dynamic arrays to variadic functions

2014-10-26 Thread Ali Çehreli via Digitalmars-d-learn

On 10/26/2014 05:33 PM, anonymous wrote:

On Monday, 27 October 2014 at 00:26:00 UTC, ketmar via
Digitalmars-d-learn wrote:

Hello.

let's assume we have this code:

  void doWrite(A...) (A args) {
import std.stdio;
import std.conv;
writeln(to!string(args[0]));
  }

  void main () {
char[3] a0 = abc;
char[3] a1 = ['a', 'b', 'c'];
doWrite(a0);
doWrite(a1);
  }

i don't know why, but this code prints complete garbage each time i run


Prints
abc
abc
for me.


Yeah, works with git head.

Ali



Re: passing non-dynamic arrays to variadic functions

2014-10-26 Thread ketmar via Digitalmars-d-learn
On Sun, 26 Oct 2014 17:41:28 -0700
Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn@puremagic.com
wrote:

 Yeah, works with git head.
ah, thank you. seems that one of the custom patches i'm using broke
that. i just checked this on unpatched DMD, and it works too.

sorry for the noise.


signature.asc
Description: PGP signature


Re: passing non-dynamic arrays to variadic functions

2014-10-26 Thread MachineCode via Digitalmars-d-learn
On Monday, 27 October 2014 at 00:26:00 UTC, ketmar via 
Digitalmars-d-learn wrote:

Hello.

let's assume we have this code:

  void doWrite(A...) (A args) {
import std.stdio;
import std.conv;
writeln(to!string(args[0]));
  }

  void main () {
char[3] a0 = abc;
char[3] a1 = ['a', 'b', 'c'];
doWrite(a0);
doWrite(a1);
  }

i don't know why, but this code prints complete garbage each 
time i


run

it. yet if i'll change `doWrite()` invocations to this:

doWrite(a0[]);
doWrite(a1[]);

everything is working fine.

am i doing something wrong in the first sample and missed the 
relevat
part of documentation, or this is a bug? and do we have 
workaround for

this?


It worked fine for me. Output:


abc
abc


Environment: Win 8.1 64-bit (but dmd target is 32-bit, IIRC), dmd 
v2.066.0


Re: forum.dlang.org open source?

2014-10-26 Thread MachineCode via Digitalmars-d-learn

On Sunday, 26 October 2014 at 23:57:41 UTC, Mike wrote:
Does forum.dlang.org have an open source repository somewhere 
that we can contribute pull requests to, or are bug reports to 
recommended procedure.


I see that the left navigation menu needs updating, and I think 
we can wordsmith the forum descriptions a little to make it 
clearer where to post things.


Some other nice features like backtick(`) markup and the 
ability to collapse/expand threads are also on my mind at the 
moment.


Thanks for the support,

Mike


Are you going to use HTML in the posts? because neither Walter 
and probably forum maintainer wants to use it.


Re: passing non-dynamic arrays to variadic functions

2014-10-26 Thread ketmar via Digitalmars-d-learn
On Mon, 27 Oct 2014 02:19:49 +
MachineCode via Digitalmars-d-learn digitalmars-d-learn@puremagic.com
wrote:

 It worked fine for me. Output:
 
  abc
  abc
 
 Environment: Win 8.1 64-bit (but dmd target is 32-bit, IIRC), dmd 
 v2.066.0
yes, thank you too. that was one of my custom patches that broke this.
i already found that patch, and it's not even mine! ;-)


signature.asc
Description: PGP signature


Re: Where is a variable declared in a module allocated?

2014-10-26 Thread MachineCode via Digitalmars-d-learn

On Saturday, 25 October 2014 at 22:16:12 UTC, John Colvin wrote:

On Saturday, 25 October 2014 at 21:52:13 UTC, MachineCode wrote:
Where is a variable declared in a module allocated? is it same 
as a C's global?


for example:

module foo;
int myvar;


that is in thread local storage.

__shared, shared or immutable cause the variable to be in 
classic global storage like in C.


See: http://dlang.org/migrate-to-shared.html



Thank you guy. :) I need to learn to use that forum search.


Re: passing non-dynamic arrays to variadic functions

2014-10-26 Thread ketmar via Digitalmars-d-learn
On Mon, 27 Oct 2014 02:25:50 +0200
ketmar via Digitalmars-d-learn digitalmars-d-learn@puremagic.com
wrote:

for those who interested here is the patch that broke everything:
https://github.com/D-Programming-Language/dmd/pull/3806/

i simply forgot that i included it for testing purposes, and it breaks
something inside Phobos.


signature.asc
Description: PGP signature


Re: forum.dlang.org open source?

2014-10-26 Thread Mike via Digitalmars-d-learn

On Monday, 27 October 2014 at 02:24:04 UTC, MachineCode wrote:

On Sunday, 26 October 2014 at 23:57:41 UTC, Mike wrote:

Are you going to use HTML in the posts? because neither Walter 
and probably forum maintainer wants to use it.


I don't plan on adding HTML to the posts.  And you don't need to 
worry about my ideas ruining anything because they have to pass 
the scrutiny of the repository owner and the D community at large 
before they will be accepted.


Re: passing non-dynamic arrays to variadic functions

2014-10-26 Thread MachineCode via Digitalmars-d-learn
On Monday, 27 October 2014 at 02:27:32 UTC, ketmar via 
Digitalmars-d-learn wrote:

On Mon, 27 Oct 2014 02:19:49 +
MachineCode via Digitalmars-d-learn 
digitalmars-d-learn@puremagic.com

wrote:


It worked fine for me. Output:

 abc
 abc

Environment: Win 8.1 64-bit (but dmd target is 32-bit, IIRC), 
dmd v2.066.0
yes, thank you too. that was one of my custom patches that 
broke this.

i already found that patch, and it's not even mine! ;-)


You're welcome :) what do you call git head is the dmd compiler 
compiled from dmd's source code on github?


Re: passing non-dynamic arrays to variadic functions

2014-10-26 Thread ketmar via Digitalmars-d-learn
On Mon, 27 Oct 2014 03:07:12 +
MachineCode via Digitalmars-d-learn digitalmars-d-learn@puremagic.com
wrote:

 You're welcome :) what do you call git head is the dmd compiler 
 compiled from dmd's source code on github?
yes. i'm updating my compiler on dayly basis, so my git head is
really head. ;-)

but i also have alot of custom patches applied to it (some
not-yet-accepted PRs, my internal patches that will never made into
mainline and so on). usually i'm trying to reproduce the bug with
vanilla DMD, but this time i was so sure that it's in vanilla too
that i didn't bother to check. my bad.


signature.asc
Description: PGP signature