Re: utils.toBulkString is not accesible from utils

2015-12-02 Thread Andre via Digitalmars-d-learn

On Wednesday, 2 December 2015 at 12:37:29 UTC, Marc Schütz wrote:



I think so, yes. But according to digger, the current behaviour 
goes back to at least DMD 2.052. Please file a bug report 
anyway.


Bug report filed
https://issues.dlang.org/show_bug.cgi?id=15395


Re: DDOC adds emphasis on symbols, so how to use $(LINK a) properly?

2015-12-02 Thread kraybit via Digitalmars-d-learn

Just wanna follow up.


Thanks for the replies everyone. Helped a lot!


***


Hmm, this might be out of line, but I can't help myself. I got an 
idea. I guess a nice feature would be something like a built-in 
clean representation of macro arguments, so that you could define 
LINK as



LINK = $0


Or perhaps an immutable built-in macro?


LINK = $0


And then it would always work? I mean it seems most macros 
generate HTML, and then anything is fine really. But there are 
those special cases when you're generating something other than 
HTML, such as an URL, or even JavaScript-code, and you really 
need to get rid of all "cleverness".


I've understood you always end posts like this with:
Destroy!

So there, I did it :)
Cheers!


gdc-4.4 on sparc64 debian linux?

2015-12-02 Thread Ish via Digitalmars-d-learn

Where can I find help on this?

-ish


demangle()

2015-12-02 Thread Andrew via Digitalmars-d-learn
When I run the DMD profile, the "overview" at the end of the 
trace.log contains some mangles names (such as:


_D3std5stdio4File17LockingTextWriter12__T3putTAyaZ3putMFAyaZ13trustedFwriteFNbNiNexPvmmPOS4core4stdc5stdio7__sFILEZm

When I call demangle() on those mangled names it returns the 
mangled name, presumably because it can't detangle the name 
(according to the spec).


How do I get the demangled name?  Why can't it demangle?  What is 
the consequence to my program of its inability to demangle (is it 
a many to 1?)?


Thanks



Re: Struct initializers as expressions

2015-12-02 Thread Mike Parker via Digitalmars-d-learn

On Thursday, 3 December 2015 at 05:26:17 UTC, Chris Wright wrote:

I can initialize a struct with named values:

---
struct Foo {
  int i, j, k, l, m, n;
}
Foo f = {k: 12};  // other fields get default initialization
---

I can initialize it with call syntax:

---
auto f = Foo(0, 0, 12, 0, 0, 0);  // works
---


The bottom syntax is a struct literal, the top one is not.




Ideally, I want something that lets you specify only the fields 
you care about and won't have to be modified (just recompiled) 
if I add more fields. I also want something inline.


Is there anything I can use here that's better than what I have?


AFAIK, your only option is to use a struct constructor. This is 
the sort of thing they're  used for.




Struct initializers as expressions

2015-12-02 Thread Chris Wright via Digitalmars-d-learn
I can initialize a struct with named values:

---
struct Foo {
  int i, j, k, l, m, n;
}
Foo f = {k: 12};  // other fields get default initialization
---

I can initialize it with call syntax:

---
auto f = Foo(0, 0, 12, 0, 0, 0);  // works
---

I can use the latter as an expression:

---
void bar(Foo f) {}
bar(Foo(0, 0, 12, 0, 0, 0));  // just peachy
---

but not the latter:

---
void bar(Foo f) {}
bar({k: 12});
bar(Foo{k: 12});
---

Those both give:
Error: found '{' when expecting ','
Error: found ':' when expecting ','
Error: found '}' when expecting ','

This is slightly cruddy. I wanted to write

couchdb.queryView("byUsername", {key: "neia"});

But it looks like I have to use:

QueryOptions o = {key: "neia"};
couchdb.queryView("byUsername", o);

Not so good.

Ideally, I want something that lets you specify only the fields you care 
about and won't have to be modified (just recompiled) if I add more 
fields. I also want something inline.

Is there anything I can use here that's better than what I have?


Re: Can't understand how to do server response with vibed

2015-12-02 Thread Jack Applegame via Digitalmars-d-learn

On Saturday, 28 November 2015 at 18:03:13 UTC, Suliman wrote:
Could anybody help me to understand how to complete HTTP 
response with vibed.


I am sending POST request from AngularJS:

$.post("http://127.0.0.1:8080/my;, total_result);
where total_result is JSON string: [{"QID":3,"AID":3}, 
{"SubAID":[4]}, {"MinArea":"10","MaxArea":"90"}]


Handler is look like:

void action(HTTPServerRequest req, HTTPServerResponse res)
{
   // res.statusCode = 201;
}

I know that I can set statusCode like code above, but problem 
that in Chrome console I am getting:

POST http://127.0.0.1:8080/my 404 (Not Found)
How can I pass to it (from vibed to browser) status code?
If you do not send any response in handler, vibe.d will try to 
match next route (if any). So you should send any response (empty 
string for example).


void action(HTTPServerRequest req, HTTPServerResponse res)
{
res.statusCode = 201;
res.writeBody("");
}



Re: utils.toBulkString is not accesible from utils

2015-12-02 Thread Marc Schütz via Digitalmars-d-learn

On Wednesday, 2 December 2015 at 06:33:36 UTC, Andre wrote:

Hi,

for following coding there is an error during compilation:

  module utils;

  package string toBulkString(string s)
  {
  import std.string: format;
  return "$%s\r\n%s\r\n".format(s.length, s);
  }

  unittest
  {
  string actual = "foobar".toBulkString();
  //...
  }

source\utils.d(11,39): Error: function utils.toBulkString is 
not accessible from module utils


The error disappears if I change the visibility attribute from 
package to private.

This seems to be a bug, is it?

Version: DMD v2.069.0-b2


I think so, yes. But according to digger, the current behaviour 
goes back to at least DMD 2.052. Please file a bug report anyway.


issue importing std.file or std.stdio on win x64 build.

2015-12-02 Thread Jonathan Villa via Digitalmars-d-learn

Hello,

I've been trying to program and app that writes its own log, so, 
to deal with files I tried using std.file. But with just adding 
the import std.file; it throws me (AFAIK) a link error:


(some texts are in spanish, I tried to translate the important 
thing)

Building Release\ASI.exe...
libucrt.lib(fgetc.obj) : error LNK2005: already defined 
_fgetc_nolock in phobos64.lib(stdio_374_54d.obj)
phobos64.lib(stdio_374_54d.obj) : error LNK2019: extern symbol 
_filbuf [unresolved referred in the function] _fgetc_nolock

Release\ASI.exe : fatal error LNK1120: 1 externos sin resolver
Building Release\ASI.exe failed!

This only happens with x64 build, in x86 works fine, but I want 
to stick with x64 as much as possible. So I did some research to 
get some kind of alternative and I found that std.stdio has a 
File class to work with, I implemented it, but now throws me the 
following:


(some texts are in spanish, I tried to translate the important 
thing)

Building Release\ASI.exe...
phobos64.lib(stdio_373_566.obj) : error LNK2019: extern symbol 
_flsbuf [unresolved referred in the function] _fputc_nolock

Release\ASI.exe : fatal error LNK1120: 1 externos sin resolver
Building Release\ASI.exe failed!

I did some research again, and the _flsbuf function is in:
https://github.com/D-Programming-Language/druntime/blob/6f6ec7f4706b128bffaefe9145bec9581e2e7d39/src/rt/msvc.c
at line 94.

_fgetc_nolock is in msvc.c (druntime) and std/stdio.d as well 
(phobos lib).


What can I do to resolve this issue? Using std.stdio looks like 
it should be easier to resolve, BUT in the future I want to 
implement some file/directory management and std.file can do that 
job, so advices to get rid of the first problem would be my first 
priority.


I'm using VisualD 0.3.43 on Visual Studio Community 2015.
Any kind of advice will be appreciated.
Thanks.


mutex usage problem?

2015-12-02 Thread Ish via Digitalmars-d-learn
The following code does core dump (compiled with gdc). Pointers 
will be appreciated.

import std.stdio;
import std.conv;
import std.math;
import std.concurrency;
import core.thread;
import core.sync.mutex;

enum count = 5;
__gshared double rslt = 0.0;
__gshared Mutex mutex;

void term(immutable(int)* nterm) {
double r;
auto n = to!double(*nterm);
r = 4.0*pow(-1.0, *nterm)/(2.0*n + 1);
writefln("%s: %6.6f.", *nterm, r);
mutex.lock();
   rslt = rslt + r;
mutex.unlock();
}


void main() {

foreach (i; 0 .. count) {
int* jm = new int;
*jm = i;
immutable int *j = cast(immutable) jm;
Tid tid = spawn(, j);
}

thread_joinAll();
writefln("Result: %6.9f.", rslt);
}

-ish


Re: mutex usage problem?

2015-12-02 Thread Alex Parrill via Digitalmars-d-learn

On Wednesday, 2 December 2015 at 13:55:02 UTC, Ish wrote:
The following code does core dump (compiled with gdc). Pointers 
will be appreciated.

import std.stdio;
import std.conv;
import std.math;
import std.concurrency;
import core.thread;
import core.sync.mutex;

enum count = 5;
__gshared double rslt = 0.0;
__gshared Mutex mutex;

void term(immutable(int)* nterm) {
double r;
auto n = to!double(*nterm);
r = 4.0*pow(-1.0, *nterm)/(2.0*n + 1);
writefln("%s: %6.6f.", *nterm, r);
mutex.lock();
   rslt = rslt + r;
mutex.unlock();
}


void main() {

foreach (i; 0 .. count) {
int* jm = new int;
*jm = i;
immutable int *j = cast(immutable) jm;
Tid tid = spawn(, j);
}

thread_joinAll();
writefln("Result: %6.9f.", rslt);
}

-ish


You never initialize Mutex, so it is a null pointer when you call 
`mutex.lock`.


Also, no point in passing a pointer here; just pass `i` instead 
of `j`.