Re: Units of Measurement Library: units-d

2016-04-04 Thread Simen Kjaeraas via Digitalmars-d-announce

On Saturday, 2 April 2016 at 01:19:45 UTC, Meta wrote:

What is needed is Lisp's gensym construct.


That's basically what I said, no? :p

One problem of lisp's gensym (if we were to use it in D) is that 
it's simply a monotonically increasing number with a global 
prefix. It's perfect for the language it's in, and all but 
useless in D.


For this very reason, I have made a stab at implementing 
__GENSYM__ in D. It follows basically the ideas I outlined above, 
and spits out a string on the form MANGLE_#, with # being a 
counter for the given mangled name:


module bar;
struct Ham(string gensym = __GENSYM__) {
pragma(msg, gensym);
}
struct Eggs(string gensym = __GENSYM__) {
pragma(msg, gensym);
}

// ===

module foo;
import bar;

pragma(msg, __GENSYM__); // 3foo_1

void main() {
pragma(msg, __GENSYM__); // _Dmain_1
Ham!() a; // _Dmain_3bar_1
Ham!() b; // _Dmain_3bar_2
assert(!is(typeof(a) == typeof(b)));
Eggs!() c; // _Dmain_3bar_3
S2!() d; // _Dmain_3foo_1
}

struct Qux {
pragma(msg, __GENSYM__); // 3foo3Qux_1
void baz() {
pragma(msg, __GENSYM__); // _D3foo3Qux3bazMFZv_1
Ham!() a; // _D3foo3Qux3bazMFZv_3bar_1
}
}

struct S2(string gensym = __GENSYM__) {
pragma(msg, gensym);
}

Should I file an enhancement for this?

--
  Simen


Re: Beta D 2.071.0-b2

2016-04-04 Thread Steven Schveighoffer via Digitalmars-d-announce

On 4/3/16 7:59 AM, tost wrote:

On Wednesday, 30 March 2016 at 11:03:51 UTC, Martin Nowak wrote:

Second beta for the 2.071.0 release.

http://dlang.org/download.html#dmd_beta
http://dlang.org/changelog/2.071.0.html

Please report any bugs at https://issues.dlang.org

-Martin


//foo.d
module foo;

void main() {}

class A {

 void bar(int i) {}

 void baz() {
 import othermodule;
 bar("abc");
 }
}

// othermodule.d
module othermodule;

void bar(string s) {}

compiled with

dmd foo.d othermodule.d

gives

foo.d(11): Error: function foo.A.bar (int i) is not callable using
argument types (string)

is this a feature of the new name lookup algorithm or a bug? Adapting my
codebase would be trivial :)


Yes. There are new lookup rules. See my post about it here: 
http://www.schveiguy.com/blog/2016/03/import-changes-in-d-2-071/


To fix, you should import with selective:

import othermodule: bar;

If you need both bar(int) and bar(string) from their respective 
locations, I'd suggest a renaming import.


-Steve