Re: Wrapping C code?

2014-03-29 Thread CJS
Well, you can write one. You can also let D generate that list: __traits(allMembers, some_c_module) gives you all symbols in some_c_module. Iterate over them, generate alias declarations, mix those declarations in. I don't understand how that is possible. The C code I have available is a comp

Re: Wrapping C code?

2014-03-29 Thread CJS
On Saturday, 29 March 2014 at 19:16:34 UTC, bearophile wrote: alias context = action; Sorry, I meant: alias action = action; Bye, bearophile When you say define them in bulk at compile time, is there some convenient way to just give an array of actions and iterate over them to gen

Wrapping C code?

2014-03-29 Thread CJS
I've been using a medium-sized C library. Most of the library calls look something like action(context, arg1, arg2) Where is the name of the library, action is the action to take, and context is an opaque pointer defined by the library to keep all the state related to these actions.

Re: Python calling D

2014-01-19 Thread CJS
Sorry to be late coming to this. It would great to be able to push D as a CPython extension language. However the state of pyd.dsource.org and places reached from it do make it seem that the project died in 2009. ariovistus' GitHub project on Bitbucket is moving but everything else appears

Re: Better idea for double list comprehension?

2014-01-19 Thread CJS
That's std.array.join() there. However, I notice that the output (the order of elements) differs from the one on that page you linked earlier. The order shouldn't be a problem. Join is a great idea. I'd thought it was only for an array of strings. Thanks for all the help!

Re: Better idea for double list comprehension?

2014-01-19 Thread CJS
Thanks! auto app = appender(&unitlist); Ah, I'd been wondering if there was something like this. But why does it need unitlist's address? (Assume & has the same meaning as in C and C++.) This one seems like it should be unitlist.filter!(x => x.any!(y => s==y)).array(); Oh. D

Re: Better idea for double list comprehension?

2014-01-19 Thread CJS
to!string(c) ===> c.text That's more concise but I also think it's more confusing. I assume that to!string is doing the exact same thing, but I was hoping for something to do the appropriate implicit conversations. Especially to a range of length 1, though I can understand that kind of

Re: Better idea for double list comprehension?

2014-01-19 Thread CJS
import std.stdio, std.conv, std.algorithm, std.array; string[] cross(in string A, in string B) { return cartesianProduct(A, B).map!(ab => ab[].text).array; } void main() { cross("ab", "12").writeln; } But note that currently cartesianProduct doesn't return the pairs in a natural orde

Re: Better idea for double list comprehension?

2014-01-19 Thread CJS
#x27;m not sure that's the case here. On Saturday, 18 January 2014 at 05:40:56 UTC, CJS wrote: I'm trying to write a D function that does the same as this Python function: def cross(A, B): "Cross product of elements in A and elements in B." return [a+b for a in A

Better idea for double list comprehension?

2014-01-19 Thread CJS
I'm trying to write a D function that does the same as this Python function: def cross(A, B): "Cross product of elements in A and elements in B." return [a+b for a in A for b in B] where A and B are strings. (So cross("ab","12") is ["a1", "b1", "a2", "b2"]). It's easy to get somethin

Python calling D

2013-12-10 Thread CJS
I'd like to use cython to wrap a D library. It's possible to do this with a statically compiled C library, but it fails when I try with a statically compiled D library. Any suggestions on how to do this successfully?

SciD examples?

2013-12-10 Thread CJS
I've been having trouble figuring out how to write a minimal non-trivial example of code using SciD. In particular I've never called another D library before. Does anyone know of existing examples? Including how to compile? A related question is how to choose which blas/lapack are called by S

equivalent of python join?

2013-12-02 Thread CJS
In python a common performance tip for joining many strings together is to use the join method. So, for example, instead of "a" + "b" + "c" use ''.join(["a","b","c"]). The idea is to avoid creating temporary objects that are immediately thrown away. It's obviously overkill for such a small numb

enum value vs. immutable

2013-12-01 Thread CJS
I was reading the enum page of Ali Çehreli's (excellent) D book (http://ddili.org/ders/d.en/enum.html), and I'm confused by an enum value (not enum type), such as enum secondsPerDay = 60 * 60 * 24; In that situation I would have used an immutable variable. Is there any reason to prefer enum

Re: Calling D from C

2013-11-24 Thread CJS
On Sunday, 24 November 2013 at 07:22:37 UTC, evilrat wrote: On Sunday, 24 November 2013 at 05:25:36 UTC, CJS wrote: dmd -c foo.d gcc bar.c foo.o ok i find out what's your problem. here is 2 ways of solving this problem. 1) build like you do already but add to gcc call phobos lib, s

Calling D from C

2013-11-23 Thread CJS
I haven't been able to make calling D from C on Mac OS 10.9 work. I tried the following simple example: foo.d import std.stdio; extern(C) int add(int x, int y){ return x + y; } bar.c #include int add(int , int); int main(){ int x = 1; int y = 2; char s[] = "%d + %d = %d"

Re: delegates, functions, and literals confusion

2013-07-04 Thread CJS
Thanks for the detailed answer! Just to clarify: So if f is an inner function then &f will be a delegate even if it doesn't reference anything in the environment in which it was defined? (i.e. even if it could have been typed as a function?)

Re: std.conv.to vs. casting

2013-07-04 Thread CJS
By the way, CJS -- sorry to have hijacked your query. But I think you had your answer already :-) Yes. It was a very helpful answer. I'm just glad the question I asked was apparently relevant to other users as well.

delegates, functions, and literals confusion

2013-07-03 Thread CJS
Confusion over delegates seems to be a somewhat common topic, judging from http://forum.dlang.org/thread/jbkahhlvevgectisd...@forum.dlang.org and http://stackoverflow.com/questions/6431884/function-and-delegate-literals-in-d. I'm also somewhat confused by functions vs. function literals and h

std.conv.to vs. casting

2013-07-03 Thread CJS
I'm having trouble understanding the difference between casting and std.conv.to. Any help?

Re: C standard libraries

2013-07-01 Thread CJS
It is in core.stdc. For example: import core.stdc.stdio; // import core.stdc.stdlib;// etc. Thanks! I'm confused why that module isn't mentioned in the library reference page. What's the difference between core.stdc and std.c? The docs do refer to core.stdc, though std.c.stdio in Pho

C standard libraries

2013-07-01 Thread CJS
Is there some header/module that includes declaration for all C standard libraries? I'm wondering both in general for future reference, and for the specific case of wanting to time a function and not knowing what in D--even after looking through the docs--would do something equivalent to cloc