On 2012-03-13 14:24:37 +, H. S. Teoh said:
Indeed. Would've thought const AA keys would be reasonable. (In
Python they're *required*... :)
[...]
I'm of the opinion that AA keys should be *implicitly* immutable.
Seconded, whole-heartedly.
--
Magnus Lie Hetland
http://hetland.org
On 2012-03-12 17:33:35 +, Ali Çehreli said:
You can use isNarrowString to either disallow or provide special
implementation for narrow strings (char[] and wchar[]):
Ah -- useful, thanks!
--
Magnus Lie Hetland
http://hetland.org
heir
characteristics off of the top of my head. Certainly, with how sort is currenly
implemented, it can't handle any range which isn't a random access range.
No, I get that. I was just assuming that any T[] could be treated as a
random access range if I really wanted to ;)
--
Magnus Lie Hetland
http://hetland.org
I guess this issue then covers both (despite the different error
messages)? I'll just leave this alone (i.e., not submit any additional
tickets), then (and cast away the constness for now; seems to help).
--
Magnus Lie Hetland
http://hetland.org
ng illegal?-)
--
Magnus Lie Hetland
http://hetland.org
On 2012-03-12 13:56:15 +, bearophile said:
It's not a bug, char is meant to be a UTF-8.
Right.
Two workarounds:
Thanks. I'm doing the sorting in a template, so this won't work -- but
I guess I just can't use char as a type parameter to my template
either, the
The thing is, I'm using sort() in a template, and I just happen to use
char as the template parameter in a unit test. And since I have no
special UTF-8 values in there, my own sort() works just fine. (Although
maybe it shouldn't? ;)
--
Magnus Lie Hetland
http://hetland.org
thing to a file ;-)
But no problem -- not many lines to add to my own code.
--
Magnus Lie Hetland
http://hetland.org
t (although I found some
similar reports) in the Bugzilla. (No biggie for me, though; the Phobos
sort seems to fail with all kinds of things, so I have my own anyway...
;)
--
Magnus Lie Hetland
http://hetland.org
lem.
Just surprised me that there wasn't a standard way of writing
file-related unit tests :)
--
Magnus Lie Hetland
http://hetland.org
as that my tempfiles don't seem to have names (i.e.,
they are unnamed tempfiles, and file.name is null; platform-dependent,
I think).
Otherwise, this wouldn't have been a problem :)
--
Magnus Lie Hetland
http://hetland.org
On 2012-03-09 15:08:42 +, bearophile said:
Magnus Lie Hetland:
It seems that File has no method for reading the entire file contents
into a string, so I'd have to read and concatenate lines or chunks or
something?
There are std.file.read() and std.file.readText().
Yeah, I found
y; much of it
seems to be very related to file-names and actual files, rather than
"file-like" objects, i.e., those with the appropriate methods...)
--
Magnus Lie Hetland
http://hetland.org
On 2012-03-02 11:23:20 +, Ali Çehreli said:
On 03/02/2012 02:18 AM, Magnus Lie Hetland wrote:
I'm writing a template for generating data of some possibly immutable
type -- e.g., a string. What I'm wondering is, is there some way of
accessing the mutable version of an immutable t
something like that? (E.g., a template in Phobos or
something.) I guess I could do a match with an is() expression to
extract the type, perhaps.
--
Magnus Lie Hetland
http://hetland.org
).
For testing, I might want some small numbers, too -- perhaps I should
just generate the mantissa and exponent separately (maybe even throwing
in some NaNs and Infs etc.) :)
Thanks for your help, though.
--
Magnus Lie Hetland
http://hetland.org
gs and odd behavior? Perhaps it's been left
out for a reason? (Sounds sort of likely ;-)
--
Magnus Lie Hetland
http://hetland.org
On 2012-03-01 10:52:49 +, Magnus Lie Hetland said:
I could just use
uniform(cast(T) -1, cast(T) 1)*T.max
I guess (for some floating-point type T). Seems to work fine, at least.
Aaactually, not so much. The output here seems to get about the same
exponent as T.max. Which isn'
isn't terribly helpful.
What's the standard thing to do here? I could just use
uniform(cast(T) -1, cast(T) 1)*T.max
I guess (for some floating-point type T). Seems to work fine, at least.
Am I missing the obvious way to do it?
--
Magnus Lie Hetland
http://hetland.org
args) {
static if (lvl == args.length) {
func(args);
}
else {
foreach (e; args[lvl]) {
forall!(func, lvl+1)
(args[0..lvl], e, args[lvl+1..$]);
}
}
}
--
Magnus Lie Hetland
http://hetland.org
nd hard-code the cases -- but there must be
a prettier way? I've made some stabs at a recursive version, DMD
complaining all the while. Any pointers?
(Now, I would eventually like to do more complex versions, using only a
*subset* of the Cartesian product (for, e.g., all-pairs testi
void method(uint arg)
in {
// assert(arg + 1); // Uncomment to prevent bug
}
out {
assert(arg == 0, "BUG: arg == " ~ to!string(arg));
}
body {}
}
void main(string[] args) {
(new Class).method(0);
}
--
Magnus Lie Hetland
http://hetland.org
I think I've stumbled across a DbC bug. In an out-block, I have the
assertion `assert(id < objs.length);`. Now, if I don't have an
in-block, this fails. However, if I add an in-block (with basically any
code that isn't optimized away, or so it seems), the assertion
succeeds. (Before this was an
;ll
see how it goes. (It can be useful to have the most recent version;
ideally, it should have fewer bugs ;) If that fails, I could try just
the runtime, as you suggest.
--
Magnus Lie Hetland
http://hetland.org
...
SDK=/Developer/SDKs/MacOSX10.5.sdk
#SDK=/Developer/SDKs/MacOSX10.6.sdk
... into ...
SDK=/Developer/SDKs/MacOSX10.5.sdk
#SDK=/Developer/SDKs/MacOSX10.6.sdk
SDK=/Developer/SDKs/MacOSX10.7.sdk
(or equivalent).
--
Magnus Lie Hetland
http://hetland.org
On 2011-08-04 12:27:54 +, Alex Rønne Petersen said:
Hi,
You can see my blog for Linux:
http://xtzgzorex.wordpress.com/2011/07/31/d-building-dmd-and-phobos-on-linux/
Thanks!
--
Magnus Lie Hetland
http://hetland.org
five different repos...? Do
I have to assemble a full distro myself, or am I just missing something
obvious? (I'm assuming the latter, really ;)
--
Magnus Lie Hetland
http://hetland.org
mysterious, probably Lion-related, bugs in my test suite...)
--
Magnus Lie Hetland
http://hetland.org
least for me). Seems the collector is a bit over-eager...?
--
Magnus Lie Hetland
http://hetland.org
estion. (Right...? There are no other dynamic dispatch mechanisms
that I'm forgetting, other than type-based switch statements?)
Thanks,
- M
--
Magnus Lie Hetland
http://hetland.org
comment out at least one of the local
functions (but not if you, for example, comment out the global ones, of
course).
Is this a bug, or am I just missing the reasoning behind it? Any
workarounds? (I'm still at 2.052, so maybe this works in the new
version?)
--
Magnus Lie Hetland
http://hetland.org
of DbC.
Is there a feature request on this that I could add my vote to? If not,
perhaps it's worth creating one?
If not, I guess I could just post a "bump" to the D group :-}
--
Magnus Lie Hetland
http://hetland.org
scope() somehow, perhaps.
I see that the feature has been requested a few years ago [1], so there
might not be that much demand for this sort of thing. Is there perhaps
a D idiom here already?
[1] http://d.puremagic.com/issues/show_bug.cgi?id=2304
--
Magnus Lie Hetland
http://hetland.org
variable that would be local to one specific
in/out instantiation (or stack frame) would be preferable.
I guess I could just use a local variable (guarded by version()) and
then have an assert() near the end of the function. Probably a better
solution...
--
Magnus Lie Hetland
http://hetland.org
re/after"
contracts like this? If not, can it be done in a less ugly manner? (Or
should I just learn to like this way of doing it?)
--
Magnus Lie Hetland
http://hetland.org
argument. I mean, the set-up *could* work (and, in fact,
generally seems to do so), but it might be a bit problematic?
This way of doing it seems like the most practical for my current use,
though... (I.e., I'd like foo to be inline-able, and have access to x.)
--
Magnus Lie Hetland
http://hetland.org
ays
of tuples (which I couldn't get std.container.BinaryHeap to accept). I
then wrapped it in a PriorityQueue class, which takes care of resizing
the array (and having BinaryHeap switch to the possibly reallocated new
one).
Not an ideal solution, but at least it works.
--
Magnus Lie Hetland
http://hetland.org
nswer to both is "you're doing it wrong" ;)
And, of course, my main question:
3. How do you (canonically) make a growable heap using Phobos?
--
Magnus Lie Hetland
http://hetland.org
On 2011-03-24 18:25:30 +0100, bearophile said:
Magnus Lie Hetland:
I guess this is getting old by now ... but I've come across yet another bug :->
The out(result) turns the result into a const,
Riiight! Yes, I've seen that it's const, and (naughtily) cast away the
if (isTuple!(R)) cannot
deduce template function from argument types
!()(const(Tuple!(real,uint)))
I take it this is a bug (or am I just missing something)? Is it a known
bug? (Sorry if it's in the tracker; it can be hard to find equivalents
there...)
--
Magnus Lie Hetland
http://hetland.org
e I
inadvertently used an uint that was of a semantically different kind,
and got a hard-to-spot bug -- so I thought I'd try to prevent that by
using the type system.
Any way to do that without (to be deprecated) typedef?
--
Magnus Lie Hetland
http://hetland.org
mplate declaration
inferencebug.d(19): Error: template inferencebug.foo(T) cannot deduce
template function from argument types !()(uint[],real function(uint x,
uint y))
--
Magnus Lie Hetland
http://hetland.org
d it there already.)
--
Magnus Lie Hetland
http://hetland.org
es) is also a bit awkward. I'd like to have a template so I
could just do
Foo!T foo(T)(T[] bar, baz_t!T baz) { ... }
However, I haven't been able to define such a template without running
into the same problem (i.e., that DMD no longer can deduce what T
should be from my arguments)
wers that
go with it: http://stackoverflow.com/questions/4219600/logical-const-in-d
Thanks for the insights + tip :)
--
Magnus Lie Hetland
http://hetland.org
On 2011-03-14 11:51:09 +0100, Mafi said:
I found away which doesn't use casts or bugs.
Just use delegates/closures.
Nice :D
--
Magnus Lie Hetland
http://hetland.org
On 2011-03-13 23:32:34 +0100, Magnus Lie Hetland said:
(Still open to schooling on the design part of this, though. Perhaps
declaring a method as const is no good when it's not *really* const?
For now, I'm just doing it to check that I don't inadvertently change
things I don
On 2011-03-13 23:27:14 +0100, Magnus Lie Hetland said:
Any other ideas on how to handle this sort of "mostly const" or "const
where it counts" stuff? Perhaps my design intentions here are off to
begin with?-)
OK -- a *little* quick on the trigger there. My solution: Decla
to const (assigning them to local variables) early on in the relevant
methods (dropping the const modifier on the method itself -- sort of a
bummer).
Any other ideas on how to handle this sort of "mostly const" or "const
where it counts" stuff? Perhaps my design intentions h
On 2011-03-13 21:27:27 +0100, spir said:
On 03/13/2011 07:58 PM, Magnus Lie Hetland wrote:
For some reason, it seems like expressions of the form "foo.bar !in baz" aren't
allowed. I suspect this is a grammar/parser problem -- the bang is interpreted
as a template argument operat
return false;
}
}
void main() {
Baz baz;
Foo foo;
auto res = (foo.bar) !in baz;
res = !(foo.bar in baz);
// res = foo.bar !in baz; // Not OK...
uint frozz;
res = frozz !in baz;
}
--
Magnus Lie Hetland
http://hetland.org
ense, given that I'm talking about a limit of
256... :D)
And, for the record, I'm using DMD 2.052 (OS X).
Just replace bool with byte in your program, and it should compile.
Sorry for the brain fart ;)
--
Magnus Lie Hetland
http://hetland.org
ua range propagations and
overflow checking, would it be possible to catch this special case
(i.e., detect when the array can be too long for the index type)? Or
are any other safeguards possible to prevent this sort of thing?
--
Magnus Lie Hetland
http://hetland.org
On 2011-03-06 14:58:10 +0100, Magnus Lie Hetland said:
[corrected the example below, replacing int with string]
that works just fine. However, if I try
alias Tuple!(real,string) Entry;
Array!Entry Q;
then I get the following errors:
container.d(1549): Error: this for _data needs to
On 2011-03-06 15:00:29 +0100, David Nadlinger said:
On 3/6/11 2:58 PM, Magnus Lie Hetland wrote:
alias Tuple!(real,int) Entry;
Array!Entry Q;
[...]
alias Tuple!(real,int) Entry;
Array!Entry Q;
Is it just me, or is there really no difference between the two snippets? ;)
$(WITTY_REPLY
On 2011-03-06 14:37:19 +0100, Magnus Lie Hetland said:
Just wondering: If I want a growable binary heap (I'd be open to other
priority queue structures, for that matter ;), is the standard way in D
(w/Phobos) to combine std.container.BinaryHeap with std.container.Array?
Another
. Also, there's no core.memory link in the sidebar...)
--
Magnus Lie Hetland
http://hetland.org
ending, or appender instances, for that matter? Or, to
put the questions a bit differently: Is there a reason why std.array
doesn't have an insertBack method (that BinaryHeap can use) either
defined for dynamic arrays or for std.array.Appender?
Just trying to figure out what's what he
agree with your point, though. In Python, too, iterators
(i.e., ranges) and iterables (i.e., containers) are separate concepts.
You can iterate over an iterable, and the loop then automatically
extracts an iterator. As this is The Way to Go, it makes sense to me
that it's automatic/implicit.
--
Magnus Lie Hetland
http://hetland.org
On 2011-03-04 17:46:39 +0100, Simen kjaeraas said:
Simen kjaeraas wrote:
[snip]
Found it:
http://d.puremagic.com/issues/show_bug.cgi?id=5605
Oo -- nice :) (That it should work, that is; not that it doesn't ;)
--
Magnus Lie Hetland
http://hetland.org
er like the opBinaryRight
solution, really. I just didn't know of it :)
--
Magnus Lie Hetland
http://hetland.org
ess? (One that isn't really executed -- but
still...) Worth reporting?
Anwyay: Thanks for the clarification :)
--
Magnus Lie Hetland
http://hetland.org
you need to use foreach(e; foo[])? Is there no way
to get this functionality directly (i.e., for foreach(e; foo))?
--
Magnus Lie Hetland
http://hetland.org
too recent
for my dmd ... or that I'm doing something wrong elsewhere in my code,
preventing the operator overloading to take force.
Suggestions/solutions?-)
--
Magnus Lie Hetland
http://hetland.org
1.2). So using those shold be safe -- and perhaps more
easily read on other platforms, for example (byte order), or into
floats with other precisions or the like.
Thanks for the suggestion, though :)
--
Magnus Lie Hetland
http://hetland.org
On 2011-03-01 13:20:18 +0100, Steven Schveighoffer said:
On Tue, 01 Mar 2011 07:19:21 -0500, Lars T. Kyllingstad
wrote:
On Tue, 01 Mar 2011 12:25:30 +0100, Magnus Lie Hetland wrote:
2. How can I make r.front = foo work, when I only have r.front(),
returning a ref (which seems like it is
ives.) Or am
I missing a difference in functionality?
Second question: Just to make sure, this *is* an exact representation
of the underlying floating-point number? (I.e., if that'w what I'm
after, using %a *is* the way to go?)
--
Magnus Lie Hetland
http://hetland.org
foo work, when I only have r.front(),
returning a ref (which seems like it is used in actual code)?
--
Magnus Lie Hetland
http://hetland.org
On 2011-02-27 02:33:46 +0100, Jonathan M Davis said:
[snip lots of useful stuff]
Thanks for your patience, and more useful clarifications. I think I get
it now (but I may very well be wrong ;)
- M
--
Magnus Lie Hetland
http://hetland.org
On 2011-02-26 16:30:10 +0100, Magnus Lie Hetland said:
It's documented here...
http://www.digitalmars.com/d/2.0/phobos/std_cover.html
... but I can't find it in the Phobos source. (Also, I can't import it
-- which is perhaps the most pressing issue :)
It's just that
x27;t know
where any coverage reports end up (unless I examine the path to the
generated executable), so I thought I'd specify where I wanted them...
--
Magnus Lie Hetland
http://hetland.org
ng your code correctly.
That sounds quite in line with programming by contract to me ... but
then, again, I'm a reall n00b on the subject :)
--
Magnus Lie Hetland
http://hetland.org
On 2011-02-26 13:15:58 +0100, Jonathan M Davis said:
On Saturday 26 February 2011 03:24:15 Magnus Lie Hetland wrote:
OK. I had the impression that using assert() in contracts was standard,
also for API functions. I thought contracts fulfilled a similar sort of
function to assert(), in that
to test any functionality they use
separately).
[snip]
I guess the conclusion will be that I'll focus on keeping my
preconditions really simple. (And any utility functions I use in them
can then get unit tests of their own instead ;)
That's probably a good way to handle it .
OK, good :)
--
Magnus Lie Hetland
http://hetland.org
On 2011-02-25 20:04:10 +0100, Jonathan M Davis said:
On Friday, February 25, 2011 07:30:50 Magnus Lie Hetland wrote:
Or, more generally, how do you test asserts (which is what I'm using in
my preconditions etc.)?
As far as I can see, collectException() won't collect errors, whi
On 2011-02-25 17:48:54 +0100, spir said:
On 02/25/2011 04:30 PM, Magnus Lie Hetland wrote:
Or, more generally, how do you test asserts (which is what I'm using in my
preconditions etc.)?
As far as I can see, collectException() won't collect errors, which is what
assert() throws --
foo() catch (AssertError) thrown++;
...
assert(thrown == k);
I guess I could wrap it up a bit, or something.
--
Magnus Lie Hetland
http://hetland.org
I.e., test that they will, in
fact, throw when you break them.)
--
Magnus Lie Hetland
http://hetland.org
s[0] contains the full path to the temporary executable
built and run by rdmd, and args[1..$] contain any arguments I supplied
when running the script.
The fact that --shebang borks the whole execution seems like it must be
a bug. As for the rest of the behavior, it seems pretty useful to me,
ame out with a new Python book,
"Python Algorithms", last fall ;)
--
Magnus Lie Hetland
http://hetland.org
On 2011-02-20 19:22:20 +0100, Magnus Lie Hetland said:
On 2011-02-19 22:25:31 +0100, Nick Sabalausky said:
[snip]
Unfortunately, rdmd doesn't seem to have gotten much attention lately.
I've had a few patches for it sitting in bugzilla for a number of
months. (Not that I'
is
pretty much finalized now.
I just realized I didn't give a direct answer to your question: I'd say
that most minor releases of DMD are *not* backward-incompatible.
Thanks for both the thorough and the more direct answer. Very helpful/useful :)
--
Magnus Lie Hetland
http://hetland.org
might still need some updating for 2.052.
Hm. Are most minor releases of DMD backward-incompatible? (Sort of a
scary prospect to me, at least...)
--
Magnus Lie Hetland
http://hetland.org
Do It[tm], or if perhaps I should
submit an issue about this?
[1] http://www.digitalmars.com/d/2.0/rdmd.html
--
Magnus Lie Hetland
http://hetland.org
meant whichever function is
actually using the string ;) But, yeah, I understand how it works.
Thanks.
But thanks for noting that, I've filed it as issue #5513.
Good.
--
Magnus Lie Hetland
http://hetland.org
On 2011-02-01 16:09:22 +0100, Simen kjaeraas said:
Magnus Lie Hetland wrote:
Sort of related (though perhaps only remotely) is the following, which
won't compile (Error: static assert "Bad unary function: f(a) for type
int"):
Not related. unaryFun and binaryFun are simply g
On 2011-02-01 16:00:16 +0100, Magnus Lie Hetland said:
import std.functional, std.stdio;
int f(int x) {return x;}
void main() {
alias unaryFun!("f(a)") g;
writeln(g(3));
}
Just to be clear -- I realize I could just have used unaryFun!f here
(or just f, for t
On 2011-02-01 12:37:05 +0100, Simen kjaeraas said:
Magnus Lie Hetland wrote:
Hm. Just to make sure this *is* a bug, and I'm not just being a dumbass
... this is a tiny program that illustrates the problem (i.e., gives
the error above). Perhaps the use of a local function here real
On 2011-02-01 10:12:44 +0100, Magnus Lie Hetland said:
On 2011-01-31 19:46:53 +0100, Simen kjaeraas said:
Magnus Lie Hetland wrote:
Hm. Using code quite similar to you, supplying a lambda in the second
aliasing, I get this error:
something.d(93): Error: template instance cannot use local
On 2011-02-01 10:49:23 +0100, bearophile said:
Magnus Lie Hetland:
Saw your post on digitalmars.D now, about the currying of templates
(i.e., the main topic here). I guess perhaps that was what you were
talking about?
Tuple unpacking syntax and template currying are two different things
On 2011-02-01 10:11:53 +0100, Magnus Lie Hetland said:
On 2011-01-31 22:21:40 +0100, bearophile said:
Magnus Lie Hetland:
[snip]
I'm accustomed to is the ability to
assign to multiple variables, such as
arg, val = minArg(...)
(Yeah, I'm a Python guy... ;)
I will eventu
On 2011-01-31 19:46:53 +0100, Simen kjaeraas said:
Magnus Lie Hetland wrote:
Hm. Using code quite similar to you, supplying a lambda in the second
aliasing, I get this error:
something.d(93): Error: template instance cannot use local
'__dgliteral2(__T3)' as parameter to
On 2011-01-31 22:21:40 +0100, bearophile said:
Magnus Lie Hetland:
[snip]
I'm accustomed to is the ability to
assign to multiple variables, such as
arg, val = minArg(...)
(Yeah, I'm a Python guy... ;)
I will eventually add a detailed enhancement request on this topic.
Grea
I want it to do...
Using optArg!"a", for example, works just fine -- but the whole point
was to include some local state. Using local functions worked (I
think...?) when I had a global template.
It seems D's compile-time computation system is less straightforward
than I thought :
;-)
At the moment, I'm using a mixing to create the min and max templates
(as rather large strings). Probably not ideal.
Thanks!
--
Magnus Lie Hetland
http://hetland.org
ent that yields a max/min value for a given expression), I'd be
interested to hear that too. The best way to solve a problem is often
to rephrase it :)
--
Magnus Lie Hetland
http://hetland.org
h seems excessively hacky for such a simple thing).
Any ideas/suggestions? I'm sure I'm missing something obvious ...
(Perhaps even existing functionality for minArg/maxArg -- although the
general question still stands.)
--
Magnus Lie Hetland
http://hetland.org
97 matches
Mail list logo