rogram is terminated instead of continuing in an invalid state.
- Jonathan M Davis
On Monday, September 9, 2024 6:40:07 PM MDT kookman via Digitalmars-d-learn
wrote:
> On Tuesday, 10 September 2024 at 00:27:43 UTC, Jonathan M Davis
>
> wrote:
> > On Monday, September 9, 2024 5:46:18 PM MDT kookman via
> >
> > Digitalmars-d-learn wrote:
> >>
lance, it looks like the part of case 5 which explicitly catches the
Exception and the part that uses assertThrown should behave the same, but
your example doesn't actually compile (you didn't include a definition for
base32Alphabet), so it's not actually possible to reproduce you
ent, but it's arguably best practice to just avoid expressions that
modify a variable while also evaluating that variable in another part of the
expression. It makes the code clearer and avoids any order-of-evaluation
issues which may exist in the language.
- Jonathan M Davis
On Friday, August 16, 2024 10:37:45 AM MDT Nick Treleaven via Digitalmars-d-
learn wrote:
> On Friday, 16 August 2024 at 16:30:09 UTC, Jonathan M Davis wrote:
> > Whether the result of dup is then able to be implicitly
> > converted to immutable based on whether the operation is p
sult is used.
So, dup may very well work in this particular case, but in the general case,
you really want to be using idup if you want immutable. And in this
particular example, all it would take to make the result not immutable would
be to use auto instead of string.
- Jonathan M Davis
On Friday, July 26, 2024 2:17:21 AM MDT Dom DiSc via Digitalmars-d-learn
wrote:
> On Thursday, 25 July 2024 at 13:07:03 UTC, Jonathan M Davis wrote:
> > On Thursday, July 25, 2024 6:00:58 AM MDT Dom DiSc via
> >
> >> But a parameter given by value is ALWAYS a copy.
>
ors, an rvalue constructor
would become a move constructor, though since it's not necessarily obvious
that that's what it is, and such constructors already exist as normal
constructors, there are some objections to making such a change. But of
course, we'll have to see what ultimately happens with that.
- Jonathan M Davis
dds via scope (since without the extra checks, you could easily take
that address and pass it around, letting it escape the lifetime of the
reference).
- Jonathan M Davis
lates with a tail-const version similar
to what we get with dynamic arrays, but that really only makes sense for
certain types such as ranges.
But either way, it would cause quite a few problems if IFTI started
instantiating templates in general with mutable instead of the actual type
that it's given, because it's extremely common that const and immutable
types cannot be converted to mutable.
- Jonathan M Davis
ert(is(typeof(arr) == const(int[])));
static assert(is(typeof(arr[]) == const(int)[]));
So, if you have something like
immutable string foo = "hello";
and you pass it to a templated function, the type will be treated as string,
whereas with a user-defined type - or with any built-in types which aren't
dynamic arrays - the templated function is instantiated with exactly the
type that you pass it.
- Jonathan M Davis
u know enough to suspect that something
along those lines might be the problem, I bet that most of us would not
immediately come to that conclusion. It's just too subtle. And all to avoid
typing a couple of characters.
- Jonathan M Davis
nd you could
easily spend more time trying to optimize your build times than you would
ever save by trying generate the string more efficiently, but it's your
code.
- Jonathan M Davis
ully lead to the file being updated (and if you're feeling particularly
motivated, you can always open a pull request -
https://github.com/dlang/dmd/).
- Jonathan M Davis
zeof;
which would be equivalent to
template sizeOf(T)
{
enum sizeOf = T.sizeof;
}
and they're used with function templates, e.g.
T identity(T)(T value)
{
return value;
}
is equivalant to
template identity(T)
{
T identity(T value)
{
return value;
}
}
- Jonathan M Davis
On Friday, May 31, 2024 6:28:27 PM MDT Andy Valencia via Digitalmars-d-learn
wrote:
> On Friday, 31 May 2024 at 16:59:08 UTC, Jonathan M Davis wrote:
>
> Speaking as an old kernel engineer for the Sequent multiprocessor
> product line, this is all very comfortable to me. I'm v
ed. But if all you're doing is passing an object across
threads, then it's pretty straightforward, since you just cast it to shared
or immutable to be able to pass it across threads and then cast back to
thread-local on the other side to use it as normal again (you just need to
make sure that you don't leave a reference to the data on the original
thread when you do that).
- Jonathan M Davis
ed AAs, because it
has no way of guaranteeing that that's thread-safe. So, the solution is that
you must explicitly removed shared temporarily to call clear when you know
that it's thread-safe to do so.
- Jonathan M Davis
On Friday, May 3, 2024 2:38:31 PM MDT Jonathan M Davis via Digitalmars-d-learn
wrote:
> On Friday, May 3, 2024 1:15:16 PM MDT Ben Jones via Digitalmars-d-learn
wrote:
> > In general, you can't skip a declaration with goto, but it seems
> > to be allowed if the declaratio
because of
the label for some reason, and one or more of the checks that it's supposed
to be doing is being missed.
- Jonathan M Davis
ullable). E.g.
auto a = nullable(3);
allows you to not bother giving the explicit type of the Nullable at all.
- Jonathan M Davis
ndings if you want to use them now.
- Jonathan M Davis
them for Linux, so they got them added, but either no one
else has needed the bindings, or no one else has needed them for anything
other than Linux with glibc - or if they did, they didn't get them into
druntime.
- Jonathan M Davis
On Friday, April 5, 2024 3:11:42 AM MDT Dom DiSc via Digitalmars-d-learn
wrote:
> On Sunday, 24 March 2024 at 09:16:20 UTC, Jonathan M Davis wrote:
> > So, yes, you've run into a problem that it would be nice to
> > have a better fix for, but even if we could negate attri
On Monday, April 1, 2024 5:37:56 PM MDT dany via Digitalmars-d-learn wrote:
> Actually I would get an ID's Usb
That's going to depend on the operating system, and it's also going to
depend on exactly what kind of ID you're looking for.
- Jonathan M Davis
worry about code within a module accidentally
accessing other code within that module, then your module is probably too
large anyway.
So, if don't want code to be able to access any of the private members of
your QueueNode type, that code will need to be in a separate module rather
than in the same module as the QueueNode type.
- Jonathan M Davis
to do something
like generate a switch statement from the list of enum members.
https://dlang.org/phobos/std_traits.html#EnumMembers
- Jonathan M Davis
t easy to miss the fact that a particular attribute applies to the
code being changed.
So, yes, you've run into a problem that it would be nice to have a better
fix for, but even if we could negate attributes in general, there are good
reasons to prefer to avoid mass-applying attributes.
- Jonathan M Davis
a value more than once. It should be initialized, and
then it should be treated as illegal to ever assign to it - or to do
anything else which would mutate it. So, clearly, the logic in static
constructors with regards to non-mutable variables is overly simple at the
moment.
- Jonathan M Davis
atic assert(typeof(arr[]) == const(int)[]);
For better or worse, arrays do that to avoid requiring that you explicitly
slice them to pass them to range-based functions in the cases where you did
something like declare a string to be immutable. But nothing like that
happens with any other types, so if you pass a const Foo - or a const int -
to a templated function, it's instantiated with that exact type.
- Jonathan M Davis
that they're used for the same thing at
all. And having them be implicitly convertible could cause serious problems
with overloading.
If you want to do that conversion without a cast, then you can just use
std.string.representation (which will do the cast internally).
- Jonathan M Davis
On Wednesday, March 13, 2024 3:49:55 PM MDT zoujiaqing via Digitalmars-d-learn
wrote:
> On Wednesday, 13 March 2024 at 21:21:21 UTC, Jonathan M Davis
>
> wrote:
> > On Wednesday, March 13, 2024 3:03:30 PM MDT zoujiaqing via
> >
> > Digitalmars-d-learn wrote:
> >
ile system and then does a copy and remove instead
if moving within the file system doesn't work, but otherwise, you'll have to
implement that yourself, which could be as simple as catching the any
exceptions from move and then attempting to copy the file and then remove it
if an exception was thrown.
- Jonathan M Davis
On Monday, March 11, 2024 10:51:48 AM MDT Andy Valencia via Digitalmars-d-
learn wrote:
> On Monday, 11 March 2024 at 16:25:13 UTC, Jonathan M Davis wrote:
> > ...
> > But what exactly static means varies based on the context.
>
> Thank you for the list! But none of those
tributes:
https://dlang.org/spec/attribute.html#visibility_attributes
And specifically, to make a symbol only be visible inside a module, you
mark it with private.
- Jonathan M Davis
t; scope(failure)?
If anything, I think that it's been decided that chained exceptions were a
mistake. So, if things go in any direction with them, it's likely to be
towards removing them, not doing more to support them.
- Jonathan M Davis
ing file = __FILE__,
size_t line = __LINE__)
{
import core.exception : AssertError;
try
expression();
catch (T)
return;
static if (!is(immutable E == immutable noreturn))
throw new AssertError("assertThrown failed: No " ~ T.stringof ~
" was thrown" ~
(msg.length == 0 ? "." : ": ") ~ msg,
file, line);
}
- Jonathan M Davis
ast away const or immutable to fix the copy. The
only way to work properly with const or immutable is to construct the object
with the changes in the first place rather than mutating the copy after the
fact.
- Jonathan M Davis
char[] is
@safe, so dmd should be taking that possibility into account, and it's
apparently not.
So, there's definitely a bug here, but it's a dmd bug. Its checks for
whether it can safely change the constness of the return type apparently
aren't sophisticated enough to catch this case.
- Jonathan M Davis
On Saturday, February 10, 2024 7:31:47 PM MST Steven Schveighoffer via
Digitalmars-d-learn wrote:
> On Saturday, 10 February 2024 at 23:48:56 UTC, Jonathan M Davis
>
> wrote:
> > If I understand correctly, he cares about how far into the
> > month the dates
> > are, whe
reas diffMonths ignores the smaller units, meaning that you get the
same result no matter when in the month the dates are. So,
2000-05-10 - 1990-05-09 would give 10, whereas 2000-05-10 - 1990-05-30
would give 9. diffMonths / 12 would give 10 in both cases.
- Jonathan M Davis
, there are edge cases where it definitely does the
wrong thing (e.g. with regards to leap years or DST). And math around months
is a prime area where it's difficult to get right in part because different
people have different requirements depending on the actual problem that
they're trying to solve.
- Jonathan M Davis
== -3);
assert(yearsApart(Date(2000, 2, 29), Date(2004, 2, 29)) == -4);
assert(yearsApart(Date(2000, 2, 29), Date(2005, 2, 28)) == -4);
}
- Jonathan M Davis
We would like to improve the situation with the next major version of Phobos
so that the copy semantics of ranges are cleaner, and the range API will
likely see a redesign to fix that issue, among others, but the current range
API is as I've explained it to you, warts and all.
- Jonathan M Davis
tic arrays).
As it is, you can probably only put the first dimension between the
brackets, because other languages do that, and allowing it makes it easier
to port code. Arguably though, for consistency, you should always put the
dimensions between the parens when allocating a new dynamic array.
- Jonathan M Davis
On Friday, January 19, 2024 3:49:29 AM MST Jim Balter via Digitalmars-d-learn
wrote:
> On Friday, 17 November 2017 at 17:55:30 UTC, Jonathan M Davis
>
> wrote:
> > When you have
> >
> > foreach(e; range)
> >
> > it gets lowered to something like
> >
On Thursday, January 18, 2024 4:58:32 PM MST zoujiaqing via Digitalmars-d-
learn wrote:
> On Thursday, 18 January 2024 at 23:43:13 UTC, Jonathan M Davis
>
> wrote:
> > On Thursday, January 18, 2024 4:26:42 PM MST zoujiaqing via
> >
> > Digitalmars-d- learn wrote:
> &g
the various properties on SysTime and passing them to something
like std.format's format to create a string, or there are several packages
on https://code.dlang.org which have functions for doing custom date/time
formatting.
- Jonathan M Davis
On Wednesday, January 17, 2024 11:33:48 PM MST zjh via Digitalmars-d-learn
wrote:
> On Thursday, 18 January 2024 at 04:30:33 UTC, Jonathan M Davis
> wrote:
> but for a lot of code, using auto and size_t makes it
>
> > so that you don't need to use int, and it would be a big
because you'd just be using size_t, which would then be ulong on 64-bit
systems. Obviously, when you do need to convert to int, then that can be
annoying, but for a lot of code, using auto and size_t makes it so that you
don't need to use int, and it would be a big problem in general if the
language made length int.
- Jonathan M Davis
s run into. So, as is often the case, D's metaprogramming capabiltiies
complicate the situation considerably with regards to tooling.
- Jonathan M Davis
On Tuesday, January 16, 2024 1:42:04 PM MST bomat via Digitalmars-d-learn
wrote:
> Wow, that was... exhaustive. Thanks for that. :)
> One more question that I have, though...
>
> On Tuesday, 16 January 2024 at 19:05:43 UTC, Jonathan M Davis
>
> wrote:
> > The downside of
ode
easier, because they make it clear where the symbols are coming from. You do
obviously need to be aware that you could run into problems with them
depending on how you use them, but I don't even recall the last time that I
had a problem due to a selective import. Regardless, obviously, you are
going to have to decide what works for you, and that could change over time.
Both features can definitely help with code encapsulation and with
understanding where the symbols being used are actually coming from, but the
cost-benefit analysis is likely to differ based on how you think and
function.
- Jonathan M Davis
s. I fully expect that there are things that you'd get out of TDPL
that you wouldn't get from Ali's book, so there's definitely something to
said for reading both, but again, whether that makes sense largely depends
on whether you want to deal with figuring out which parts of TDPL are still
valid.
- Jonathan M Davis
ctions, it will work directly with a static array (and should
take it by ref to avoid copying) - at least so long as the function that
it's given compiles properly. Personally, I'd just use a foreach loop and
don't see much point in each at all, but looking at its implementation, it
does look like the OP should be able to use it with static arrays in spite
of the fact that they're not ranges
- Jonathan M Davis
On Tuesday, January 9, 2024 4:13:23 AM MST Alexibu via Digitalmars-d-learn
wrote:
> On Tuesday, 9 January 2024 at 10:44:34 UTC, Jonathan M Davis
>
> wrote:
> > How would it even be possible for a static array to be a range?
> > It has a fixed length. For a type to work as a r
be
careful about the dynamic array (or any ranges which wrap it) escaping from
the scope where the static array is, because if the static array goes out of
scope and is destroyed, then any dynamic arrays referring to it will be
referring to invalid memory, and you'll get undefined behavior. So, w
On Tuesday, January 2, 2024 3:41:55 AM MST Anonymouse via Digitalmars-d-learn
wrote:
> On Monday, 1 January 2024 at 19:49:28 UTC, Jonathan M Davis wrote:
> > [...]
>
> Thank you. Yes, `Foo` is a class for the purposes of inheritance
> -- I left that out of the example.
>
&g
have to deal with the locking primitives yourself as well
as casting away shared to then operate on the AA while it's protected. It's
a bug when you can do pretty much anything with a shared AA other than pass
it around without casting away shared first.
- Jonathan M Davis
n. But if you
want to use a class and use its built-in mutex with synchronized, that works
too. Either way, it makes more sense to pass a shared object containing both
the AA and the mutex around than to pass the AA around by itself given that
the whole point of the mutex is to protect that AA.
- Jonathan M Davis
directory, whether it exists, etc. - and of course, it has
functions for reading in and writing to files.
std.stdio also has some functions for reading from and writing to files, but
the difference there is that it does it in pieces, whereas std.file reads
and writes files as single units (e.g. std.std
ng _deflayer from
code that's marked with @safe, then you're going to get a compilation error.
So, based on what I can see here, it looks like you need to be marking your
functions with @safe where you can, and if any of your code is doing stuff
that isn't guaranteed to be memory-safe (and thus can't be @safe), then
you'll need to make sure that what it's doing is actually memory-safe (in
spite of the fact that the compiler can't guarantee it) and mark it with
@trusted to indicate that you've verified it, and then @safe code can call
it.
- Jonathan M Davis
gt; Nor does replacing 'Dummy' with {}
>
> Suggestions?
Normally, if you're not going to actually use the member variables, then
there's no point in them even being there. However, if you need them there
for alignment purposes, then you can just make them private.
- Jonathan M Davis
king
on the compiler to more easily get an overview of the public symbols within
those modules. But if you're not contributing to those projects, there
really isn't any reason to see those modules.
- Jonathan M Davis
s.
https://github.com/dlang/dmd/blob/master/druntime/src/object.d#L269
- Jonathan M Davis
r[] risks living longer than the char* that it's a slice
of. But if all you're doing is comparing it against a D string, then
presumably, you don't need to keep the char[] around, and you won't have to
allocate a copy.
https://dlang.org/phobos/std_string.html#.fromStringz
- Jonathan M Davis
all
class-specific functions on it, but ideally, once you're dealing with an
interface or base class, you just use it as that and don't need to do
anything class-specific to it. So, if possible, it's generally better to
figure out how to rework your code so that you don't need to set anything
that's class-specific in the parts of the code which deal with the object
through an interface or base class reference.
- Jonathan M Davis
and that's been
debated in the past), but it's unlikely to change at this point.
So, if we were to add something to std.traits for them, it would probably be
something more like isManifestConstant than isEnum. In spite of the keyword
being used, they really aren't intended to be considered enums.
- Jonathan M Davis
On Thursday, November 16, 2023 6:04:43 PM MST Jonathan M Davis via
Digitalmars-d-learn wrote:
> I would suggest that you open up a bug report for it -
> https://issues.dlang.org - and certainly, there's a good argument that what
> you're seeing here is a bug. I fully expe
thus was not dealt with properly
when the other bugs for visibility attributes on aliases were fixed however
many years ago that was now. I very much doubt that what you're seeing is
the intended behavior - or at least I fully expect that if Walter or one of
the other compiler devs sees the issue, they will agree that what you're
trying to do should work.
- Jonathan M Davis
age. And in this case, not only does a template solve the problem quite
easily, but it's solving a problem that only rarely needs to be solved these
days.
So, while some might prefer a language solution, this really isn't the sort
of problem that D is likely to solve in the language at this point.
- Jonathan M Davis
e, but that's going to be _very_ surprising to anyone else using your
project and might cause issues if it's a project that other projects end up
depending on.
- Jonathan M Davis
ny format for converting from strings
to Durations. There are third party libraries on code.dlang.org which
support custom formatting for dates and times (e.g.
https://code.dlang.org/packages/ae), but I'm not familiar enough with any of
them to tell you how to solve your problem with them. That being said, since
you seem to haves strings that are almost in the ISO extendend format, it
should be pretty easy to get them to work with D's standard library.
- Jonathan M Davis
ly different.
E.G. mymodule.d becomes foo/a.d and foo/b.d, with public imports in
mymodule.d like you would have done in mymodule/package.d. You then either
deprecate everything in mymodule.d so that folks will eventually change
their code to use foo/a.d and foo/b.d directly, or you leave the code in the
weird situation of everything being in the foo package, but existing code
continues to import mymodule potentially forever.
- Jonathan M Davis
orts other modules in order to be able to import a single module
and get several modules. Either way, personally, I don't think that that's
something that should typically be done (with package.d or with any module
name), but for whatever reason, some folks seem to love the idea.
- Jonathan M Davis
On Tuesday, October 31, 2023 8:23:28 AM MDT Salih Dincer via Digitalmars-d-
learn wrote:
> On Tuesday, 31 October 2023 at 10:24:56 UTC, Jonathan M Davis
>
> wrote:
> > On Tuesday, October 31, 2023 4:09:53 AM MDT Salih Dincer via
> >
> > Digitalmars-d- learn wrote:
>
wrapper to use in your own code.
- Jonathan M Davis
On Monday, October 16, 2023 12:05:04 PM MDT Paul via Digitalmars-d-learn
wrote:
> On Thursday, 12 October 2023 at 21:20:44 UTC, Jonathan M Davis
>
> wrote:
> > look like?
> >
> > Types can have static members.
> >
> > Basically what it comes down to is t
On Monday, October 16, 2023 12:05:04 PM MDT Paul via Digitalmars-d-learn
wrote:
> On Thursday, 12 October 2023 at 21:20:44 UTC, Jonathan M Davis
>
> wrote:
> > look like?
> >
> > Types can have static members.
> >
> > Basically what it comes down to is t
an access
via their arguments (be it by getting pointers from those arguments or
calling other pure functions on them).
- Jonathan M Davis
to it just means that
they have to remove your post too (which of course means that I'm adding to
the problem as well, but at least now you know).
- Jonathan M Davis
#x27;t be a solution,
since you can't call C functions during CTFE) rather than converting
variables in general to string, then it shouldn't be hard to write a simple
function that converts from an integer to a string. So, if that's all that
you're looking to do, it shouldn't be hard to avoid Phobos. However, you're
still going to need to implement it yourself.
- Jonathan M Davis
he assignment work and if it can statically see that
the lengths of the arrays don't much.
As such, I'm not sure that there's actually anything that the compiler could
do here to catch the problem in the OP's case (at least not without doing
code flow analysis, which isn't going to happen).
- Jonathan M Davis
. E.G.
AliasSeq!(a, b) = doStuff(bar, 2.7);
So, for many programmers, Tuple and tuple from std.typecons are good enough,
and whether we ever get tuples added to the language will largely depend on
whether anyone can come up with a proposal for them that convinces Walter
and Atila that they're worth adding.
Either way, the unpacking of dynamic arrays likely stands no chance
whatsoever of ever being added, because it would require runtime checks to
determine whether the unpacking was valid.
- Jonathan M Davis
r than assigning to foo. And then which elements are assigned to
depends on how much of foo you slice, and how those elements are assigned to
depends on the type of x.
- Jonathan M Davis
compile-time one.
https://dlang.org/spec/template.html#template_constraints
https://dlang.org/spec/version.html#staticif
https://dlang.org/spec/statement.html#if-statement
http://ddili.org/ders/d.en/templates.html
http://ddili.org/ders/d.en/cond_comp.html
http://ddili.org/ders/d.en/if.html
- Jonathan M Davis
mpiled in regardless (and
potentially result in compiler errors if it doesn't work with the type that
that the template is being instantiated with). So, you usually want to use
static if with compile-time tests and not if.
- Jonathan M Davis
lice with two parameters for slicing the range or
container, and then either opIndex or opSlice with no parameters to return a
slice of the entire container (in which case, personally, I'd use opSlice,
because semantically, that's what you're doing, but either should work IIRC).
- Jonathan M Davis
ks in terms
of performance.
Of course, the exact performance characteristics are going to depend on what
you're doing in your program, and whether the approach of D's dynamic arrays
or C++'s std::vector is better depends on what your code is doing, but for
most code, D's app
ex.html#zachy
The video isn't up yet though, since the videos are currently in the process
of getting rendered and uploaded to youtube.
https://forum.dlang.org/thread/rgevjorzaoeylhwii...@forum.dlang.org
- Jonathan M Davis
but I have a variety of items on my todo list.
- Jonathan M Davis
e forum), but that's pretty much it, and even then, that doesn't
remove it from the mailing list, because you can't get an e-mail back once
it's been sent. So, once you send something to the forum, it's out there
forever.
- Jonathan M Davis
On Thursday, September 21, 2023 9:29:17 AM MDT Uranuz via Digitalmars-d-learn
wrote:
> Hello!
> I have some strange problem. I am trying to parse XML files and
> extract some information from it.
> I use library dxml for it by Jonathan M Davis. But I have a
> probleme that I hav
you watch this video from dconf 2016 which discusses
floating point values:
https://www.youtube.com/watch?v=YEUAUnamQiA
- Jonathan M Davis
compile-time
value that gives the size of a type in bytes. In neither case does how it is
calculated have any impact on the performance of the program.
- Jonathan M Davis
evel module, object, you can only
declare your own if you replace the default one, which you might do in some
special situations, but it's not something that you would normally do, and
you can never have both the normal object module and your own in the same
program.
- Jonathan M Davis
https://dlang.org/phobos/std_socket.html#.Socket.hostName
- Jonathan M Davis
- at least if you're not in an
environment where everyone is expected to look at the code itself rather
than at documentation.
- Jonathan M Davis
e it is not full right now)?
In general, system-specific bindings get added to druntime, because someone
who needed them took the time to add them to the right place in druntime
rather than there being an organized effort to add bindings to druntime.
- Jonathan M Davis
ey is on the all-values enum generating the array list.
import std.traits : EnumMembers;
enum Terminator
{
percent = '%',
colon = ':',
qmark = '?'
}
enum terminators = [EnumMembers!Terminator];
- Jonathan M Davis
1 - 100 of 1001 matches
Mail list logo