Re: Posix access function
On Wednesday, October 19, 2016 04:29:30 tcak via Digitalmars-d-learn wrote: > Checked std.stdio, std.file, std.path, couldn't have found anyway > to check permissions on a file for read, write, execute. > > Without getting into core module, does it exist anywhere in std > module? On POSIX, std.file.getAttributes or attributes on a std.file.DirEntry will give you st_mode from the stat system call. http://www.unix.com/man-page/FreeBSD/2/stat/ The flags that st_mode uses are declared in core.sys.posix.sys.stat, and the rwx permissions for owner, group, and other are all there as described in the man page. - Jonathan M Davis
Re: TIL: auto struct members
On Wednesday, October 19, 2016 03:30:06 Basile B. via Digitalmars-d-learn wrote: > On Tuesday, 18 October 2016 at 22:12:47 UTC, Ali Çehreli wrote: > > It may be embarrassing to discover this fact so late but you > > can define struct members as 'auto': > > > > import std.range; > > import std.algorithm; > > > > struct S { > > > > auto r = only("a", "b").cycle;// <-- WOW! > > > > } > > > > pragma(msg, typeof(S.r)); > > > > /* Prints: > > * Cycle!(OnlyResult!(string, 2LU)) > > */ > > > > // It's extra cool that S and the whole construct is @nogc pure > > nothrow > > // (In that regard, only() is better than an array as the > > latter cannot > > // be @nogc. i.e. [ "a", "b", "a" ] cannot be @nogc.) > > void foo() @nogc pure nothrow { > > > > assert(S().r.take(3).equal(only("a", "b", "a"))); > > > > } > > > > void main() { > > } > > > > Ali > > > > P.S. I propose a new attribute, @cool, which should mean '@nogc > > pure nothrow'. :o) > > It also works if it's an enum, but without surprise because this > kind of enums are grammatically the same as an auto declaration. In D, all auto is is a placeholder for a type in a variable declaration. Type inference actually _always_ happens unless you provide the exact type. So, stuff like enum, const, immutable, static, etc. all are enough without needing auto. It's just that if you don't want any of those other attributes, you need the auto to indicate that you're defining a variable. I expect that the reason that Ali was surprised is that even if you're used to using auto all over the place in functions, you probably think of a user-defined type having fields of specific types, and you often don't directly initialize a member variable, in which case, you need the type. So, it can be easy to not realize that auto works with member variables too simply because you never thought about it. - Jonathan M Davis
Posix access function
Checked std.stdio, std.file, std.path, couldn't have found anyway to check permissions on a file for read, write, execute. Without getting into core module, does it exist anywhere in std module?
Re: TIL: auto struct members
On Tuesday, 18 October 2016 at 22:12:47 UTC, Ali Çehreli wrote: It may be embarrassing to discover this fact so late but you can define struct members as 'auto': import std.range; import std.algorithm; struct S { auto r = only("a", "b").cycle;// <-- WOW! } pragma(msg, typeof(S.r)); /* Prints: * Cycle!(OnlyResult!(string, 2LU)) */ // It's extra cool that S and the whole construct is @nogc pure nothrow // (In that regard, only() is better than an array as the latter cannot // be @nogc. i.e. [ "a", "b", "a" ] cannot be @nogc.) void foo() @nogc pure nothrow { assert(S().r.take(3).equal(only("a", "b", "a"))); } void main() { } Ali P.S. I propose a new attribute, @cool, which should mean '@nogc pure nothrow'. :o) It also works if it's an enum, but without surprise because this kind of enums are grammatically the same as an auto declaration.
Re: Render SVG To Display And Update Periodically
On Tuesday, 18 October 2016 at 21:00:12 UTC, Karabuta wrote: On Monday, 17 October 2016 at 07:18:40 UTC, ketmar wrote: On Monday, 17 October 2016 at 07:05:24 UTC, ketmar wrote: [...] oops, forgot to give some links. ;-) nanovg and nanosvg ports: http://repo.or.cz/iv.d.git/tree/HEAD:/nanovg some demos: http://repo.or.cz/iv.d.git/tree/HEAD:/nanovg_demo to make it actually draw something, i'm using Adam's excellect simpledisplay from here: https://github.com/adamdruppe/arsd fetching color.d and simpledisplay.d is enough, you don't need the whole repository. ;-) it works at least in GNU/Linux and Windows. OSX is not tested. This thing really needs a GitHub repo + documentation after all the hardwork. https://github.com/Pctg-x8/nanovg-d, I even think it's been announced here last year.
TIL: auto struct members
It may be embarrassing to discover this fact so late but you can define struct members as 'auto': import std.range; import std.algorithm; struct S { auto r = only("a", "b").cycle;// <-- WOW! } pragma(msg, typeof(S.r)); /* Prints: * Cycle!(OnlyResult!(string, 2LU)) */ // It's extra cool that S and the whole construct is @nogc pure nothrow // (In that regard, only() is better than an array as the latter cannot // be @nogc. i.e. [ "a", "b", "a" ] cannot be @nogc.) void foo() @nogc pure nothrow { assert(S().r.take(3).equal(only("a", "b", "a"))); } void main() { } Ali P.S. I propose a new attribute, @cool, which should mean '@nogc pure nothrow'. :o)
Re: Render SVG To Display And Update Periodically
On Monday, 17 October 2016 at 07:18:40 UTC, ketmar wrote: On Monday, 17 October 2016 at 07:05:24 UTC, ketmar wrote: On Monday, 17 October 2016 at 02:07:47 UTC, rikki cattermole wrote: [...] 'cmon, you know that i have a working port of NanoSVG! and it works on top of NanoVG, so no toolkit is required. ah... oops, forgot to give some links. ;-) nanovg and nanosvg ports: http://repo.or.cz/iv.d.git/tree/HEAD:/nanovg some demos: http://repo.or.cz/iv.d.git/tree/HEAD:/nanovg_demo to make it actually draw something, i'm using Adam's excellect simpledisplay from here: https://github.com/adamdruppe/arsd fetching color.d and simpledisplay.d is enough, you don't need the whole repository. ;-) it works at least in GNU/Linux and Windows. OSX is not tested. This thing really needs a GitHub repo + documentation after all the hardwork.
Re: Visual Studio Linker Problem
On Tuesday, 18 October 2016 at 18:09:11 UTC, Johan Engelen wrote: So this was a VS installation issue? (Visual Studio set the LIB path wrong?) I'm not sure where LIB was set.
Re: Visual Studio Linker Problem
On Tuesday, 18 October 2016 at 17:29:34 UTC, Jason C. Wells wrote: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat did in fact exist. My search for the file must have been errant. ldc2.exe hello.d also failed in cmd.exe. I took Mike's advice to run cmd.exe from one of the environments provided in the VS start menu. I tried to compile hello world and failed with the same error. I then ran 'set > environment.txt'. The value of LIB included the path: C:\Program Files (x86)\Windows Kits\10\lib\10.0.14393.0\ucrt\x64 which should have been: C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10150.0\ucrt\x64. I reset environment variable LIB to include the path to libucrt.lib. I was able to compile hello.d Thanks all. Your advice set me on the right path. So this was a VS installation issue? (Visual Studio set the LIB path wrong?)
Re: Visual Studio Linker Problem
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat did in fact exist. My search for the file must have been errant. ldc2.exe hello.d also failed in cmd.exe. I took Mike's advice to run cmd.exe from one of the environments provided in the VS start menu. I tried to compile hello world and failed with the same error. I then ran 'set > environment.txt'. The value of LIB included the path: C:\Program Files (x86)\Windows Kits\10\lib\10.0.14393.0\ucrt\x64 which should have been: C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10150.0\ucrt\x64. I reset environment variable LIB to include the path to libucrt.lib. I was able to compile hello.d Thanks all. Your advice set me on the right path. Regards, Jason C. Wells
Re: weighted round robin
On Wednesday, 12 October 2016 at 13:44:59 UTC, Erikvv wrote: On Tuesday, 11 October 2016 at 06:28:10 UTC, vino wrote: On Monday, 10 October 2016 at 09:18:16 UTC, Marc Schütz wrote: [...] Hi Marc, Thank you, I have made a small update as the Server Array is fixed length and the Socket array would be dynamic so made the below changes as now it is working as expected Prog:1 import std.stdio; import std.range; import std.range.primitives; import std.algorithm.comparison : max; void main() { auto a = [1,2,3]; // E.g :Server Array auto b = [1,2,3,4,5,6,7,8,9,10,11,12]; // E.g: Socket Array auto r = roundRobin(a.cycle, b.cycle); writeln(r.take(max(a.length, b.length * 2))); } From, Vino.B In your first post you mention it should be weighted, but I see no weights anywhere. Hi Marc, I am at the initial stage of implementing the round robin algorithm and still not reached the next part of weighted , if you have the code then please send me at present i am trying to implement this algorithm in my Server socket program and i would require few more days to complete it.
Re: inferred size for static array initialization
On Tuesday, 18 October 2016 at 10:35:44 UTC, Nordlöw wrote: On Monday, 2 May 2016 at 17:43:56 UTC, Namespace wrote: immutable auto a = [1,2,3].s; Will that have zero run-time overhead compared to: immutable int[3] a = [1,2,3]; ? I'm not quite sure if pragma(inline, true) would result in zero runtime overhead, but without you have 3 lines of assembler more (with gdc). https://godbolt.org/g/JUjP1d https://godbolt.org/g/qaqylp
Re: From Python to Dlang
@All, thanks a lot !
Re: From Python to Dlang
On Tuesday, 18 October 2016 at 12:03:54 UTC, Alfred Newman wrote: Hello and greetings, I'm a brand new D developer coming from Python. So, can you pls guys suggest me any resource like "D for a Python Developer" or so ? BTW, I just ordered the "D Programming Language" book from AA. Cheers Another great book, available for free online: http://ddili.org/ders/d.en/index.html
Re: From Python to Dlang
On Tuesday, 18 October 2016 at 12:03:54 UTC, Alfred Newman wrote: Hello and greetings, I'm a brand new D developer coming from Python. I decided to move to D, mainly because it's a compiled language and has a great runtime speed (and I don't feel confortable at Cython environment at all). And of course, D has a nice community and the language has nice syntax too... and is a joy to code with. However, I have some important production code in Python to migrate to D and every help will count ! So, can you pls guys suggest me any resource like "D for a Python Developer" or so ? BTW, I just ordered the "D Programming Language" book from AA. Cheers http://wiki.dlang.org/Programming_in_D_for_Python_Programmers And also of interest: http://code.dlang.org/packages/pyd
Re: From Python to Dlang
On 19/10/2016 1:03 AM, Alfred Newman wrote: Hello and greetings, I'm a brand new D developer coming from Python. I decided to move to D, mainly because it's a compiled language and has a great runtime speed (and I don't feel confortable at Cython environment at all). And of course, D has a nice community and the language has nice syntax too... and is a joy to code with. However, I have some important production code in Python to migrate to D and every help will count ! So, can you pls guys suggest me any resource like "D for a Python Developer" or so ? BTW, I just ordered the "D Programming Language" book from AA. Cheers TDPL is a great book to get an idea of what D is meant to do. But it isn't completely matching up to what D is today. There is an errata which contains errors with corrections[0]. You may also want to take a look at[1]. Otherwise browse the official spec, that is the way I learned. Once you've got some of the basics down p0nce has a great D idioms resource[2]. If you run into trouble, please join us in #d on Freenode (IRC). Much easier to help solve problems since it is interactive there. [0] http://erdani.com/tdpl/errata/ [1] http://tour.dlang.org [2] http://p0nce.github.io/d-idioms/
From Python to Dlang
Hello and greetings, I'm a brand new D developer coming from Python. I decided to move to D, mainly because it's a compiled language and has a great runtime speed (and I don't feel confortable at Cython environment at all). And of course, D has a nice community and the language has nice syntax too... and is a joy to code with. However, I have some important production code in Python to migrate to D and every help will count ! So, can you pls guys suggest me any resource like "D for a Python Developer" or so ? BTW, I just ordered the "D Programming Language" book from AA. Cheers
Re: inferred size for static array initialization
On 10/18/16 6:35 AM, Nordlöw wrote: On Monday, 2 May 2016 at 17:43:56 UTC, Namespace wrote: immutable auto a = [1,2,3].s; Will that have zero run-time overhead compared to: immutable int[3] a = [1,2,3]; Neither will have zero runtime overhead, but use the disassembler to see if there is a difference. My understanding is that while the compiler used to allocate whenever it saw an array literal (including your above usage), that is no longer the case. -Steve
Re: inferred size for static array initialization
On Monday, 2 May 2016 at 17:43:56 UTC, Namespace wrote: immutable auto a = [1,2,3].s; Will that have zero run-time overhead compared to: immutable int[3] a = [1,2,3]; ?
Re: Visual Studio Linker Problem
On Tuesday, 18 October 2016 at 05:23:15 UTC, Jason C. Wells wrote: I am able to compile hello world using dmd2. I am running in cygwin because I understand bash way better than cmd.exe. I bet it works if you invoke LDC outside bash. bash may tamper with environment variables, I've had a similiar issue with a bash shipped with PortableGit for Windows (C:\... => /C/...).
Re: Visual Studio Linker Problem
On Tuesday, 18 October 2016 at 05:23:15 UTC, Jason C. Wells wrote: I am working my way up to building NanoVG per my previous post. I am able to compile hello world using dmd2. I am running in cygwin because I understand bash way better than cmd.exe. Does `ldc2 hello.d` also fail in cmd.exe? [snip I see mention of a "vcvarsall.bat" file that might set my paths correctly, but this file is not found on my system. LDC's amd64.bat script should complain about it not being able to find "vcvarsall.bat". I see mention of a VCINSTALLDIR variable which is not set on my system. That's expected, that variable is set by one of VS's batch scripts. -Johan
Re: Speed of synchronized
On 18/10/16 07:04, Daniel Kozak via Digitalmars-d-learn wrote: > dub run --build=release --compiler=ldc on my machine i get the following output (using ldc2) ldc2 --version 09:32 LDC - the LLVM D compiler (1.0.0): based on DMD v2.070.2 and LLVM 3.8.1 built with LDC - the LLVM D compiler (0.17.1) Default target: x86_64-apple-darwin15.6.0 Host CPU: haswell http://dlang.org - http://wiki.dlang.org/LDC Registered Targets: amdgcn - AMD GCN GPUs arm - ARM armeb - ARM (big endian) nvptx - NVIDIA PTX 32-bit nvptx64 - NVIDIA PTX 64-bit r600- AMD GPUs HD2XXX-HD6XXX thumb - Thumb thumbeb - Thumb (big endian) x86 - 32-bit X86: Pentium-Pro and above x86-64 - 64-bit X86: EM64T and AMD64 dub test --compiler=ldc2 (my unittest configuration now includes the proper release flags thanks to sönke). No source files found in configuration 'library'. Falling back to "dub -b unittest". Performing "unittest" build using ldc2 for x86_64. 05-threads ~master: building configuration "application"... source/app.d(18): Deprecation: read-modify-write operations are not allowed for shared variables. Use core.atomic.atomicOp!"+="(this.counter, 1) instead. source/app.d(28): Deprecation: read-modify-write operations are not allowed for shared variables. Use core.atomic.atomicOp!"+="(this.counter, 1) instead. source/app.d(43): Deprecation: read-modify-write operations are not allowed for shared variables. Use core.atomic.atomicOp!"+="(this.counter, 1) instead. Running ./05-threads app.AtomicCounter: got: 100 expected: 100 in 21 ms, 692 μs, and 6 hnsecs app.ThreadSafe1Counter: got: 100 expected: 100 in 3 secs, 909 ms, 137 μs, and 3 hnsecs app.ThreadSafe2Counter: got: 100 expected: 100 in 3 secs, 724 ms, 201 μs, and 9 hnsecs app.ThreadUnsafeCounter: got: 759497 expected: 100 in 8 ms, 841 μs, and 9 hnsecs from example got: 3 secs, 840 ms, 387 μs, and 2 hnsecs looks similar to me. thanks christian
Re: Visual Studio Linker Problem
On Tuesday, 18 October 2016 at 05:23:15 UTC, Jason C. Wells wrote: $ ldc2 hello.d Using Visual C++: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC I see mention of a "vcvarsall.bat" file that might set my paths correctly, but this file is not found on my system. Are you sure? The path should be: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat I use MSYS2 frequently, but not with D or the Visual Studio tools, so I can't speak to anything specific in that regard. However, in my programs menu in the Visual Studio 2015 folder are several command prompt shortcuts which are preconfigured to set the environment for the VS tools. I suggest you open one of those and see if you can build anything with ldc, then go from there.
Re: Visual Studio Linker Problem
On Tuesday, 18 October 2016 at 05:23:15 UTC, Jason C. Wells wrote: The file "libucrt.lib" is found in several VS folders. I am sure that this is some path issue, but I'm not savvy on VisualStudio. I read some scary messages about this error in other parts of the forum from about a year ago. Hopefully the solution is easier than what I read in that thread. And I should mention that the old issue you're talking about was a side effect of a big change in Visual Studio 2015 over previous versions that DMD was unable to handle. Once DMD got caught up, the problem went away. I don't know that LDC was ever affected by it.
Re: Programming in D by Ali Çehreli
On 10/17/2016 11:48 PM, vino wrote: On Monday, 17 October 2016 at 18:20:00 UTC, cym13 wrote: On Monday, 17 October 2016 at 18:10:01 UTC, vino wrote: Hi All, As per the book named in the subject it states as below,so can some one guide me what is wrong in the below code nor correct if my understanding is wrong. Page 154 immutable(int[]) specifies that neither the slice nor its elements can be modified. So which means that a element or a slice of any array can be modified, but the below example code is not working. import std.stdio; void main() { immutable(int[]) immSlice = [ 1, 2 ]; immSlice ~= 3; immSlice[0] = 3; // Error's out at this point immSlice.length = 1; writeln(immSlice); } From, Vino.B I don't see what you don't understand, you said it yourself: "neither the slice nor its elements can be modified". So you can't modify the elements of an immutable array. immSlice is an immutable array of which you are trying to modify an element. Hi, Thank you for your reply, can you address why the below code is not working import std.stdio; void main() { int[] Array = [ 1, 2, 3, 4 ]; immutable(int[]) immSlice = Array[ 0 .. 2 ]; writeln("1st : ", immSlice); immSlice ~= 3; writeln("2nd : ", immSlice); immSlice[0] = 3; writeln("3rd : ", immSlice); immSlice.length = 1; writeln("4th : ",immSlice); } What is meant in that section in the book is 1) We cannot modify elements of an immutable slice 2) We cannot modify an immutable slice (e.g. cannot add elements to it) That's the reason for the following three compilation errors: Error: cannot modify immutable expression immSlice Error: cannot modify immutable expression immSlice[0] Error: cannot modify immutable expression immSlice Your new code has another compilation error here: int[] Array = [ 1, 2, 3, 4 ]; immutable(int[]) immSlice = Array[ 0 .. 2 ]; // <-- ERROR Error: cannot implicitly convert expression (Array[0..2]) of type int[] to immutable(int[]) That's because immSlice wants to guarantee that it has immutable elements. For that to be true, it cannot share elements of a mutable slice. Otherwise, elements could be modified through Array, which would also change immSlice's elements. (Remember that Array and immSlice would be sharing elements.) Ali
Re: Programming in D by Ali Çehreli
On Monday, 17 October 2016 at 18:17:24 UTC, Ali Çehreli wrote: On 10/17/2016 11:10 AM, vino wrote: [...] What version is your compiler? My version is DMD64 D Compiler v2.072.0-b2. Trying the code with a recent compiler produces three compilation errors for the following three lines immSlice ~= 3; immSlice[0] = 3; immSlice.length = 1; Error: cannot modify immutable expression immSlice Error: cannot modify immutable expression immSlice[0] Error: cannot modify immutable expression immSlice Ali Hi Ali, I am using DMD64 D Compiler v2.071.2-b5
Re: Programming in D by Ali Çehreli
On Monday, 17 October 2016 at 18:20:00 UTC, cym13 wrote: On Monday, 17 October 2016 at 18:10:01 UTC, vino wrote: Hi All, As per the book named in the subject it states as below,so can some one guide me what is wrong in the below code nor correct if my understanding is wrong. Page 154 immutable(int[]) specifies that neither the slice nor its elements can be modified. So which means that a element or a slice of any array can be modified, but the below example code is not working. import std.stdio; void main() { immutable(int[]) immSlice = [ 1, 2 ]; immSlice ~= 3; immSlice[0] = 3; // Error's out at this point immSlice.length = 1; writeln(immSlice); } From, Vino.B I don't see what you don't understand, you said it yourself: "neither the slice nor its elements can be modified". So you can't modify the elements of an immutable array. immSlice is an immutable array of which you are trying to modify an element. Hi, Thank you for your reply, can you address why the below code is not working import std.stdio; void main() { int[] Array = [ 1, 2, 3, 4 ]; immutable(int[]) immSlice = Array[ 0 .. 2 ]; writeln("1st : ", immSlice); immSlice ~= 3; writeln("2nd : ", immSlice); immSlice[0] = 3; writeln("3rd : ", immSlice); immSlice.length = 1; writeln("4th : ",immSlice); }