Re: Where is pragma Declaration in the grammar?
On Saturday, 5 December 2020 at 03:55:52 UTC, Stefan Koch wrote: On Saturday, 5 December 2020 at 02:59:58 UTC, Paul Backus wrote: They're under Attribute: https://dlang.org/spec/grammar.html#Attribute The syntax tree for `pragma(msg, typeof(f))` in a declaration context would be: DeclDef AttributeSpecifier Attribute Pragma pragma(msg, typeof(f)) DeclarationBlock DeclDef ; The Decldef is not optional. This is for pragmas like pragma mangle that affect symbols. That's what I thought at first too, but according to the official grammar, the DeclDef can be a single semicolon (i.e., empty): https://dlang.org/spec/grammar.html#DeclDef
Re: Where is pragma Declaration in the grammar?
On Saturday, 5 December 2020 at 02:59:58 UTC, Paul Backus wrote: On Saturday, 5 December 2020 at 00:57:04 UTC, Stefan Koch wrote: Hi, today I've been dusting my SDC fork and implemented a rudimentary version of pragma(msg). I could pragmaStatement as in void f() { pragma(msg, typeof(f)); } but not a declaration as in pragma(msg, typeof(f)) without a function body. They're under Attribute: https://dlang.org/spec/grammar.html#Attribute The syntax tree for `pragma(msg, typeof(f))` in a declaration context would be: DeclDef AttributeSpecifier Attribute Pragma pragma(msg, typeof(f)) DeclarationBlock DeclDef ; The Decldef is not optional. This is for pragmas like pragma mangle that affect symbols.
Re: Where is pragma Declaration in the grammar?
On Saturday, 5 December 2020 at 00:57:04 UTC, Stefan Koch wrote: Hi, today I've been dusting my SDC fork and implemented a rudimentary version of pragma(msg). I could pragmaStatement as in void f() { pragma(msg, typeof(f)); } but not a declaration as in pragma(msg, typeof(f)) without a function body. They're under Attribute: https://dlang.org/spec/grammar.html#Attribute The syntax tree for `pragma(msg, typeof(f))` in a declaration context would be: DeclDef AttributeSpecifier Attribute Pragma pragma(msg, typeof(f)) DeclarationBlock DeclDef ;
Where is pragma Declaration in the grammar?
Hi, today I've been dusting my SDC fork and implemented a rudimentary version of pragma(msg). I could pragmaStatement as in void f() { pragma(msg, typeof(f)); } but not a declaration as in pragma(msg, typeof(f)) without a function body. there is a StaticAssert is in the grammar under declaration, pragma is not. Maybe it's stated differently? Any help is appreciated. Cheers, Stefan
Re: Pass enum variable as const ref arg
On Friday, 4 December 2020 at 12:54:25 UTC, Andrey wrote: Hello, void test(const ref string[3] qazzz) { qazzz.writeln; } void main() { enum string[3] value = ["qwer", "ggg", "v"]; test(value); } Gives errors: It works if you pass `-preview=rvaluerefparam` to the compiler. But the other suggestions are better IMO. —Bastiaan.
Re: Pass enum variable as const ref arg
Thank you!
Re: Pass enum variable as const ref arg
On Friday, 4 December 2020 at 13:42:45 UTC, Andrey wrote: Hm, you mean that enum variable is not a real variable? I thought that to make CT variable you should mark it as enum (in c++ as constexpr). How to do it here? The official name for what you're calling an "enum variable" is "manifest constant" [1]. Manifest constants are like named literals: when you use one, it is treated by the compiler as though you had copy-and-pasted its value at that point in the code. So, for example, enum string[3] value = ["qwer", "ggg", "v"]; test(value); ...is equivalent to test(cast(string[3]) ["qwer", "ggg", "v"]); If you want to declare a compile-time constant that's also an lvalue, you can use `static immutable` instead of `enum`: static immutable string[3] value = ["qwer", "ggg", "v"]; test(value); [1] https://dlang.org/spec/enum.html#manifest_constants
Re: Pass enum variable as const ref arg
On 05/12/2020 2:42 AM, Andrey wrote: Hm, you mean that enum variable is not a real variable? It is not a variable. It is a constant that cannot be changed and does not exist in the executable. I thought that to make CT variable you should mark it as enum (in c++ as constexpr). How to do it here? You are already doing it. This is not what you want. You want a variable that will pass by ref. Remove enum.
Re: Pass enum variable as const ref arg
Hm, you mean that enum variable is not a real variable? I thought that to make CT variable you should mark it as enum (in c++ as constexpr). How to do it here?
Re: Pass enum variable as const ref arg
On 05/12/2020 1:54 AM, Andrey wrote: Hello, void test(const ref string[3] qazzz) { qazzz.writeln; } void main() { enum string[3] value = ["qwer", "ggg", "v"]; That is a compile time constant (remove the enum). test(value); } Gives errors: onlineapp.d(26): Error: function onlineapp.test(ref const(string[3]) qazzz) is not callable using argument types (string[3]) onlineapp.d(26): cannot pass rvalue argument ["qwer", "ggg", "v"] of type string[3] to parameter ref const(string[3]) qazzz WTF? The ref. The problem is the ref. You are passing it a constant, not a variable.
Pass enum variable as const ref arg
Hello, void test(const ref string[3] qazzz) { qazzz.writeln; } void main() { enum string[3] value = ["qwer", "ggg", "v"]; test(value); } Gives errors: onlineapp.d(26): Error: function onlineapp.test(ref const(string[3]) qazzz) is not callable using argument types (string[3]) onlineapp.d(26):cannot pass rvalue argument ["qwer", "ggg", "v"] of type string[3] to parameter ref const(string[3]) qazzz WTF?
Re: strip in stdin
On Friday, 4 December 2020 at 06:51:32 UTC, MGW wrote: string[] m = stdin.byLineCopy.array; How to make strip() for each line in an expression ... To apply a function to each element of a range, use the `map` algorithm: import std.algorithm: map; string[] m = stdin.byLineCopy.map!strip.array;
Re: Anybody know if I can build DMD with Visual Studio 2019?
On Friday, 4 December 2020 at 09:32:29 UTC, Imperatorn wrote: On Wednesday, 2 December 2020 at 22:37:06 UTC, WhatMeWorry wrote: It works now. Not sure what I did to _not_ make it work yesterday. That's easy. You made a post here about it and the universe got scared. This made my day.
Re: Anybody know if I can build DMD with Visual Studio 2019?
On Wednesday, 2 December 2020 at 22:37:06 UTC, WhatMeWorry wrote: On Tuesday, 1 December 2020 at 22:58:53 UTC, WhatMeWorry wrote: I'm trying to build DMD with Visual D under Visual Studio as shown in the Wiki: https://wiki.dlang.org/Building_under_Windows The notes say to use the solution vcbuild: You should be able to build DMD using the visual studio solution found in: dmd\src\vcbuild A typical choice is to build the 64-bit debug version (the VisualD options are named 'Release' and 'x64'). [Btw, Should that be "64-bit release version" or "'Debug' and 'x64'"?] I do this with Visual Studio 2019 and I'm getting errors. Should I be using Visual Studio 2017 or even VS 2013? Didn't want to waste time debugging if VS2019 is not supported. It works now. Not sure what I did to _not_ make it work yesterday. That's easy. You made a post here about it and the universe got scared.
Re: My first application in Dlang
On Thursday, 3 December 2020 at 03:54:16 UTC, Marcone wrote: On Thursday, 3 December 2020 at 02:44:40 UTC, Ali Çehreli wrote: On 12/2/20 5:46 PM, Marcone wrote: [...] Cool. :) But did you want to share your *source* code? All I see there is a .exe, which I would not start due to risk of viruses (of course unknown to you). Ali Hi, are you Ali Çehreli author of Programming in D book? I learned Dlang by reading this book on my Kindle. If I published my source code you wouldn't understand. I created a module with functions so useful, that using UFCS if it weren't for the keys delimiting the blocks, anyone would think they're reading a Python code. I'm pretty sure we would be able to understand the source. Hard to give any constructive criticism without it