digitalmars.D.learn - Is there any writeln like functions without GC?
- lili (2/2) Oct 30 2019 Hi:
- Ferhat =?UTF-8?B?S3VydHVsbXXFnw==?= (50/52) Oct 31 2019 I cannot answer why it needs GC but something can be implemented
- Adam D. Ruppe (5/7) Oct 31 2019 It almost never does, it just keeps the option open in case
- Ferhat =?UTF-8?B?S3VydHVsbXXFnw==?= (8/16) Oct 31 2019 It would be nice if one reimplement writeln of Phobos by
- bachmeier (4/11) Oct 31 2019 I can't imagine any possibility we'll ever see a breaking change
- Seb (2/14) Nov 02 2019 Yep or Phobos 2 which is more realistic at this point.
- Jonathan M Davis (4/25) Nov 02 2019 You can always just use printf.
- 9il (3/5) Nov 02 2019 See also Mir's @nogc formatting module
- dangbinghoo (5/10) Nov 09 2019 hi, is mir right now fully implemented using betterC?
- 9il (5/17) Nov 13 2019 Nope, but you can write a lot of things that would not require to
- Ferhat =?UTF-8?B?S3VydHVsbXXFnw==?= (5/7) Nov 09 2019 Upon this post, I thought writing a gc-free writeln would be a
- bauss (7/14) Nov 11 2019 If you wanted to follow the standard of D then you didn't need a
- Ferhat =?UTF-8?B?S3VydHVsbXXFnw==?= (3/6) Nov 11 2019 And that is why std.exception.assumeUnique converts char[] to
- Ogi (5/5) Nov 12 2019 If your goal is to debug your @nogc code, you can use writeln in
On Thursday, 31 October 2019 at 03:56:56 UTC, lili wrote:Hi: why writeln need GC?I cannot answer why it needs GC but something can be implemented like: import core.stdc.stdio; struct Point { int x; int y; } class Person { string name; uint age; } template GenStructMemberPrint(string structInstanceName, string memberName){ const char[] GenStructMemberPrint = "printf(\"%d\", " ~structInstanceName ~ "." ~ memberName ~ ");"; // static ifs can be used to use proper formats depending on the typeof struct member } // entire thing can be implemented using sprintf to obtain a nice formatted line void writeln2(A...)(A arguments) nogc nothrow { foreach (a; arguments) { static if (is(typeof(a) == class) || is(typeof(a) == interface)) { printf("%s \n", typeof(a).stringof.ptr); } else static if (is(typeof(a) == string)) { printf("%s \n", a.ptr); } else static if (is(typeof(a) == struct)){ foreach (member; __traits(allMembers, typeof(a))) { //writeln(member); mixin(GenStructMemberPrint!(a.stringof, member)); // this needs some improvements to imitate writeln } } else { static assert( "non-supported type!"); } } } void main() { auto pt = Point(10, 20); auto per = new Person(); // nogc custom allocator can be used here writeln2("ssss", per, pt); }
Oct 31 2019
On Thursday, 31 October 2019 at 03:56:56 UTC, lili wrote:Hi: why writeln need GC?It almost never does, it just keeps the option open in case * it needs to throw an exception (like if stdout is closed) * you pass it a custom type with toString that uses GC nogc is just super strict and doesn't even allow for rare cases.
Oct 31 2019
On Thursday, 31 October 2019 at 13:46:07 UTC, Adam D. Ruppe wrote:On Thursday, 31 October 2019 at 03:56:56 UTC, lili wrote:It would be nice if one reimplement writeln of Phobos by bypassing gc and use a custom nogc exception as described here*? Of course I can imagine that it would be a breaking change in the language and requires so much work for it to be compatible with other std modules/language features. *: https://www.auburnsounds.com/blog/2016-11-10_Running-D-without-its-runtime.htmlHi: why writeln need GC?It almost never does, it just keeps the option open in case * it needs to throw an exception (like if stdout is closed) * you pass it a custom type with toString that uses GC nogc is just super strict and doesn't even allow for rare cases.
Oct 31 2019
On Thursday, 31 October 2019 at 15:11:42 UTC, Ferhat Kurtulmuş wrote:It would be nice if one reimplement writeln of Phobos by bypassing gc and use a custom nogc exception as described here*? Of course I can imagine that it would be a breaking change in the language and requires so much work for it to be compatible with other std modules/language features. *: https://www.auburnsounds.com/blog/2016-11-10_Running-D-without-its-runtime.htmlI can't imagine any possibility we'll ever see a breaking change to writeln. It would have to be an addition to Phobos.
Oct 31 2019
On Thursday, 31 October 2019 at 16:03:22 UTC, bachmeier wrote:On Thursday, 31 October 2019 at 15:11:42 UTC, Ferhat Kurtulmuş wrote:Yep or Phobos 2 which is more realistic at this point.It would be nice if one reimplement writeln of Phobos by bypassing gc and use a custom nogc exception as described here*? Of course I can imagine that it would be a breaking change in the language and requires so much work for it to be compatible with other std modules/language features. *: https://www.auburnsounds.com/blog/2016-11-10_Running-D-without-its-runtime.htmlI can't imagine any possibility we'll ever see a breaking change to writeln. It would have to be an addition to Phobos.
Nov 02 2019
On Thursday, October 31, 2019 9:11:42 AM MDT Ferhat Kurtulmuş via Digitalmars-d-learn wrote:On Thursday, 31 October 2019 at 13:46:07 UTC, Adam D. Ruppe wrote:You can always just use printf. - Jonathan M DavisOn Thursday, 31 October 2019 at 03:56:56 UTC, lili wrote:It would be nice if one reimplement writeln of Phobos by bypassing gc and use a custom nogc exception as described here*? Of course I can imagine that it would be a breaking change in the language and requires so much work for it to be compatible with other std modules/language features. *: https://www.auburnsounds.com/blog/2016-11-10_Running-D-without-its-runtime .htmlHi: why writeln need GC?It almost never does, it just keeps the option open in case * it needs to throw an exception (like if stdout is closed) * you pass it a custom type with toString that uses GC nogc is just super strict and doesn't even allow for rare cases.
Nov 02 2019
On Thursday, 31 October 2019 at 03:56:56 UTC, lili wrote:Hi: why writeln need GC?See also Mir's nogc formatting module https://github.com/libmir/mir-runtime/blob/master/source/mir/format.d
Nov 02 2019
On Sunday, 3 November 2019 at 05:46:53 UTC, 9il wrote:On Thursday, 31 October 2019 at 03:56:56 UTC, lili wrote:hi, is mir right now fully implemented using betterC? thanks! -- binghooHi: why writeln need GC?See also Mir's nogc formatting module https://github.com/libmir/mir-runtime/blob/master/source/mir/format.d
Nov 09 2019
On Sunday, 10 November 2019 at 07:57:38 UTC, dangbinghoo wrote:On Sunday, 3 November 2019 at 05:46:53 UTC, 9il wrote:Nope, but you can write a lot of things that would not require to link with DRuntime. The betterC flags also means that you can't use DRuntime during compilation, which makes D generics almost useless.On Thursday, 31 October 2019 at 03:56:56 UTC, lili wrote:hi, is mir right now fully implemented using betterC? thanks! -- binghooHi: why writeln need GC?See also Mir's nogc formatting module https://github.com/libmir/mir-runtime/blob/master/source/mir/format.d
Nov 13 2019
On Thursday, 31 October 2019 at 03:56:56 UTC, lili wrote:Hi: why writeln need GC?Upon this post, I thought writing a gc-free writeln would be a good learning practice. Although it is not a feature-complete one, it was a lot of fun to do it :) https://github.com/aferust/stringnogc
Nov 09 2019
On Saturday, 9 November 2019 at 22:03:03 UTC, Ferhat Kurtulmuş wrote:On Thursday, 31 October 2019 at 03:56:56 UTC, lili wrote:If you wanted to follow the standard of D then you didn't need a string type. Since it doesn't really exist in D. string is just an alias for immutable(char)[] So what you want is to use this: https://dlang.org/phobos/std_container_array.htmlHi: why writeln need GC?Upon this post, I thought writing a gc-free writeln would be a good learning practice. Although it is not a feature-complete one, it was a lot of fun to do it :) https://github.com/aferust/stringnogc
Nov 11 2019
On Monday, 11 November 2019 at 16:20:59 UTC, bauss wrote:If you wanted to follow the standard of D then you didn't need a string type. Since it doesn't really exist in D. string is just an alias for immutable(char)[]And that is why std.exception.assumeUnique converts char[] to string AKA immutable(char)[].
Nov 11 2019
If your goal is to debug your nogc code, you can use writeln in debug statement: nogc void main() { debug writeln("hello, debug world!"); }
Nov 12 2019