Re: extern(C++) linker errors

2015-04-22 Thread bitwise via Digitalmars-d-learn
On Wed, 22 Apr 2015 02:14:40 -0400, Dan Olson zans.is.for.c...@yahoo.com  
wrote:



bitwise bitwise@gmail.com writes:

I am trying to interface to C++, and getting linker errors. Below are
my 3 source files and 2 build scripts with their associated
errors. Can anyone see what I'm doing wrong?


Hi, I think both examples need libstdc++ added when you link
(-L-lstdc++).  That should resolve the missing C++ operators.

For script1.sh with ldc2 I see an extra underscore in C++ mangled names.
You must be on OS X.  ldc was just fixed in merge-2.067 branch to remove
an extra underscore on OS X.  If you want to experiment, you can build
https://github.com/ldc-developers/ldc/tree/merge-2.067 and check it out.
There are still a few tests to reolve, but it works pretty well for me.
--
Dan


Awesome, Thanks!

I am now getting the expected error from clang/LDC, and the GCC/DMD build  
is working. I'll probably switch to LDC at some point, but I just need to  
get up and running right now.


My updated(objective-C++) and working code:

/ test.mm
#include stdio.h
#import Foundation/Foundation.h

@interface XYZPerson : NSObject
- (void)sayHello;
@end

@implementation XYZPerson
- (void)sayHello {
printf(Hello, World!\n);
}
@end

class Test {
public:
virtual void Foo(){
XYZPerson *person = [[XYZPerson alloc] init];
[person sayHello];
[person release];
}
};

Test* CreateTest() {
return new Test;
}

void DestroyTest(Test *test) {
delete test;
}

/  Test.d
same

/  main.d
same

/ script2.sh
g++ test.mm -olibTest.o -c -stdlib=libc++
ar rcs libTest.a libTest.o
dmd main.d Test.d libTest.a -ofTest -L/usr/lib/libc++.dylib -L-framework  
-LFoundation

./Test


Re: Download DDMD?

2015-04-22 Thread jkpl via Digitalmars-d-learn

On Wednesday, 22 April 2015 at 09:26:37 UTC, jkpl wrote:
On Wednesday, 22 April 2015 at 07:57:40 UTC, Jeremiah DeHaan 
wrote:
Just curious, but I was wondering if there was a 2.067 DDMD 
available for download somewhere for Windows. If not, then are 
there any special build instructions I need to build it? I 
kind of just want to try a couple of things, so I would rather 
I not have to build it if I can avoid it.


the 2.067 ddmd is available as a static library. For the moment 
it only includes the lexer and the parser:


https://github.com/yebblies/ddmd

it does not require anything specific to build: pass the 
sources, set the -lib switch, maybe set the 
warnings/depreciations to off because there are some small 
syntax issues (C-stle array or switch case fallthrough).


I've put it metad btw

https://github.com/BBasile/metad/blob/master/projects/ddmd.coedit



Re: Reading whitespace separated strings from stdin?

2015-04-22 Thread TheGag96 via Digitalmars-d-learn

On Tuesday, 21 April 2015 at 03:44:16 UTC, weaselcat wrote:

snip


Wow, that's a damn good solution... I didn't know that readln() 
could take an argument that it stops at once it finds.


Now the thing is, this program is supposed to be a reverse Polish 
notation calculator. A human using this program would probably be 
confused as to why nothing happens when they hit enter after a 
line -- it only really works in the context of copying and 
pasting the whole input in. Still a really neat solution to know 
anyhow. Thanks!


Re: Download DDMD?

2015-04-22 Thread jkpl via Digitalmars-d-learn
On Wednesday, 22 April 2015 at 15:06:17 UTC, Jeremiah DeHaan 
wrote:

On Wednesday, 22 April 2015 at 09:26:37 UTC, jkpl wrote:
On Wednesday, 22 April 2015 at 07:57:40 UTC, Jeremiah DeHaan 
wrote:
Just curious, but I was wondering if there was a 2.067 DDMD 
available for download somewhere for Windows. If not, then 
are there any special build instructions I need to build it? 
I kind of just want to try a couple of things, so I would 
rather I not have to build it if I can avoid it.


the 2.067 ddmd is available as a static library. For the 
moment it only includes the lexer and the parser:


https://github.com/yebblies/ddmd

it does not require anything specific to build: pass the 
sources, set the -lib switch, maybe set the 
warnings/depreciations to off because there are some small 
syntax issues (C-stle array or switch case fallthrough).


Yes, I was aware of this, but I actually want it as a compiler.


oops, i was not sure of you being a noob even if i saw your 
avatar many times here. Sorry. Just ask to someone of the core...


Re: Download DDMD?

2015-04-22 Thread Jeremiah DeHaan via Digitalmars-d-learn

On Wednesday, 22 April 2015 at 09:26:37 UTC, jkpl wrote:
On Wednesday, 22 April 2015 at 07:57:40 UTC, Jeremiah DeHaan 
wrote:
Just curious, but I was wondering if there was a 2.067 DDMD 
available for download somewhere for Windows. If not, then are 
there any special build instructions I need to build it? I 
kind of just want to try a couple of things, so I would rather 
I not have to build it if I can avoid it.


the 2.067 ddmd is available as a static library. For the moment 
it only includes the lexer and the parser:


https://github.com/yebblies/ddmd

it does not require anything specific to build: pass the 
sources, set the -lib switch, maybe set the 
warnings/depreciations to off because there are some small 
syntax issues (C-stle array or switch case fallthrough).


Yes, I was aware of this, but I actually want it as a compiler.


Re: Structural exhaustive matching

2015-04-22 Thread weaselcat via Digitalmars-d-learn

On Wednesday, 22 April 2015 at 04:54:39 UTC, Martin Nowak wrote:

On Tuesday, 21 April 2015 at 15:36:28 UTC, Jadbox wrote:
What's the best equivalent to Rust's structural enum/pattern 
(match)ing? Is it also possible to enforce exhaustive matches? 
Basically, I'm curious on what the best way to do ADTs in D.


If it needs to be really fast, use final switch on the tag of a 
discriminated union.


enum Tag { A, B, C }
struct Val
{
  Tag tag;
  union
  {
A a;
B b;
C c;
  }
}

void too(Val val)
{
  final switch (val.tag)
  {
  case Tag.A: writeln(val.a); break;
  case Tag.B: writeln(val.b); break;
  case Tag.C: writeln(val.c); break;
  }
}


there's no reason this should be faster than Algebraic(restricted 
variant) from std.variant, is there? implementation issue?


Re: extern(C++) linker errors

2015-04-22 Thread Dan Olson via Digitalmars-d-learn
bitwise bitwise@gmail.com writes:
 I am trying to interface to C++, and getting linker errors. Below are
 my 3 source files and 2 build scripts with their associated
 errors. Can anyone see what I'm doing wrong?

Hi, I think both examples need libstdc++ added when you link
(-L-lstdc++).  That should resolve the missing C++ operators.

For script1.sh with ldc2 I see an extra underscore in C++ mangled names.
You must be on OS X.  ldc was just fixed in merge-2.067 branch to remove
an extra underscore on OS X.  If you want to experiment, you can build
https://github.com/ldc-developers/ldc/tree/merge-2.067 and check it out.
There are still a few tests to reolve, but it works pretty well for me.
--
Dan


Re: how does isInputRange(T) actually work?

2015-04-22 Thread kevin via Digitalmars-d-learn

On Tuesday, 21 April 2015 at 19:42:42 UTC, anonymous wrote:

On Tuesday, 21 April 2015 at 19:17:56 UTC, kevin wrote:

On Tuesday, 21 April 2015 at 19:13:34 UTC, Meta wrote:

On Tuesday, 21 April 2015 at 19:11:43 UTC, John Colvin wrote:

On Tuesday, 21 April 2015 at 19:06:39 UTC, kevin wrote:

enum bool isInputRange = is(typeof(
(inout int = 0)
{
R r = R.init; // can define a range object
if (r.empty) {}   // can test for empty
r.popFront(); // can invoke popFront()
auto h = r.front; // can get the front of the range
}));

[...]
Also, what is the purpose of typeof? I would have expected a 
simple is() to work just fine.


(In this most simple form,) `is` evaluates to true if the 
argument is a valid type. A function/delegate literal isn't a 
type.


If you passed the lambda expression itself to `is`, the result 
would always be false. As it is, the result is true when the 
lambda expression compiles (so it has a valid type).


More about the IsExpression: 
http://dlang.org/expression.html#IsExpression


That makes sense. It seems to me that D has very... special but 
effective syntax. I'm having a hard time remembering all the 
keywords and expression forms (especially of IsExpression) but 
it's definitely a vast improvement over C++'s half baked pile of 
whatever. Thanks for the help, everyone.


GetModuleHandle

2015-04-22 Thread Laeeth Isharc via Digitalmars-d-learn

Hi.

I am trying to use the Excel API with latest release dmd on Win 
32.  It looks like GetModuleHandle isn't in the D windows header 
anymore.


Should I try to use GetModuleHandleA or B ?

Thoughts?


Re: string to thread

2015-04-22 Thread armando sano via Digitalmars-d-learn
Is there any update on this? This question of the distinction 
between reading/writing to a file stream vs to a string seems 
recurrent.


I am interested in writing to a string and am wondering if there 
is a reason for having to use explicitly the convenience 
functions std.conv.text() (or to!string()) and 
std.string.format() when one would expect to be able to do:


string s;
int n = 10;
s.writeln(Hello , n,  times); // s == Hello 10 times\n
s.writefln(and %d times, n); // s == Hello 10 times\nand 10 
times\n


There is a simple way to emulate this by expanding on string:

struct sstring {
string _s;
alias _s this; // treat sstring just like _s, a string

this(string literal = ) { _s = literal; }

	void write(Args...)(Args args) { foreach(a; args)  {_s ~= 
to!string(a);} }

void writeln(Args...)(Args args) { this.write(args, '\n'); }
	void writef(Char, Args...)(in Char[] fmt, Args args) { _s ~= 
std.string.format(fmt, args); }
	void writefln(Char, Args...)(in Char[] fmt, Args args) { 
this.writef(fmt ~ '\n', args); }	

}

An 'sstring s;' can be then be used just like a normal 'string' 
with the addition of being able to use it as in the example above.


I suspect something similar could be done for reading.

Why the syntactic burden of having to use to!string, 
std.string.format, std.conv.parse etc?


Re: how does isInputRange(T) actually work?

2015-04-22 Thread Vlad Levenfeld via Digitalmars-d-learn

On Wednesday, 22 April 2015 at 21:22:43 UTC, Meta wrote:
That makes sense. It seems to me that D has very... special 
but effective syntax. I'm having a hard time remembering all 
the keywords and expression forms (especially of IsExpression) 
but it's definitely a vast improvement over C++'s half baked 
pile of whatever. Thanks for the help, everyone.


The `is` expression is complicated and has a bunch of different 
usage syntax, but it's like one of those little multitools. 
Complicated to figure out how to use, but extremely flexible 
and able to do a lot of cool things.


Yeah, the `is` expression is one of my favorite D features.

import std.container;

template Substitute (T, U) {
  static if (is (T == F!V, alias F, V))
alias Substitute = F!U;
}

alias List = SList!int;

static assert (is (Substitute!(List, char) == SList!char));

It's the little things.


Startup files for STM32F4xx

2015-04-22 Thread Jens Bauer via Digitalmars-d-learn
I've now created a few startup files for the STM32F4xx 
microcontrollers.

You can grab them here ...

http://d.gpio.dk/cgi-bin/gitweb.cgi

... Unfortunately I have no 'read-only' checkout on my 
git-server, but I'll be happy to make a tar.bz2 archive upon 
request.


Re: how does isInputRange(T) actually work?

2015-04-22 Thread Meta via Digitalmars-d-learn
That makes sense. It seems to me that D has very... special but 
effective syntax. I'm having a hard time remembering all the 
keywords and expression forms (especially of IsExpression) but 
it's definitely a vast improvement over C++'s half baked pile 
of whatever. Thanks for the help, everyone.


The `is` expression is complicated and has a bunch of different 
usage syntax, but it's like one of those little multitools. 
Complicated to figure out how to use, but extremely flexible and 
able to do a lot of cool things.


Re: Startup files for STM32F4xx

2015-04-22 Thread Jens Bauer via Digitalmars-d-learn
On Thursday, 23 April 2015 at 04:48:16 UTC, Rikki Cattermole 
wrote:

On 23/04/2015 2:41 p.m., Jens Bauer wrote:
... Unfortunately I have no 'read-only' checkout on my 
git-server, but

I'll be happy to make a tar.bz2 archive upon request.


Make a github mirror if you don't want to push it directly 
there.


That might work. I had to create my own git server, because 
GitHub does not work with any of my Web-browsers. -The only thing 
I can do with a Web-browser is to fork another repository and 
post comments. This is basically because GitHub's buttons do not 
work on my browsers.
I'll try and make an attempt to set up a mirror tomorrow, but it 
might be easier setting up gitolite with HTTP anyway. ;)


Re: Startup files for STM32F4xx

2015-04-22 Thread Rikki Cattermole via Digitalmars-d-learn

On 23/04/2015 4:53 p.m., Jens Bauer wrote:

On Thursday, 23 April 2015 at 04:48:16 UTC, Rikki Cattermole wrote:

On 23/04/2015 2:41 p.m., Jens Bauer wrote:

... Unfortunately I have no 'read-only' checkout on my git-server, but
I'll be happy to make a tar.bz2 archive upon request.


Make a github mirror if you don't want to push it directly there.


That might work. I had to create my own git server, because GitHub does
not work with any of my Web-browsers. -The only thing I can do with a
Web-browser is to fork another repository and post comments. This is
basically because GitHub's buttons do not work on my browsers.
I'll try and make an attempt to set up a mirror tomorrow, but it might
be easier setting up gitolite with HTTP anyway. ;)


Ehh, maybe you should setup a e.g. vm of e.g. Linux Mint and use e.g. 
Github via it.
After all, not having a web browser working for it isn't an excuse when 
all the main ones do ;)


Re: Startup files for STM32F4xx

2015-04-22 Thread Rikki Cattermole via Digitalmars-d-learn

On 23/04/2015 2:41 p.m., Jens Bauer wrote:

I've now created a few startup files for the STM32F4xx microcontrollers.
You can grab them here ...

http://d.gpio.dk/cgi-bin/gitweb.cgi

... Unfortunately I have no 'read-only' checkout on my git-server, but
I'll be happy to make a tar.bz2 archive upon request.


Make a github mirror if you don't want to push it directly there.


Re: GetModuleHandle

2015-04-22 Thread Laeeth Isharc via Digitalmars-d-learn

On Wednesday, 22 April 2015 at 19:37:35 UTC, John Chapman wrote:
On Wednesday, 22 April 2015 at 18:31:20 UTC, Laeeth Isharc 
wrote:

Hi.

I am trying to use the Excel API with latest release dmd on 
Win 32.  It looks like GetModuleHandle isn't in the D windows 
header anymore.


Should I try to use GetModuleHandleA or B ?

Thoughts?


Import core.sys.windows.windows and pick either 
GetModuleHandleA (ANSI) or GetModuleHandleW (Unicode, 
preferred).


Thank you.


Download DDMD?

2015-04-22 Thread Jeremiah DeHaan via Digitalmars-d-learn
Just curious, but I was wondering if there was a 2.067 DDMD 
available for download somewhere for Windows. If not, then are 
there any special build instructions I need to build it? I kind 
of just want to try a couple of things, so I would rather I not 
have to build it if I can avoid it.


Re: Download DDMD?

2015-04-22 Thread jkpl via Digitalmars-d-learn
On Wednesday, 22 April 2015 at 07:57:40 UTC, Jeremiah DeHaan 
wrote:
Just curious, but I was wondering if there was a 2.067 DDMD 
available for download somewhere for Windows. If not, then are 
there any special build instructions I need to build it? I kind 
of just want to try a couple of things, so I would rather I not 
have to build it if I can avoid it.


the 2.067 ddmd is available as a static library. For the moment 
it only includes the lexer and the parser:


https://github.com/yebblies/ddmd

it does not require anything specific to build: pass the sources, 
set the -lib switch, maybe set the warnings/depreciations to off 
because there are some small syntax issues (C-stle array or 
switch case fallthrough).