[Issue 17790] [scope] Escaping pointer possible through array of aggregates
https://issues.dlang.org/show_bug.cgi?id=17790 Walter Brightchanged: What|Removed |Added CC||bugzi...@digitalmars.com --- Comment #1 from Walter Bright --- https://github.com/dlang/dmd/pull/7108 --
Transitive const and function pointers/delegates
I was wondering how transitive const applies to functions. For example would the following declaration: const int delegate(char) be equivalent to: const(int) delegate(char) // I think its this one or: const(int) delegate(const(char)) Would it be different for function instead of delegate?
Re: Open Methods: From C++ to D
On Tuesday, 29 August 2017 at 12:45:50 UTC, Jean-Louis Leroy wrote: On Tuesday, 29 August 2017 at 12:09:01 UTC, Mark wrote: Nice. This does seem superior to the visitor pattern. Here is another example - AST traversal: https://github.com/jll63/openmethods.d/blob/master/examples/acceptnovisitors/source/app.d Thanks for this library. Just a suggestion. Would it possible to use `@openmethod` instead of `@method`?
Re: D as a Better C
On Tue, Aug 29, 2017 at 7:19 PM, Michael V. Franklin via Digitalmars-d-announcewrote: > For example, the following is the most minimal "Hello World" I can make with > D that does not require the -betterC switch, and does not use the official D > runtime. Instead the runtime features required by this program are > implemented in object.d. Thank you for the very helpful example and explanation. -Parke
Re: Compiler scalability. Question inspired by OOM errors seen by Crystal language
On Wednesday, 30 August 2017 at 01:30:30 UTC, Pradeep Gowda wrote: I'm referring to this thread about Crystal -- https://lobste.rs/s/dyitr0/its_fun_program_crystal_is_it_scalable Crystal is strongly typed, but overwhelmingly uses type inference, rather than explicit types. Because Crystal aims to be spiritually—and frequently literally—compatible with Ruby, that’s a problem: to accomplish that, Crystal relies on sometimes-nullable types with implicit structure and implicit unions, such that, frequently, the only way to even begin type inference is to load the entire program’s AST into RAM all at once and then start your massive type inference pass. What you’re seeing in this thread is how a “simple” fix to a YAML parser error reporting hit that problem, causing Crystal to use a critical amount too much RAM and OOM. How does D compare in this regard, especially in cases where `auto` storage class specifiers are used liberally throughout the code base? Auto is not the problem you can easily figure out the return type of function that return a primitive type, and aggregates have to be specified. The problem with D is the memory hogging nature of CTFE and the sheer number of templates that get instantiated when compiling big codebases. Symbol length is also a problem but that eats you dose space not your RAM.
Re: D as a Better C
On Wednesday, 30 August 2017 at 00:29:19 UTC, Parke wrote: But my original question was about what you (Kagamin) called "intermediate D". I was trying to understand what "intermediate D" is, and whether or not I could use "intermediate D" (whatever it is) to produce small(er) executables. "Intermediate D" probably refers to not use the -betterC switch, not linking in the official druntime, and instead implementing the features of D required by your program yourself. For example, the following is the most minimal "Hello World" I can make with D that does not require the -betterC switch, and does not use the official D runtime. Instead the runtime features required by this program are implemented in object.d. object.d module object; alias immutable(char)[] string; struct ModuleInfo { } class Object { } class TypeInfo { bool equals(in void* p1, in void* p2) const { return p1 == p2; } int compare(in void* p1, in void* p2) const { return _xopCmp(p1, p2); } } class TypeInfo_Class : TypeInfo { ubyte[136] ignore; } alias TypeInfo_Class ClassInfo; class TypeInfo_Struct : TypeInfo { ubyte[120] ignore; } extern (C) Object _d_newclass(const ClassInfo ci) { return null; } extern(C) void _d_throwc(Object h) { } class Throwable { } class Error : Throwable { this(string x) { } } extern(C) void _d_throwdwarf(Throwable o) { } extern(C) void _d_dso_registry(void* data) { } // The following code basically replaces the C runtime // extern extern(C) int main(int argc, char** argv); extern(C) void sys_exit(long arg1) { asm { mov RAX, 60; mov RDI, arg1; syscall; } } extern(C) void _start() { auto ret = main(0, null); sys_exit(ret); } private alias extern(C) int function(char[][] args) MainFunc; extern (C) int _d_run_main(int argc, char **argv, MainFunc mainFunc) { // ignore args for now return mainFunc(null); } main.d -- module main; long sys_write(long arg1, in void* arg2, long arg3) { long result; asm { mov RAX, 1; mov RDI, arg1; mov RSI, arg2; mov RDX, arg3; syscall; } return result; } void write(in string text) { sys_write(2, text.ptr, text.length); } void main() { write("Hello\n"); } Building and executing -- On Linux 64-bit compile with: $ dmd -c -fPIC -release object.d main.d -of=main.o Link with: $ ld main.o -o main Report size: $ size main textdata bss dec hex filename 10701872 82950 b86 main Text execution: $ ./main Hello If you link with: $ ld main.o -o main --gc-sections You end up with: $ size main textdata bss dec hex filename 9501688 02638 a4e main This illustration does not require -betterC, but instead requires you to implement a "minimal D runtime" specific to your program, and the features of D that it employs. In this illustration that "minimal D runtime" is object.d. As you can see it is not a polished experience and gets much worse when you start employing more features of D. This could be improved, and in fact, with GDC you need even less useless boilerplate in object.d and may end up with an even smaller executable. (Maybe I'll follow up later with GDC illustration. Right now I don't have a computer with the latest GDC installed). If you try this experiment with LDC, you may end up with a multi-gigabyte file and crash your PC due to https://github.com/ldc-developers/ldc/issues/781 Hopefully we can improve the compiler/runtime implementation so doing this kind of programming won't require so many useless stubs, and users can implement just the features of D that they need for their program without having to rely on the on the blunt and heavy hand of -betterC. Mike
Compiler scalability. Question inspired by OOM errors seen by Crystal language
I'm referring to this thread about Crystal -- https://lobste.rs/s/dyitr0/its_fun_program_crystal_is_it_scalable Crystal is strongly typed, but overwhelmingly uses type inference, rather than explicit types. Because Crystal aims to be spiritually—and frequently literally—compatible with Ruby, that’s a problem: to accomplish that, Crystal relies on sometimes-nullable types with implicit structure and implicit unions, such that, frequently, the only way to even begin type inference is to load the entire program’s AST into RAM all at once and then start your massive type inference pass. What you’re seeing in this thread is how a “simple” fix to a YAML parser error reporting hit that problem, causing Crystal to use a critical amount too much RAM and OOM. How does D compare in this regard, especially in cases where `auto` storage class specifiers are used liberally throughout the code base?
Re: Events in D
On Tuesday, 29 August 2017 at 05:10:25 UTC, bitwise wrote: I needed some C# style events, so I rolled my own. Long story short, the result was unsatisfactory. ` Foo foo; foo.onEvent += (int n) => writeln(n); foo.onEvent += foo.onEvent -= if(foo.onEvent) foo.onEvent(1); ` I implemented one: bt_ok = new IupButton(""); bt_ok.padding = Size(10,2); bt_ok.click += _ok_click; private void bt_ok_click(Object sender, CallbackEventArgs e) { string v = textBox.text; } See also: https://github.com/Heromyth/Iup4D/blob/master/Examples/SimpleDemo/main.d https://github.com/Heromyth/Iup4D/blob/master/Iup4D/toolkit/event.d
Re: D as a Better C
On Wednesday, 30 August 2017 at 00:29:19 UTC, Parke wrote: The above D code yields 445,187 bytes when compiled with -release -betterC. DMD64 D Compiler 2.075.0-b2 on Linux on x86-64. -betterC does virtually nothing on that version of dmd... But my original question was about what you (Kagamin) called "intermediate D". I was trying to understand what "intermediate D" is, and whether or not I could use "intermediate D" (whatever it is) to produce small(er) executables. Regular D with a custom runtime library. You can get as small as 3 KB on Linux (though that is a super bare bones hello world). But note that if you are distributing several executables you might also just use the shared phobos lib too with -defaultlib=libphobos2.so on Linux.
Re: D as a Better C
> On Monday, 28 August 2017 at 22:45:01 UTC, Parke wrote: >> When I write "hello world" in C, the executable is 8,519 bytes. >> When I write "hello world" in D, the executable is 100 times larger: >> 865,179 bytes. On Tue, Aug 29, 2017 at 8:26 AM, Kagamin via Digitalmars-d-announcewrote: > You mean the examples from the blog post > https://dlang.org/blog/2017/08/23/d-as-a-better-c/ give you 800kb > executables? No, I was talking about the below version of "hello world" that I compiled several weeks prior to reading the blog post. import std.stdio; void main() { writeln("Hello, world!"); } The above D code yields 865,179 bytes. Below is the version from the blog post: import core.stdc.stdio; extern (C) int main( int argc, char** argv ) { printf ( "hello world\n" ); return 0; } The above D code yields 445,244 bytes when compiled with -release. The above D code yields 445,187 bytes when compiled with -release -betterC. DMD64 D Compiler 2.075.0-b2 on Linux on x86-64. Still 50 times larger than C. Perhaps it would be smaller with a newer version of DMD. But my original question was about what you (Kagamin) called "intermediate D". I was trying to understand what "intermediate D" is, and whether or not I could use "intermediate D" (whatever it is) to produce small(er) executables. -Parke
Re: Protection attribute in another module
On Tuesday, 29 August 2017 at 15:48:05 UTC, Kagamin wrote: You iterate over string literals: https://dlang.org/spec/traits.html#allMembers I had known that, but I couldn't figure out how to get the identifiers. It turns out that I can loop over getOverloads and it produces the desired result (below). module B; import A; void main() { import std.stdio : writeln; foreach(member; __traits(allMembers, A)) { foreach (t; __traits(getOverloads, A, member)) { writeln(__traits(getProtection, t)); } } }
Re: Events in D
On Tuesday, 29 August 2017 at 20:27:11 UTC, kinke wrote: I like the C# event syntax too and came up with the following D analogon, just to prove that a primitive library-based solution in D is doable in 35 lines and can offer as much comfort as C# here. My current implementation looks basically the same, which is what prompted me to create this thread. Neither of our implementations address the issues I've stated above - and those issues aren't trivial corner cases either.
Re: Beta 2.076.0
-BEGIN PGP SIGNED MESSAGE- Hash: SHA512 On 08/18/2017 02:58 PM, Martin Nowak wrote: > First beta for the 2.076.0 release. > Release Candidate out now! http://dlang.org/download.html#dmd_beta http://dlang.org/changelog/2.076.0.html -BEGIN PGP SIGNATURE- iQIzBAEBCgAdFiEEpzRNrTw0HqEtE8TmsnOBFhK7GTkFAlml3gcACgkQsnOBFhK7 GTm9yg/+JiF+F12kZKNuE0JB6i8DXSbI5/itvG1ja9YFwn6BppjNH6dRtR/5wVnJ Bh8Hz629Q7XoAysAyMcCEdKEKZ1VcHcKs5169AjENpMsvRxzEjEL0I3lXIeU5CFh xqSX+6ucEEh7ZfNn7f7AfZW2trYc76rc3Udyr00y7bmrJKcgTUoqZcmclclP+UUJ mKdk3+g4lxYt7To9M1CAqooBN2bEIosBF/mGjrX7PoQQq25exFfA4sg0rIIb5dS5 U1LnF9Jt3vj9p3R5fGNhci5XzHvjAxfssPMB6i040U0pfmaywWY348QKOzMXlaiw 5sFc0CSf+0R88eXf2Q2JcfXuJ7RC5hhCiDYKvaFjLOacRHnlAK78RPs/Og5DDWis el6D83fOnADUqMWRFEe9+JX1Y0kD/2F1f8bHhF5UobTngSWCurRRbUwOSZgNr8Xh nrh78PNAn15/bRftXtoiD9tS/B5TLZpNVr2NwpaPv/Wl/90BQSyGJB8HmtScFxHp Kys6MbFQz+0TLyk9Qe7tX0libOB0Npegb1m5dwJGTDTg8pQPo2KRYnks8K/UZEY7 Ew9up2x2n2FId7vC/qsMKU4ItKfbKg6mNo6KA0wrVk3pehA7AfzqyMJ0Txhe/cKJ bw2T1jRkF+q3R19y9tbIeZM8qHzraLmhVXETYiZ6HCXBIGWIj9A= =lBFr -END PGP SIGNATURE-
Re: Casting non-aliased mutable arrays to immutable in return values
On Tuesday, 29 August 2017 at 16:41:48 UTC, Jonathan M Davis wrote: Regardless, using assumeUnique or using a pure function to construct the object and implicitly convert it to immutable works for types in general. - Jonathan M Davis I'm, as always, grateful for your thorough answers, Jonathan. Thank you.
Re: Events in D
On Tuesday, 29 August 2017 at 05:10:25 UTC, bitwise wrote: I needed some C# style events, so I rolled my own. Long story short, the result was unsatisfactory. [...] Anyways, I threw together some code while thinking about what an event may look like in D: [...] I like the C# event syntax too and came up with the following D analogon, just to prove that a primitive library-based solution in D is doable in 35 lines and can offer as much comfort as C# here. struct Event(Args) { alias CB = void delegate(Args); CB[] callbacks; void opOpAssign(string op)(CB handler) if (op == "+" || op == "-") { static if (op == "+") callbacks ~= handler; else { import std.algorithm.mutation : remove; callbacks = callbacks.remove!(x => x == handler); } } void opOpAssign(string op)(void function(Args) handler) if (op == "+" || op == "-") { import std.functional : toDelegate; opOpAssign!op(toDelegate(handler)); } void opCall(Args args) { foreach (cb; callbacks) cb(args); } bool opCast(T)() if (is(T == bool)) { return callbacks.length != 0; } } The following test code prints the expected output: struct S { int a; void handler(int arg) { printf("S.handler: this.a = %d, arg = %d\n", a, arg); } } void func(int arg) { printf("func: arg = %d\n", arg); } void main() { Event!int onChanged; auto s = S(666); assert(!onChanged); onChanged += (int arg) { printf("lambda: arg = %d\n", arg); }; onChanged += onChanged += assert(onChanged); onChanged(1); onChanged -= onChanged(2); onChanged -= onChanged(3); }
Re: Events in D
On Tuesday, 29 August 2017 at 16:25:33 UTC, Jonathan Marler wrote: [...] While responding to your question, I provided an example for needing access to the host's data members (Mutex), but failed to provide an example of needing an extra delegate-to-host for an event. I just hit that case though, and it's timers/animations. For any app where battery life is a concern, you can't just spin for no reason. So when you add a handler to a timer/animation event, you have to kick off whatever timer handles the animation if it's not running. Likewise, you have to stop it when all events have been removed.
Re: xml utf-8 encoding error
On Tuesday, 29 August 2017 at 15:55:50 UTC, Adam D. Ruppe wrote: On Tuesday, 29 August 2017 at 04:41:34 UTC, graw-prog wrote: I'm not sure what the problem is. It seems to be may the lowercase 'utf-8' in the charset section but I'm not sure if the problem is some mistake I made, a bug in DMD or just lousy xml. Either way is there any way around this issue? It looks like a bug in Phobos: http://dpldocs.info/experimental-docs/source/std.net.curl.d.html#L2470 That's where it populates the charset that it passes to Phobos' (woefully inadequate btw) encoding decoder... and it doesn't handle the quotes correctly according to the http standard. I guess you could probably hack it by editing your copy of Phobos or change your server to remove the quotes. Thank you for the explanation. I guess I'll have to take a look in phobos and see if I can figure out how to make it work. I'm getting the data using the api built into the tv so I don't think I can change anything on the server side. Thank you everybody for your help.
Re: Missing array element
On 08/29/2017 11:20 AM, Vino.B wrote: string[] a = ["test1", "test2", "test4"]; string[] b = ["test2", "test4"]; Required output: "test1" You're looking for setDifference: https://dlang.org/phobos/std_algorithm_setops.html#.setDifference Ali
Re: Missing array element
On Tuesday, 29 August 2017 at 18:20:38 UTC, Vino.B wrote: Hi, Can any one help me on the below program, as I need the missing element for array "a" to be printed when compared with array "b" Program: import std.stdio, std.array, std.algorithm; string[] a = ["test1", "test2", "test4"]; string[] b = ["test2", "test4"]; void main () { auto m = mismatch(a,b); writeln(m[0]); writeln(m[1]); } Output: ["test1", "test2", "test4"] ["test2", "test4"] Required output: "test1" From, Vino.B The mismatch function doesn't work how your expecting it to. It compares the ith element in a with the ith element in b, until they encounter an element that is not equal. It then returns all elements including and beyond i, for both arrays. In this case the first element does not match, and therefore it returns the entire contents of both arrays.
Missing array element
Hi, Can any one help me on the below program, as I need the missing element for array "a" to be printed when compared with array "b" Program: import std.stdio, std.array, std.algorithm; string[] a = ["test1", "test2", "test4"]; string[] b = ["test2", "test4"]; void main () { auto m = mismatch(a,b); writeln(m[0]); writeln(m[1]); } Output: ["test1", "test2", "test4"] ["test2", "test4"] Required output: "test1" From, Vino.B
Re: Output range with custom string type
On Tuesday, 29 August 2017 at 09:59:30 UTC, Jacob Carlborg wrote: [...] But if I keep the range internal, can't I just do the allocation inside the range and only use "formattedWrite"? Instead of using both formattedWrite and sformat and go through the data twice. Then of course the final size is not known before allocating. Certainly, that's what dynamic arrays (aka vectors, e.g. std::vector in C++ STL) are for: --- import core.exception; import std.stdio; import std.experimental.allocator; import std.algorithm; struct PoorMansVector(T) { private: T[]store; size_t length; IAllocator alloc; public: @disable this(this); this(IAllocator alloc) { this.alloc = alloc; } ~this() { if (store) { alloc.dispose(store); store = null; } } void put(T t) { if (!store) { // Allocate only once for "small" vectors store = alloc.makeArray!T(8); if (!store) onOutOfMemoryError(); } else if (length == store.length) { // Growth factor of 1.5 auto expanded = alloc.expandArray!char(store, store.length / 2); if (!expanded) onOutOfMemoryError(); } assert (length < store.length); moveEmplace(t, store[length++]); } char[] release() { auto elements = store[0..length]; store = null; return elements; } } char[] sanitize(string value, IAllocator alloc) { import std.format : formattedWrite, sformat; auto r = PoorMansVector!char(alloc); ().formattedWrite!"'%s'"(value); // do not copy the range return r.release(); } void main() { auto s = sanitize("foo", theAllocator); scope (exit) theAllocator.dispose(s); writeln(s); } --- Do be aware that the above vector is named "poor man's vector" for a reason, that's a hasty write down from memory and is sure to contain bugs. For better vector implementations you can use at collection libraries such as EMSI containers; my own attempt at a DbI vector container can be found here [1] [1] https://github.com/Calrama/libds/blob/6a1fc347e1f742b8f67513e25a9fdbf79f007417/src/ds/vector.d
Re: Events in D
On Tuesday, 29 August 2017 at 05:10:25 UTC, bitwise wrote: [...] I think I should clarify for anyone with limited C# experience, that I'm talking about the custom-event syntax, not the regular one-liner syntax: class MyClass { Object myLock; EventHandler _completed; public event EventHandler Completed { add { lock (myLock) { _completed = (EventHandler)Delegate.Combine(_completed, value); // update some other state } } remove { lock(myLock) { _completed = (EventHandler)Delegate.Remove(_completed, value); // update some other state } } } void RaiseCompleted() { EventHandler c = null; lock(myLock) { c = _completed; } if(c != null) c(); } }
Re: Events in D
On Tuesday, 29 August 2017 at 16:25:33 UTC, Jonathan Marler wrote: On Tuesday, 29 August 2017 at 05:10:25 UTC, bitwise wrote: [...] I'm confused, C# has the same problem with events. They are delegates which under the hood have 2 pointers, a pointer to the method and a pointer to an instance of the object. How would that be different than if you used delegates in your D library? You're right that a D event would also incur the same cost for adding a delegate to an event. However, there are additional cost and problems that come with having the event in a self-contained struct that sits in some host object. 1) additional memory cost of a pointer to the event's host object if access to a shared mutex, lock, or anything is needed (even if no events are attached). 2) additional memory cost of one or more delegates to methods of the host object if any special logic is needed to update the host object's state in some way when an event is added or removed (even if no events are attached). Consider how bad this could get when an object needs 4-5, or even more events. 3) inflexibility. It's impossible to satisfy everything that one may need with a library implementation, and any attempt at doing so would result in an extremely bloated, and still inadequate abstraction. For example, @nogc/@safe/etc attributes, choice of custom internal container/allocator, signature of callbacks to host objects, and I'm sure there's more. The solution I presented is very simple and easily accounts for all of the above stated problems - No memory overhead, direct access to host object's members, choice of any attributes or event storage you want, straight-forward syntax.
Re: Casting non-aliased mutable arrays to immutable in return values
On Tuesday, August 29, 2017 16:09:17 Per Nordlöw via Digitalmars-d-learn wrote: > Is it recommended to cast an unaliased array to `immutable` after > it has been initialized? > > The reason for asking is that I would like the following function > > void[] rawReadNullTerminated(string path) > @safe > { > import std.stdio : File; > auto file = File(path, `rb`); > > import std.array : uninitializedArray; > ubyte[] data = uninitializedArray!(ubyte[])(file.size + 1); > file.rawRead(data); > data[file.size] = 0; // null terminator for sentinel > > return data;// TODO can we cast this to > `immutable(void)[]`? > } > > to have an immutable return type. > > I'm aware of that I need to verify the contexts as UTF-8 if I > want to treat it as text. It's perfectly legitimate to construct an object as mutable and then cast it to immutable if there are no other mutable references to it - that's what std.exception.assumeUnique is for. It does the cast for you while documenting your intent. However, the better solution if you can do it is to create the object in a pure function that returns it. Then, it can be implicitly converted to immutable so long as the compiler can guarantee that the return value was not passed to the function. In this particular case, you'd probably create a pure, nested function that took the File object and returned the array. Now, as for immutable(void)[], that seems pretty weird to me. Normally, when folks use void[], it doesn't have any qualifiers on it. But I don't know that there's actually a problem using qualifiers on it. Certainly, it compiles. I'd probably just use immutable(ubyte)[] and not anything with void, but this is obviously just a snippet of your code, and I have no idea what the rest of it is doing, so something with void instead of ubyte may very well be the correct solution. You'll obviously have to be the judge of that. But pretty much the only time that I'd use any kind of void array though is when accepting arbitrary arrays of data that is going to be converted to bytes (e.g. for a socket). I wouldn't pass it around. I don't know what other folks would do though. Regardless, using assumeUnique or using a pure function to construct the object and implicitly convert it to immutable works for types in general. - Jonathan M Davis
Re: Editor recommendations for new users.
On Tuesday, 29 August 2017 at 14:05:13 UTC, Ryion wrote: On Monday, 28 August 2017 at 21:17:19 UTC, Moritz Maxeiner wrote: Why "again"? You've not stated so before AFAICT. Regardless, I disagree that discussing the validity of recommendations in a thread specifically made to gather such recommendations is a distraction from the topic; I would contend that it lies at the heart of the topic. The poster asked for programs that fit his (vague) criteria, it is NOT up to you to determine what those criteria are We're repeating ourselves here, so we're going to have to agree to disagree, as I don't agree that that's what I was doing. and then belittle people there posts that try to help out with there own recommendations. The fact that you can not see this even now, really is a issue. I don't consider the way I argue to be belittling and I resent the accusation. Side point: DlangIDE invalidates my recommendation, as well And i am not referring to this topic alone or those that i personally post in. There are many where the same patterns are viable and i notice the pattern, that its always your name next to those posts. Is it so hard for you to not always override topics here and constant "straw man" or other terms calling. I have to point out that when I attribute "straw man" to a quote, it's because the author of that quote has responded to something I wrote, but argued against a point that I did not make, which is a logical fallacy. The same applies to other such fallacies such as "red herring" and if you do catch me in one, I do hope you point it out, as it is hard to see when one is committing one oneself. And i use this term because because you constantly write "irrelevant", "straw man argumentation", "but I don't care" and other belittling statements that seem to indicate that your opinion means more then others. I don't see how pointing out logical fallacies constitutes belittling (again, please do point them out if you catch me in one). W.r.t. the "I don't care" (I assume you refer to the website thread): If I perceive someone trying to engage me in a topic I have no interest in after I've commented about general procedure (which applies to the topic being turned from idea to tangible result) I can either ignore them, or point out that it doesn't interest me. I consider the first option to be ruder. Lastly the "irrelevant": If someone disagrees with me dismissing their argument like that I welcome a counter argument as to why they do consider it relevant to the point I was making in the quote they replied to. Or how you supposedly do not care and have no issue pointing it out half a dozen times. I pointed it out again when despite earlier comment(s) on the subject the attempt to engage me in it was made again. It gets very fast tiresome. You are the only poster that i see here that is non-stop doing this. If you do not like something or find it irrelevant, then do not respond to it. I generally don't; if someone responds either to me, or posts in a discussion I've joined, that's another matter, though. But they way you act, like posts are below or irrelevant to you... If they were I wouldn't take the time to respond. I point these things in responses to me out because I hope for a reply containing an actual counter argument to the point I was making. This is the "again" i refer to. You do this is a lot of topics. You dissect people there posts and write how it is irrelevant to you or some other clever looking down terminology. It totally distracts from the topic at hand and frankly, makes people less likely to continue topics. I strongly disagree that pointing out logical fallacies distracts from the topic at hand, because that's what logical fallacies do. W.r.t. post dissection: Addressing individual points allows the exchange of specific arguments and counter arguments. Its this kind of attitude that in MY personal opinion makes this mailing board toxic for new users. While you are not impolite, the way you act upon people the posts makes it hard to have a honest discussion with you without it turning off-topic or simply scaring away people. I'm not sure if you're making the point that you want to write things to me that you don't want to expose others to, or that you don't feel that you can have a discussion with me on account of how I write. For the former: You can send me a private email. For the latter: The best I can do is assure you that I'll refrain from responding to you first in a thread (unless there are exceptional circumstances); if you respond to me, that's another matter. So again polity again, to refrain from acting like this and let people have there own opinion without you dissecting every piece. Again, if someone replies to me with a logical fallacy, I will point that out; the same way I would expect them to point it out if I were to do it. I will also address the
Re: Casting non-aliased mutable arrays to immutable in return values
On 08/29/2017 09:09 AM, Per Nordlöw wrote: Is it recommended to cast an unaliased array to `immutable` after it has been initialized? The reason for asking is that I would like the following function void[] rawReadNullTerminated(string path) @safe { import std.stdio : File; auto file = File(path, `rb`); import std.array : uninitializedArray; ubyte[] data = uninitializedArray!(ubyte[])(file.size + 1); file.rawRead(data); data[file.size] = 0; // null terminator for sentinel return data;// TODO can we cast this to `immutable(void)[]`? } to have an immutable return type. I'm aware of that I need to verify the contexts as UTF-8 if I want to treat it as text. Yes and assumeUnique does exactly that: https://dlang.org/library/std/exception/assume_unique.html Further, if your function is pure, the cast is implicit for the caller: void[] foo() pure { return new void[](10); } void main() { void[] a = foo(); immutable(void)[] b = foo();// works } Ali
Re: Events in D
On Tuesday, 29 August 2017 at 05:10:25 UTC, bitwise wrote: I needed some C# style events, so I rolled my own. Long story short, the result was unsatisfactory. Library based events are inadequate for basically the same reasons as library based properties (often suggested/attempted in C++). The problem is that the properties/events don't have access to the fields or methods of the containing object, and as such, incur the cost of an extra pointer per event/property, or worse, a delegate if custom behavior per event is needed, in order to provide that access. I'm confused, C# has the same problem with events. They are delegates which under the hood have 2 pointers, a pointer to the method and a pointer to an instance of the object. How would that be different than if you used delegates in your D library?
Re: xml utf-8 encoding error
On Tuesday, 29 August 2017 at 15:55:50 UTC, Adam D. Ruppe wrote: http://dpldocs.info/experimental-docs/source/std.net.curl.d.html#L2470 Ow, annotated sources, cool. pre { box-sizing: border-box; overflow: auto; max-width: 800px; /* The script sets the real one */ max-width: calc(80vw - 16em - 4em); } Hmm... AFAIK free side space on pages is left so that the content is not too wide in characters, not because people like free side space :) But for preformatted text such limit makes little sense, it's only for word-wrapped text. I'd say code should take all the width it wants.
Casting non-aliased mutable arrays to immutable in return values
Is it recommended to cast an unaliased array to `immutable` after it has been initialized? The reason for asking is that I would like the following function void[] rawReadNullTerminated(string path) @safe { import std.stdio : File; auto file = File(path, `rb`); import std.array : uninitializedArray; ubyte[] data = uninitializedArray!(ubyte[])(file.size + 1); file.rawRead(data); data[file.size] = 0; // null terminator for sentinel return data;// TODO can we cast this to `immutable(void)[]`? } to have an immutable return type. I'm aware of that I need to verify the contexts as UTF-8 if I want to treat it as text.
Re: xml utf-8 encoding error
On Tuesday, 29 August 2017 at 04:41:34 UTC, graw-prog wrote: I'm not sure what the problem is. It seems to be may the lowercase 'utf-8' in the charset section but I'm not sure if the problem is some mistake I made, a bug in DMD or just lousy xml. Either way is there any way around this issue? It looks like a bug in Phobos: http://dpldocs.info/experimental-docs/source/std.net.curl.d.html#L2470 That's where it populates the charset that it passes to Phobos' (woefully inadequate btw) encoding decoder... and it doesn't handle the quotes correctly according to the http standard. I guess you could probably hack it by editing your copy of Phobos or change your server to remove the quotes.
Re: xml utf-8 encoding error
On 08/29/2017 05:41 PM, Kagamin wrote: On Tuesday, 29 August 2017 at 04:41:34 UTC, graw-prog wrote: < Content-Type: text/xml; charset="utf-8" Should be Content-Type: text/xml; charset=utf-8 HTTP allows a quoted string there. https://tools.ietf.org/html/rfc7231#section-3.1.1.1
Re: Protection attribute in another module
You iterate over string literals: https://dlang.org/spec/traits.html#allMembers
Re: xml utf-8 encoding error
On Tuesday, 29 August 2017 at 15:41:58 UTC, Kagamin wrote: Should be Content-Type: text/xml; charset=utf-8 I'm pretty sure both are equally legal.
Re: xml utf-8 encoding error
On Tuesday, 29 August 2017 at 04:41:34 UTC, graw-prog wrote: < Content-Type: text/xml; charset="utf-8" Should be Content-Type: text/xml; charset=utf-8
Re: D as a Better C
On Monday, 28 August 2017 at 22:45:01 UTC, Parke wrote: When I write "hello world" in C, the executable is 8,519 bytes. When I write "hello world" in D, the executable is 100 times larger: 865,179 bytes. You mean the examples from the blog post https://dlang.org/blog/2017/08/23/d-as-a-better-c/ give you 800kb executables?
Re: C++ / Why Iterators Got It All Wrong
On 8/29/17 9:34 AM, jmh530 wrote: On Tuesday, 29 August 2017 at 13:23:50 UTC, Steven Schveighoffer wrote: Interesting. It reminds me a bit of cursors for dcollections. In there, a cursor is a 0 or 1 element range. The one element range points at an element, the 0 element range points at a border. You can use cursors to compose ranges. https://github.com/schveiguy/dcollections I was thinking this exact same thing when I got to the Element part of it. The mach library also makes use of cursors. https://github.com/pineapplemachine/mach.d I'm not entirely sure how if I grok how the Border thing they are talking about works. A border points between elements. It's like the end element in a standard STL container, it's not really pointing at an element, but one past the last element. It can be handy when specifying ranges. I.e. exclusive or inclusive ranges. My gut feeling is that the splitting of types between elements and borders is too much machinery, but I haven't seen it in practice to make a fair judgment. -Steve
Re: LDC 1.4.0-beta1
On Tuesday, 29 August 2017 at 13:11:44 UTC, kinke wrote: On Tuesday, 29 August 2017 at 12:46:16 UTC, Andrea Fontana wrote: On Saturday, 26 August 2017 at 22:35:11 UTC, kinke wrote: * Shipping with ldc-build-runtime, a small D tool to easily (cross-)compile the runtime libraries yourself. Have anyone ever tried to compile a linux version of ldc that generates windows executables? Andrea Yep, I even mentioned it prominently in the 1.3 release log. See https://github.com/ldc-developers/ldc/pull/2142#issuecomment-304472412. That was before ldc-build-runtime though; I simply used druntime/Phobos from the prebuilt Win64 package. Ooh, sweet! I might try this if I can't get LDC to build on windows and just build the libs from my mac instead.
[Issue 17780] Malformed DDOC links in std.range
https://issues.dlang.org/show_bug.cgi?id=17780 --- Comment #4 from github-bugzi...@puremagic.com --- Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/cf422b0521d6b63ebfc50dd7ae9e273408b49b39 fix issue 17780 - Malformed DDOC links in std.range https://github.com/dlang/phobos/commit/694d87fe02f9ca062e89d7434651b8f6cc59f912 Merge pull request #5708 from BBasile/issue-17780-stable --
Re: LDC 1.4.0-beta1
On Tuesday, 29 August 2017 at 13:11:44 UTC, kinke wrote: On Tuesday, 29 August 2017 at 12:46:16 UTC, Andrea Fontana wrote: On Saturday, 26 August 2017 at 22:35:11 UTC, kinke wrote: * Shipping with ldc-build-runtime, a small D tool to easily (cross-)compile the runtime libraries yourself. Have anyone ever tried to compile a linux version of ldc that generates windows executables? Andrea Yep, I even mentioned it prominently in the 1.3 release log. See https://github.com/ldc-developers/ldc/pull/2142#issuecomment-304472412. That was before ldc-build-runtime though; I simply used druntime/Phobos from the prebuilt Win64 package. Is there also a wiki page about this?
Re: Editor recommendations for new users.
On Monday, 28 August 2017 at 21:17:19 UTC, Moritz Maxeiner wrote: Why "again"? You've not stated so before AFAICT. Regardless, I disagree that discussing the validity of recommendations in a thread specifically made to gather such recommendations is a distraction from the topic; I would contend that it lies at the heart of the topic. The poster asked for programs that fit his (vague) criteria, it is NOT up to you to determine what those criteria are and then belittle people there posts that try to help out with there own recommendations. The fact that you can not see this even now, really is a issue. And i am not referring to this topic alone or those that i personally post in. There are many where the same patterns are viable and i notice the pattern, that its always your name next to those posts. Is it so hard for you to not always override topics here and constant "straw man" or other terms calling. And i use this term because because you constantly write "irrelevant", "straw man argumentation", "but I don't care" and other belittling statements that seem to indicate that your opinion means more then others. Or how you supposedly do not care and have no issue pointing it out half a dozen times. It gets very fast tiresome. You are the only poster that i see here that is non-stop doing this. If you do not like something or find it irrelevant, then do not respond to it. But they way you act, like posts are below or irrelevant to you... This is the "again" i refer to. You do this is a lot of topics. You dissect people there posts and write how it is irrelevant to you or some other clever looking down terminology. It totally distracts from the topic at hand and frankly, makes people less likely to continue topics. Its this kind of attitude that in MY personal opinion makes this mailing board toxic for new users. While you are not impolite, the way you act upon people the posts makes it hard to have a honest discussion with you without it turning off-topic or simply scaring away people. So again polity again, to refrain from acting like this and let people have there own opinion without you dissecting every piece. Its turns topic off-topic and adds no value to the discussion. I await your next well written comment how what i wrote is irrelevant and how you do not notice this behavior. This site really needs a proper forum with the ability to block specific posters and make this board less toxic. Because 99.9% of the people here are nice but your behavior is hard to deal with. And i am sure you will disagree with this. Stay out of my posts and stop looking down on people and we will get along. This is my last post on this off-topic issue.
Re: C++ / Why Iterators Got It All Wrong
On Tuesday, 29 August 2017 at 13:23:50 UTC, Steven Schveighoffer wrote: Interesting. It reminds me a bit of cursors for dcollections. In there, a cursor is a 0 or 1 element range. The one element range points at an element, the 0 element range points at a border. You can use cursors to compose ranges. https://github.com/schveiguy/dcollections I was thinking this exact same thing when I got to the Element part of it. The mach library also makes use of cursors. https://github.com/pineapplemachine/mach.d I'm not entirely sure how if I grok how the Border thing they are talking about works.
Re: C++ / Why Iterators Got It All Wrong
On Tuesday, 29 August 2017 at 13:23:50 UTC, Steven Schveighoffer wrote: In Phobos, find gives you a range where the first element is the one you searched for, and the last element is the end of the original range. But what if you wanted all the data *up to* the element instead? What if you just wanted to look at that specific element? So we need several functions that do this, and it's not always clear how to do it correctly, and it's difficult to compose one function from the other. With iterators, it's simple. -Steve I was about to whine about exactly this, but thought it would be off topic ;) I see "trim_left" in the slides which I'm guessing refers to what D calls "find". IMO, "trim_left" is a much better name. "find" should not return elements you didn't ask for, it should return a range of length 1 or 0.
Re: C++ / Why Iterators Got It All Wrong
On 8/29/17 8:50 AM, Robert M. Münch wrote: Maybe of interest: https://www.think-cell.com/en/career/talks/iterators/#1 I haven't read everything, so not sure if it worth to take a look. Interesting. It reminds me a bit of cursors for dcollections. In there, a cursor is a 0 or 1 element range. The one element range points at an element, the 0 element range points at a border. You can use cursors to compose ranges. https://github.com/schveiguy/dcollections Not sure how useful it is to have them be separate types. It can be nice I suppose. But one thing I love about iterators/cursors is that something like find doesn't assume what data you are interested in. In Phobos, find gives you a range where the first element is the one you searched for, and the last element is the end of the original range. But what if you wanted all the data *up to* the element instead? What if you just wanted to look at that specific element? So we need several functions that do this, and it's not always clear how to do it correctly, and it's difficult to compose one function from the other. With iterators, it's simple. -Steve
Re: C++ / Why Iterators Got It All Wrong
On Tuesday, 29 August 2017 at 12:50:08 UTC, Robert M. Münch wrote: Maybe of interest: https://www.think-cell.com/en/career/talks/iterators/#1 I haven't read everything, so not sure if it worth to take a look. "superseded" is the wrong word, as ranges cannot do everything iterators can.
Re: LDC 1.4.0-beta1
On Tuesday, 29 August 2017 at 12:46:16 UTC, Andrea Fontana wrote: On Saturday, 26 August 2017 at 22:35:11 UTC, kinke wrote: * Shipping with ldc-build-runtime, a small D tool to easily (cross-)compile the runtime libraries yourself. Have anyone ever tried to compile a linux version of ldc that generates windows executables? Andrea Yep, I even mentioned it prominently in the 1.3 release log. See https://github.com/ldc-developers/ldc/pull/2142#issuecomment-304472412. That was before ldc-build-runtime though; I simply used druntime/Phobos from the prebuilt Win64 package.
Re: Events in D
On Tuesday, 29 August 2017 at 11:26:36 UTC, Vadim Lopatin wrote: DlangUI includes signal/slot event implementation. https://github.com/buggins/dlangui/blob/master/src/dlangui/core/signals.d Again, this is a library implementation which suffers from the problems described in the original post.
Re: Events in D
On Tuesday, 29 August 2017 at 08:05:48 UTC, Andrea Fontana wrote: On Tuesday, 29 August 2017 at 05:10:25 UTC, bitwise wrote: [...] static if(op == "+") [...] Maybe "~"? Usually "+" means "sum" not "add"/"concat". Anyway I remember that something similar was used on DFL [1] [1] http://www.dprogramming.com/dfl.php True that "~" would be more D-like, but then "-" wouldn't make sense. Also, DFL must be using a library implementation, which means it's limited as I've described above.
C++ / Why Iterators Got It All Wrong
Maybe of interest: https://www.think-cell.com/en/career/talks/iterators/#1 I haven't read everything, so not sure if it worth to take a look. -- Robert M. Münch http://www.saphirion.com smarter | better | faster
Re: LDC 1.4.0-beta1
On Saturday, 26 August 2017 at 22:35:11 UTC, kinke wrote: * Shipping with ldc-build-runtime, a small D tool to easily (cross-)compile the runtime libraries yourself. Have anyone ever tried to compile a linux version of ldc that generates windows executables? Andrea
Re: Open Methods: From C++ to D
On Tuesday, 29 August 2017 at 12:09:01 UTC, Mark wrote: Nice. This does seem superior to the visitor pattern. Here is another example - AST traversal: https://github.com/jll63/openmethods.d/blob/master/examples/acceptnovisitors/source/app.d
Re: C callbacks getting a value of 0! Bug in D?
On 8/28/17 9:34 PM, Johnson Jones wrote: produces 4 on both x86 and x64. So, I'm not sure how you are getting 8. Yes, this is exactly why you should use c_long and c_ulong, because just using int makes it not portable to other systems. -Steve
Re: Open Methods: From C++ to D
On Monday, 28 August 2017 at 12:19:26 UTC, Mike Parker wrote: Jean-Louis Leroy posted about his open methods library here in the forums some time ago. Now, he's written a blog post that explains what open methods are, and describes the D implementation and how it compares to his C++ library. The blog: https://dlang.org/blog/2017/08/28/open-methods-from-c-to-d/ Reddit: https://www.reddit.com/r/programming/comments/6wj0ev/open_methods_from_c_to_d/ Nice. This does seem superior to the visitor pattern.
Re: Events in D
On Tuesday, 29 August 2017 at 05:10:25 UTC, bitwise wrote: I needed some C# style events, so I rolled my own. Long story short, the result was unsatisfactory. Library based events are inadequate for basically the same reasons as library based properties (often suggested/attempted in C++). The problem is that the properties/events don't have access to the fields or methods of the containing object, and as such, incur the cost of an extra pointer per event/property, or worse, a delegate if custom behavior per event is needed, in order to provide that access. One obvious example would be synchronized properties/events. Anyways, I threw together some code while thinking about what an event may look like in D: DlangUI includes signal/slot event implementation. https://github.com/buggins/dlangui/blob/master/src/dlangui/core/signals.d
[Issue 8882] map, filter, iota and zip in pure (and nothrow) functions
https://issues.dlang.org/show_bug.cgi?id=8882 ZombineDevchanged: What|Removed |Added Status|RESOLVED|REOPENED CC||petar.p.ki...@gmail.com Resolution|FIXED |--- --- Comment #8 from ZombineDev --- While, the OP code compiles, zip is not yet nothrow. See: ``` import std.algorithm: map, filter; import std.range: iota, zip, array; import std.typecons : tuple; auto get() pure nothrow { auto m = map!q{a * a}([1, 2, 3]); auto f = filter!q{ a > 1 }([1, 2, 3]); auto i = iota(1, 10, 2); auto z = zip([1, 2, 3], [10, 20, 30]); return tuple(m.array, f.array, i.array, z.array); } void main() { import std.stdio; writeln(get()); } ``` test.d(11): Error: function std.array.array!(Zip!(int[], int[])).array is not nothrow test.d(4): Error: nothrow function test.get may throw --
Re: Accessing outer class attribute from inner struct
On Tuesday, 29 August 2017 at 08:30:24 UTC, Moritz Maxeiner wrote: On Tuesday, 29 August 2017 at 07:59:40 UTC, Andre Pany wrote: On Monday, 28 August 2017 at 23:12:40 UTC, Moritz Maxeiner wrote: In both cases S doesn't inherently how about C, which means a solution using default initialization is not feasible, as S.init can't know about any particular instance of C. I don't think there's any way for you to avoid using a class constructor. Thanks for the explanation. I now tried to use a class and use a static opIndex. But it seems from a static method you also cannot access the attributes of a outer class :) A nested class' outer property (when nested inside another class) is a class reference, which means we not only require a class instance of the outer class to reference, but also a class instance of the nested class to store said class reference to the other class in. A static class method (by definition) is invoked without a class instance. The two are inherently incompatible. [...] This seems like an unnecessary limitation... I can only recommend reading the language specification w.r.t, nested classes [1] if it seems that way to you, because it is not. [1] https://dlang.org/spec/class.html#nested I think I found a solution which fulfills all goals but I have to try it out. A property method "Columns" will return an initialized struct "ColumnsArray" as proposed by you. This should nicely work as string mixin. Thanks for your help. Kind regards André
[Issue 17790] [scope] Escaping pointer possible through array of aggregates
https://issues.dlang.org/show_bug.cgi?id=17790 ZombineDevchanged: What|Removed |Added CC||petar.p.ki...@gmail.com --
Re: Output range with custom string type
On 2017-08-28 23:45, Moritz Maxeiner wrote: If you want the caller to be just in charge of allocation, that's what std.experimental.allocator provides. In this case, I would polish up the old "format once to get the length, allocate, format second time into allocated buffer" method used with snprintf for D: --- test.d --- import std.stdio; import std.experimental.allocator; struct CountingOutputRange { private: size_t _count; public: size_t count() { return _count; } void put(char c) { _count++; } } char[] sanitize(string value, IAllocator alloc) { import std.format : formattedWrite, sformat; CountingOutputRange r; ().formattedWrite!"'%s'"(value); // do not copy the range auto s = alloc.makeArray!char(r.count); scope (failure) alloc.dispose(s); // This should only throw if the user provided allocator returned less // memory than was requested return s.sformat!"'%s'"(value); } void main() { auto s = sanitize("foo", theAllocator); scope (exit) theAllocator.dispose(s); writeln(s); } -- I guess that would work. But if I keep the range internal, can't I just do the allocation inside the range and only use "formattedWrite"? Instead of using both formattedWrite and sformat and go through the data twice. Then of course the final size is not known before allocating. -- /Jacob Carlborg
[Issue 8494] Return value for Tuple.opAssign
https://issues.dlang.org/show_bug.cgi?id=8494 ZombineDevchanged: What|Removed |Added CC||petar.p.ki...@gmail.com --- Comment #3 from ZombineDev --- You're misunderstanding the OP. The whole point of this enhancement request is to make T and Tuple!T interchangeable. Changing the return type of `bar` misses the point completely. Essentially what this OP is asking is: 1. Tuple.opAssign should return `this` (the object being modified) 2. Tuple!T should implicitly convert to T. This comes from a higher-level goal that type constructors should be indistinguishable from built-in types - there should be nothing that user-defined can't do, that a built-in type can. Razvan, please refrain from closing valid enhancement requests. 1-2 years ago bearophile was one of the most active community members and many of his ideas helped shape the language and the standard library. While some of his enhancement request are a bit vague and not always clear, quite often there are good ideas in there. In particular, a future proposal for built-in tuples may greatly benefit from many of his litmus tests. --
Help ME Drive SSD1963
I am involving in an electronic project--make a set of control board. The MCU is 103ZET6 while the driving chip is SSD1963 and the screen is AT070TN92. However,I don’t know why the screen can’t be lighted? IF you need more detail or datasheet about SSD1963,please click: http://www.kynix.com/Detail/189630/SSD1963G41.html And this is the code: [code]//RS pin connect FSMC_A10 while the data address is (2^10)*2 | 0x6000 = 0x6000 0800 #define Bank1_LCD_Data((uint32_t)0x6800)//disp Data ADDR #define Bank1_LCD_Reg((uint32_t)0x6000) //disp Reg ADDR ////screen is AT070TN92 and resolution is 800*480 unsigned int HDP=799; unsigned int HT=799; unsigned int HPS=60; unsigned int LPS=8; unsigned char HPW=1; unsigned int VDP=479; unsigned int VT=499; unsigned int VPS=12; unsigned int FPS=4; unsigned char VPW=10; //// void Delay(u16 nCount) { while(nCount--); } //===// //function declaration:Write command function //index:written command //===// void LCD_WR_REG(unsigned int index) { *(__IO uint16_t *) (Bank1_LCD_Reg)= index; } //===// //function declaration :Write function register data //index:Written address of the data //val:written data //===// void LCD_WR_CMD(unsigned int index,unsigned int val) { *(__IO uint16_t *) (Bank1_LCD_Reg)= index; *(__IO uint16_t *) (Bank1_LCD_Data)= val; } //===// //function declaration :read data //returned value :read data //===// u16 LCD_RD_Data(void) { u16 a=0; a=*(__IO uint16_t *) (Bank1_LCD_Data); return(a); } //===// //function declaration :write data //val:written data //===// voidLCD_WR_Data(unsigned int val) { *(__IO uint16_t *) (Bank1_LCD_Data)= val; } // //===// //function declaration :FSMC configuration function of SSD1963 //===// void SSD1963_FSMC_Init(void) { FSMC_NORSRAMTimingInitTypeDef readWriteTiming; FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure; FSMC_GPIO_Init(); //==//reading and writing timing configuration slow initialization time readWriteTiming.FSMC_AddressSetupTime = 0x02;//0x00 //Address setup time(ADDSET) readWriteTiming.FSMC_AddressHoldTime = 0x02;//0x00 //Address keeping time(ADDHLD) readWriteTiming.FSMC_DataSetupTime = 0x05;//0x01 //data keeping time(DATAST) readWriteTiming.FSMC_BusTurnAroundDuration = 0x02;//0x00 readWriteTiming.FSMC_CLKDivision = 0x00; readWriteTiming.FSMC_DataLatency = 0x00; readWriteTiming.FSMC_AccessMode = FSMC_AccessMode_A; //mode A //==// FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1; //use NE1 FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; FSMC_NORSRAMInitStructure.FSMC_MemoryType =FSMC_MemoryType_SRAM; FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;//The memory data width is 16bit FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode =FSMC_BurstAccessMode_Disable; FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait=FSMC_AsynchronousWait_Disable; FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;//Memory write enabled FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; //Reading and writing using the same sequence FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = //读写同样时序 FSMC_NORSRAMInit(_NORSRAMInitStructure); //initialize FSMC configuration FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE); //enable BANK1 } // //===// //function declaration : Initialization
[Issue 17791] Add __traits(isDeprecated, ...)
https://issues.dlang.org/show_bug.cgi?id=17791 ZombineDevchanged: What|Removed |Added CC||petar.p.ki...@gmail.com --- Comment #1 from ZombineDev --- Ditto for @future. --
Update the ArchWiki page about D
See https://wiki.archlinux.org/index.php/D where is stated that "The main difference is that the dmd's back end is not FOSS (licensed from Symantec), while the others compilers are completely FOSS." Time to update this.
Re: D Tour is down
On Monday, 28 August 2017 at 23:57:01 UTC, Mengu wrote: On Monday, 28 August 2017 at 17:16:59 UTC, Mengu wrote: On Monday, 28 August 2017 at 08:19:10 UTC, Petar Kirov [ZombineDev] wrote: On Monday, 28 August 2017 at 07:52:00 UTC, Joakim wrote: On Monday, 28 August 2017 at 07:44:48 UTC, Wulfklaue wrote: On Sunday, 27 August 2017 at 22:27:45 UTC, Mengu wrote: d tour page is down for at least a week now. someone please fix that. thanks. Seems to be active for me ... It shows a blank page for me. Also, the wiki seems really slow nowadays. Can you try again? I think that if there was a problem, it is gone now. it works on my android phone rn. i'll post if it doesn't work on the mac. on mac, with chrome version 60.0.3112.90 (64-bit), it renders an empty page. Try clearing your browser cache and try again. Yesterday I experienced the same problem, but after I cleared my cache it was gone.
Re: Accessing outer class attribute from inner struct
On Tuesday, 29 August 2017 at 07:59:40 UTC, Andre Pany wrote: On Monday, 28 August 2017 at 23:12:40 UTC, Moritz Maxeiner wrote: In both cases S doesn't inherently how about C, which means a solution using default initialization is not feasible, as S.init can't know about any particular instance of C. I don't think there's any way for you to avoid using a class constructor. Thanks for the explanation. I now tried to use a class and use a static opIndex. But it seems from a static method you also cannot access the attributes of a outer class :) A nested class' outer property (when nested inside another class) is a class reference, which means we not only require a class instance of the outer class to reference, but also a class instance of the nested class to store said class reference to the other class in. A static class method (by definition) is invoked without a class instance. The two are inherently incompatible. [...] This seems like an unnecessary limitation... I can only recommend reading the language specification w.r.t, nested classes [1] if it seems that way to you, because it is not. [1] https://dlang.org/spec/class.html#nested
Re: Editor recommendations for new users.
On Sunday, 27 August 2017 at 10:05:29 UTC, Nicholas Wilson wrote: So I will be doing a workshop on programming for the biology department at my university and I was wondering what would best suit the users. The following are a must: support windows & mac ( the more consistent between the two the better) free no large install footprint, preferably simple install procedure (running on laptops) syntax highlighting straightforward to use anything else is a bonus. Whats your experience with what you use? Many thanks Nic Try DlangIDE : https://github.com/buggins/dlangide Simple IDE with DUB based project format, uses DUB to fetch dependencies, build and run projects. Support of basic debugging. Syntax highlight, code completion, go to definition - using DCD. Supports Windows, mac, linux. Precompiled binaries for Windows: https://github.com/buggins/dlangide/releases Distribution size for Windows - 5.4Mb zipped. Includes DUB and mago-mi debugger. For Mac, it's easy to build it using DUB.
Re: Events in D
On Tuesday, 29 August 2017 at 05:10:25 UTC, bitwise wrote: [...] static if(op == "+") [...] Maybe "~"? Usually "+" means "sum" not "add"/"concat". Anyway I remember that something similar was used on DFL [1] [1] http://www.dprogramming.com/dfl.php
Re: Accessing outer class attribute from inner struct
On Monday, 28 August 2017 at 23:12:40 UTC, Moritz Maxeiner wrote: In both cases S doesn't inherently how about C, which means a solution using default initialization is not feasible, as S.init can't know about any particular instance of C. I don't think there's any way for you to avoid using a class constructor. Thanks for the explanation. I now tried to use a class and use a static opIndex. But it seems from a static method you also cannot access the attributes of a outer class :) class TCustomGrid: TCustomPresentedScrollBox { class ColumnsArray { static TColumn opIndex(int index) { // Reference is defined in TCustomGrid via inheritene int r = getIntegerIndexedPropertyReference(reference, "Columns", index); return new TColumn(r); } } alias Columns = ColumnsArray; ... } This seems like an unnecessary limitation... Kind regards André
Re: testing for deprecation
On Tuesday, 29 August 2017 at 05:03:39 UTC, Sebastien Alaiwan wrote: On Thursday, 1 September 2016 at 11:11:15 UTC, Cauterite wrote: How does one test whether a symbol is deprecated? I would have expected something like: __traits(isDeprecated, foo). Such a trait makes it possible to write code that will break, just because something has been marked as deprecated. Doesn't it break the purpose of deprecation? Yeah. static assert (!__traits(isDeprecated, foo), "i could use the -de switch as well"); I don't see any real-world usage for this trait. That being said the amount of work to implement this in the compiler is trivial. I would tear down the feature + its tests in half an hour i think.
Re: dlang.org faq says dmd is licensed with norton license
On Tuesday, 29 August 2017 at 06:56:13 UTC, Jonathan M Davis wrote: On Tuesday, August 29, 2017 06:43:19 meppl via Digitalmars-d wrote: ... Both the frontend and backend are now entirely under the Boost license. ... okay, PR was sent
Re: dlang.org faq says dmd is licensed with norton license
On Tuesday, August 29, 2017 06:43:19 meppl via Digitalmars-d wrote: > i incidentally noticed the FAQ claims the dmd-backend would be > licensed under a norton license. i thought it is an outdated > information: > https://dlang.org/faq.html#q5 > > > however, i also checked the source code and it turned out that > some files dont contain the string "boost": > $ fgrep -iLR boost src/ddmd/backend/ > src/ddmd/backend/bcomplex.h > src/ddmd/backend/dt.h > src/ddmd/backend/backend.txt > src/ddmd/backend/code_stub.h > src/ddmd/backend/dwarf2.h > src/ddmd/backend/dwarf.d > src/ddmd/backend/mach.d > src/ddmd/backend/md5.c > src/ddmd/backend/md5.h > src/ddmd/backend/bcomplex.c > src/ddmd/backend/mscoff.d > src/ddmd/backend/dwarf2.d > src/ddmd/backend/xmm.h > src/ddmd/backend/cv4.d > src/ddmd/backend/mscoff.h > src/ddmd/backend/mach.h > src/ddmd/backend/dwarf.h > src/ddmd/backend/melf.h > src/ddmd/backend/md5.d > src/ddmd/backend/bcomplex.d > src/ddmd/backend/cv4.h > > > do you think the missing license headers are relevant? If not, i > would make a pull request for the FAQ Both the frontend and backend are now entirely under the Boost license. Anything that says differently is out-of-date, but the change was recent enough, and there have been enough places to change, that it's no surprise if you've found some places where it hasn't been updated yet. - Jonathan M Davis
dlang.org faq says dmd is licensed with norton license
i incidentally noticed the FAQ claims the dmd-backend would be licensed under a norton license. i thought it is an outdated information: https://dlang.org/faq.html#q5 however, i also checked the source code and it turned out that some files dont contain the string "boost": $ fgrep -iLR boost src/ddmd/backend/ src/ddmd/backend/bcomplex.h src/ddmd/backend/dt.h src/ddmd/backend/backend.txt src/ddmd/backend/code_stub.h src/ddmd/backend/dwarf2.h src/ddmd/backend/dwarf.d src/ddmd/backend/mach.d src/ddmd/backend/md5.c src/ddmd/backend/md5.h src/ddmd/backend/bcomplex.c src/ddmd/backend/mscoff.d src/ddmd/backend/dwarf2.d src/ddmd/backend/xmm.h src/ddmd/backend/cv4.d src/ddmd/backend/mscoff.h src/ddmd/backend/mach.h src/ddmd/backend/dwarf.h src/ddmd/backend/melf.h src/ddmd/backend/md5.d src/ddmd/backend/bcomplex.d src/ddmd/backend/cv4.h do you think the missing license headers are relevant? If not, i would make a pull request for the FAQ