Re: Adding a method to an enum.

2011-06-19 Thread Ali Çehreli
On Mon, 20 Jun 2011 02:48:30 +, Charles McAnany wrote: > Hi, all. I'm looking for a way to make constants that have methods > without a lot of overhead. In particular, a way to define a Direction > and then be able to rotate it right. Here's kind of what I have in mind: > > enum Direction{ >

Re: Linker errors on OSX

2011-06-19 Thread Daniel Murphy
"Peter Alexander" wrote in message news:itlk5g$e7t$1...@digitalmars.com... > I've been having strange linker errors recently and I have no ideas why > they've started happening. > > Undefined symbols: > "_D3std9exception7bailOutFAyaixAaZv", referenced from: > _D3std9exception148__T7enforceTb

Re: Adding a method to an enum.

2011-06-19 Thread Jonathan M Davis
On 2011-06-19 19:48, Charles McAnany wrote: > Hi, all. I'm looking for a way to make constants that have methods > without a lot of overhead. In particular, a way to define a > Direction and then be able to rotate it right. Here's kind of what I > have in mind: > > enum Direction{ > left, right, u

Re: Any (working) JSON library for D2?

2011-06-19 Thread Lloyd Dupont
Doost : http://www.dsource.org/projects/doost Has a serializer that can read value to and from JSon! ;) "Johannes Pfau" wrote in message news:20110619193834.2c6afdf7@jpf-Satellite-A100... std.json doesn't work at all because of bug #2962 . I tried to remove the problematic part from std.json

Re: problem with array of delegates!

2011-06-19 Thread Lloyd Dupont
There is a remove() method in std.algorithm!I even got asked why I was reimplementing it! (well, because I didn't know it existed hey!) works fine with, say, int... but not with delegate! associative array will solve the problem indeed.. (I hope) but they use way more memory! it would be nic

Adding a method to an enum.

2011-06-19 Thread Charles McAnany
Hi, all. I'm looking for a way to make constants that have methods without a lot of overhead. In particular, a way to define a Direction and then be able to rotate it right. Here's kind of what I have in mind: enum Direction{ left, right, up, down; public Direction rotateRight(){ switch(this){

RE: dmdscript osx.mak

2011-06-19 Thread Joshua Niehus
Hi Robert and Dmitry, Thanks for your replies and the heads up on the current status of DMDScript! Josh

Re: Any (working) JSON library for D2?

2011-06-19 Thread Adam D. Ruppe
Johannes Pfau : > The only difference is the argument order for dmd! Aye, I saw this one when I updated to 2.053 now I remember wasting an hour on that bug! Bugzilla suggests for the workaround to just put a dummy module in there as the first argument: icehack.d module icehack; import s

Linker errors on OSX

2011-06-19 Thread Peter Alexander
I've been having strange linker errors recently and I have no ideas why they've started happening. When compiling/linking: import std.stdio; void main() { writeln("Hello"); } with DMD 2.053 I get linker error: Undefined symbols: "_D3std9exception7bailOutFAyaixAaZv", referenced from: _

Re: Any (working) JSON library for D2?

2011-06-19 Thread Johannes Pfau
Adam D. Ruppe wrote: >Johannes Pfau wrote: >> I guess you do not have similar helper functions to parse JSON? > >My other message has some. It isn't quite as nice to use though - >getting structs and such takes a little bit of work. > >For example, I use it to get stuff from Facebook, and it >looks

Re: Any (working) JSON library for D2?

2011-06-19 Thread Adam D. Ruppe
Johannes Pfau wrote: > I guess you do not have similar helper functions to parse JSON? My other message has some. It isn't quite as nice to use though - getting structs and such takes a little bit of work. For example, I use it to get stuff from Facebook, and it looks kinda like this: ===

Re: Any (working) JSON library for D2?

2011-06-19 Thread Johannes Pfau
Adam D. Ruppe wrote: >Oh, wait a minute, you were doing from json, not to json. > >Try this on for size. It converts from a std.json.JSONValue >to a std.variant.Varaint, which is quite a bit simpler to use. > >== > >import std.variant; >import std.json; > >Variant jsonToVariant(string json) { >

Re: Any (working) JSON library for D2?

2011-06-19 Thread Johannes Pfau
Adam D. Ruppe wrote: >I use std.json with a couple helper function to make it shorter. > >To use: > >writeln(toJson(whatever)); > >or > >JSONValue val = toJsonValue(whatever); > >Works on most basic data types: int, string, array, assoc, struct, >etc. > >= > >import std.json; >import std.traits

Re: Any (working) JSON library for D2?

2011-06-19 Thread Adam D. Ruppe
Oh, wait a minute, you were doing from json, not to json. Try this on for size. It converts from a std.json.JSONValue to a std.variant.Varaint, which is quite a bit simpler to use. == import std.variant; import std.json; Variant jsonToVariant(string json) { auto decoded = parseJSON(

Re: Any (working) JSON library for D2?

2011-06-19 Thread Adam D. Ruppe
I use std.json with a couple helper function to make it shorter. To use: writeln(toJson(whatever)); or JSONValue val = toJsonValue(whatever); Works on most basic data types: int, string, array, assoc, struct, etc. = import std.json; import std.traits; import std.conv; string toJson(T)(T

Any (working) JSON library for D2?

2011-06-19 Thread Johannes Pfau
std.json doesn't work at all because of bug #2962 . I tried to remove the problematic part from std.json and got it to compile (by disabling support for floating point numbers...) but using it correctly creates very verbose code: -

Re: problem with array of delegates!

2011-06-19 Thread Andrej Mitrovic
Seems like gmail likes to cut my code. If that didn't paste well here: http://codepad.org/cyEDHSGc

Re: problem with array of delegates!

2011-06-19 Thread Andrej Mitrovic
Remove takes an offset, not a value as far as I know. If you need fast lookup and removal you could use hashes instead: int main(string[] argv) { auto a = new A; SlotDelegate x = &a.DIT; bool[SlotDelegate] _slotDg; _slotDg.remove(x); return 0; }

problem with array of delegates!

2011-06-19 Thread Lloyd Dupont
the following code seem problematic to compile... import std.algorithm; private alias void delegate(int, int) SlotDelegate; class A { void DIT(int a, int b) { } } int main(string[] argv) { A a; SlotDelegate x= &a.DIT; SlotDelegate[] _slotDg; _slotDg.remove(x); ret

Re: struct as dictionary key

2011-06-19 Thread Lloyd Dupont
Never mind, just found it! http://www.digitalmars.com/d/2.0/hash-map.html

struct as dictionary key

2011-06-19 Thread Lloyd Dupont
I am creating a struct that I want to use as dictionary (associative array) key Initially it was a class and I overrode toHash and opCmp. I just made it a struct to be more lightweight on the system, but can't "override" toHash anymore! How can I make it a good dictionary key? Here is the stru