Re: Help me decide D or C
On Wednesday, 31 July 2019 at 18:38:02 UTC, Alexandre wrote: Hi everyone, I would like an honest opinion. I have a beginner level (able to do very small programs) in a few languages such as python, go, C, guile(scheme) and common lisp. I want to pick a language and go deep with it and focus on only one for at least the next 2 years or so. Should I go for C and then when I become a better programmer change to D? Should I start with D right now? The reason I am considering starting with C: since I am a beginner, obvious I will need lots of books, tutorials, videos etc. And I believe C would have more resources and maybe a low level to help with programming in general. And, when I need a more powerful language, I would than learn D. Since you know the good and the ugly of the D programming language I wonder, what you would think would be the best to do right now? Thank you for your help! I will go against the grain: Start with both! Yes! You can do it! You can! In fact, you will do it better! It will be a little harder at first but much faster in the end. D is C... no real difference, just minor stuff. Things take time to sink in, so if you start D and C now you will be further down the road than if you start D later. But if you really want to learn to program I suggest you go with Haskell. You can do them all together too but Haskell is like learning Alien while D is learning German.
Re: Example uses "volatile"; compiler says "undefined identifier volatile"
On Thursday, 1 August 2019 at 03:04:27 UTC, Paul wrote: I'm trying to build a Bare Bones 'OS' via example. Example says to compile with "gdc -c kernel.main.d -o kernel.main.o -g" I'm having trouble getting GDC all set up..as I'm a rank amateur. So, I tried compiling the example below with DMD. DMD spits out exceptions to the use of 'volatile'. DIP62 on D wiki says status:REJECTED for volatile. Whats my work around here? This is what I'm trying to do-> https:// wiki.osdev.org / D_Bare_Bones Thanks for any help. module kernel.main; extern(C) void main(uint magic, uint addr) { int ypos = 0; //Starting points of the cursor int xpos = 0; const uint COLUMNS = 80; //Screensize const uint LINES = 25; ubyte* vidmem = cast(ubyte*)0x_8000_000B_8000; //Video memory address for (int i = 0; i < COLUMNS * LINES * 2; i++) { //Loops through the screen and clears it volatile *(vidmem + i) = 0; } volatile *(vidmem + (xpos + ypos * COLUMNS) * 2) = 'D' & 0xFF; //Prints the letter D volatile *(vidmem + (xpos + ypos * COLUMNS) * 2 + 1) = 0x07; //Sets the colour for D to be light grey (0x07) for (;;) { //Loop forever. You can add your kernel logic here } } Accesses to peripheral regiters or memory need to be marked volatile. This tells the compiler that these operations have some other meaning than just store and load the data. Otherwise the compiler may reorder or remove operations. Unfortunately the volatile feature was removed from the language some years ago. Instead, there are volatileLoad and volatileStore in core.bitop. A simple program may work if all volatile words are just omitted and the program is compiled with all optimizations turned off. I made Volatile data type to access peripheral registers, you can see it here: https://bitbucket.org/timosi/minlibd/src/default/tools/main/volatil3.d
Re: Help me decide D or C
Whatever direction you choose to go, you should have a good community available to help you out. For D there is the Discord (or IRC, but I think Discord would be more suited to you) https://discord.gg/3vFMag7 And there is a Facebook group which I'm apart of which is decent (caters to all languages contrary to the name) https://www.facebook.com/groups/Javagroup123
Example uses "volatile"; compiler says "undefined identifier volatile"
I'm trying to build a Bare Bones 'OS' via example. Example says to compile with "gdc -c kernel.main.d -o kernel.main.o -g" I'm having trouble getting GDC all set up..as I'm a rank amateur. So, I tried compiling the example below with DMD. DMD spits out exceptions to the use of 'volatile'. DIP62 on D wiki says status:REJECTED for volatile. Whats my work around here? This is what I'm trying to do-> https:// wiki.osdev.org / D_Bare_Bones Thanks for any help. module kernel.main; extern(C) void main(uint magic, uint addr) { int ypos = 0; //Starting points of the cursor int xpos = 0; const uint COLUMNS = 80; //Screensize const uint LINES = 25; ubyte* vidmem = cast(ubyte*)0x_8000_000B_8000; //Video memory address for (int i = 0; i < COLUMNS * LINES * 2; i++) { //Loops through the screen and clears it volatile *(vidmem + i) = 0; } volatile *(vidmem + (xpos + ypos * COLUMNS) * 2) = 'D' & 0xFF; //Prints the letter D volatile *(vidmem + (xpos + ypos * COLUMNS) * 2 + 1) = 0x07; //Sets the colour for D to be light grey (0x07) for (;;) { //Loop forever. You can add your kernel logic here } }
Re: Help me decide D or C
On Wednesday, 31 July 2019 at 23:11:35 UTC, bachmeier wrote: I've been writing D code for six years. Someone that has programmed before could work through Adam's cookbook or Mike's book easily. About Mike's book, you're talking about this one: https://www.amazon.com/Learning-D-Michael-Parker/dp/1783552484/ref=as_li_ss_tl?ie=UTF8&qid=1448974911&sr=8-1&keywords=learning+d&linkCode=sl1&tag=aldacron-20&linkId=d696b771c78030fc272e9b853986a708 ? I have a friend (who already program) looking for some book besides Ali's online book. Sasha.
Re: Is there a way to adjust lookup paths for modules during compilation?
On Wed, Jul 31, 2019 at 08:47:42PM +, Andrey Zherikov via Digitalmars-d-learn wrote: > On Wednesday, 31 July 2019 at 20:16:01 UTC, H. S. Teoh wrote: > > On Wed, Jul 31, 2019 at 08:09:29PM +, Andrey Zherikov via > > Digitalmars-d-learn wrote: > > > I found a function that seems could be used for adding import paths: > > > dmd.frontend.addImport > > > (https://dlang.org/phobos/dmd_frontend.html#.addImport). But it's > > > not clear how can I use it: dmd directory is not added to lookup by > > > default and trying adding it gives errors: > > [...] > > > > That's because you can only call that function from inside dmd code. > > It's not available for user code to call. > > > > > > T > > I even suspect that dmd package which (I guess) is supposed to be "DMD > as a library" doesn't interact with DMD instance that is compiling the > code. The dmd package is supposed to be for your application to compile D code at runtime. It has nothing to do with compile-time features like CTFE when compiling your application's own code. T -- What doesn't kill me makes me stranger.
Re: Help me decide D or C
On Wednesday, 31 July 2019 at 22:49:10 UTC, SashaGreat wrote: On Wednesday, 31 July 2019 at 22:16:42 UTC, bachmeier wrote: What is your goal? In my opinion, learning C is a waste of time in 2019 unless you have something specific in mind related to a job. C is mostly "fun with segmentation faults". Most of your time is not spent solving problems. If you want to be productive, choose D, Go, Rust, C++, or just about anything but C. Interesting because you asked his goal and no matter what you pretty much just said to avoid C. So why the goal matters here? "In my opinion, learning C is a waste of time in 2019 unless you have something specific in mind related to a job." Kernel, embedded systems, LIBs (In fact there is libspng right now on front page of Reddit - /r/programming) that still uses C. That's very specialized, but sure, some things are still written in C. For example there is a lot of things with those languages (D or C++) like attributes: scope, ref, pure, share and so on that is useful but not for beginner. You can write, say, a CGI app using D without having to get into all of that. I generally don't mess with attributes, templates, or any of that cognitively challenging stuff, and I've been writing D code for six years. Someone that has programmed before could work through Adam's cookbook or Mike's book easily.
Re: Help me decide D or C
On Wednesday, 31 July 2019 at 22:16:42 UTC, bachmeier wrote: What is your goal? In my opinion, learning C is a waste of time in 2019 unless you have something specific in mind related to a job. C is mostly "fun with segmentation faults". Most of your time is not spent solving problems. If you want to be productive, choose D, Go, Rust, C++, or just about anything but C. Interesting because you asked his goal and no matter what you pretty much just said to avoid C. So why the goal matters here? Kernel, embedded systems, LIBs (In fact there is libspng right now on front page of Reddit - /r/programming) that still uses C. I'm not saying that he should go with C, but if someone is learning I really would avoid D or C++ for the matter. For example there is a lot of things with those languages (D or C++) like attributes: scope, ref, pure, share and so on that is useful but not for beginner. Sasha.
Re: Help me decide D or C
On Wednesday, 31 July 2019 at 20:04:39 UTC, Ali Çehreli wrote: n 07/31/2019 12:05 PM, Paul Backus wrote: > I would not recommend D as a beginning language, both because there are > fewer beginner-oriented resources available for it than for C and Python > (the only one I know of is Ali Çehreli's book [1]), and because it's a > bigger, more complicated language. > > [1] http://www.ddili.org/ders/d.en/index.html Ali here... :) Thanks for the link and I agree that D is much larger than C. At least for that reason, learning C first or on the side would still be good for the OP. Regarding "Programming in D", although it covers most[1] of the language, it specifically targets beginners; so, it may not be too difficult for the OP. Just give it a try... :) Ali [1] Unfortunately, copy constructors and some of the other recent features are still missing. I am considering reading your book + Andrei's book + documentation on the site. That would be my plan to learn D. Good job with your book btw, I enjoyed a lot the parts I've read.
Re: Help me decide D or C
On Wednesday, 31 July 2019 at 22:16:42 UTC, bachmeier wrote: On Wednesday, 31 July 2019 at 18:38:02 UTC, Alexandre wrote: [...] What is your goal? In my opinion, learning C is a waste of time in 2019 unless you have something specific in mind related to a job. C is mostly "fun with segmentation faults". Most of your time is not spent solving problems. If you want to be productive, choose D, Go, Rust, C++, or just about anything but C. My goals: 1) Improve as a programmer 2) Have fun doing programs Thats it basically. I am planning to study all "free" time I have. I am doing basically this since last year.
Re: Help me decide D or C
On Wednesday, 31 July 2019 at 18:38:02 UTC, Alexandre wrote: Hi everyone, I would like an honest opinion. I have a beginner level (able to do very small programs) in a few languages such as python, go, C, guile(scheme) and common lisp. I want to pick a language and go deep with it and focus on only one for at least the next 2 years or so. Should I go for C and then when I become a better programmer change to D? Should I start with D right now? The reason I am considering starting with C: since I am a beginner, obvious I will need lots of books, tutorials, videos etc. And I believe C would have more resources and maybe a low level to help with programming in general. And, when I need a more powerful language, I would than learn D. Since you know the good and the ugly of the D programming language I wonder, what you would think would be the best to do right now? Thank you for your help! What is your goal? In my opinion, learning C is a waste of time in 2019 unless you have something specific in mind related to a job. C is mostly "fun with segmentation faults". Most of your time is not spent solving problems. If you want to be productive, choose D, Go, Rust, C++, or just about anything but C.
Re: How do I display unicode characters in D on standard (english) Windows 10 console window?
On Monday, 29 July 2019 at 22:17:55 UTC, WhatMeWorry wrote: This is a very stupid question but from Ali's book, I took this segment: writeln("Résumé preparation: 10.25€"); writeln("\x52\ésum\u00e9 preparation: 10.25\€"); and after running it all I get is the following: R├⌐sum├⌐ preparation: 10.25Γé¼ R├⌐sum├⌐ preparation: 10.25Γé¼ I was expecting the symbol "£" or something like that. What am I missing? In my Windows 10 build 1803 I was able to find a box to check to globally use the UTF-8 code page. Checking it requires a restart as it says the locale has changed. Settings>Time&Language>Region&Language>Administrative_Language_Settings brings up a Region dialog, and clicking on "Change system locale..." brought up a dialog where this box can be checked. After doing this the console acted sensibly right away with the code you wrote.
Re: Help me decide D or C
On Wednesday, 31 July 2019 at 18:38:02 UTC, Alexandre wrote: ... Should I go for C and then when I become a better programmer change to D? Should I start with D right now? ... I think it depend your intent, but right now for a beginner between C and D I would go with C, because as you noted there are plenty of resources for C, C++, Python etc. In some colleges where I live, 10+ years ago they used to start CS class with C and then C++ or Java, now they start with Python and then C and so on. Python was "more" friendly for beginners to understand variable/algorithm, and after that they would go with data types, pointers... more easily. Good luck, Matheus.
Re: Is there a way to adjust lookup paths for modules during compilation?
On Wednesday, 31 July 2019 at 20:16:01 UTC, H. S. Teoh wrote: On Wed, Jul 31, 2019 at 08:09:29PM +, Andrey Zherikov via Digitalmars-d-learn wrote: I found a function that seems could be used for adding import paths: dmd.frontend.addImport (https://dlang.org/phobos/dmd_frontend.html#.addImport). But it's not clear how can I use it: dmd directory is not added to lookup by default and trying adding it gives errors: [...] That's because you can only call that function from inside dmd code. It's not available for user code to call. T I even suspect that dmd package which (I guess) is supposed to be "DMD as a library" doesn't interact with DMD instance that is compiling the code.
Re: Is there a way to adjust lookup paths for modules during compilation?
On Wednesday, 31 July 2019 at 20:25:44 UTC, Ali Çehreli wrote: On 07/31/2019 10:29 AM, Andrey Zherikov wrote: I want my program to add some directories into module lookup process (like adding -I dmd options). List of directories is known at compile time but the choice of what exact directories to add depends on `-version` parameter. Is there a way to achieve this in code? I can actually do this by creating scripts like 'build-version1', 'build-version2' but I'm looking for a way to avoid this. This seems to be a task for the build system: whatever is setting the -version switch should set the -I switch as well. Ali Yes, in dub you can create configurations for your dub project. Each configuration can define it's own versions and import paths. While executing dub, you would then pass the configuration to be build as command line arg: dub build -c myconfig1. (First config is the default config) https://dub.pm/package-format-json.html Kind regards Andre
Re: Meaning of Scoped! ??
On 07/30/2019 02:33 AM, Ron Tarrant wrote: > With contemporary search engines, it's impossible to search for '!' and > get meaningful results. I recommend this Index section for such cases: http://ddili.org/ders/d.en/ix.html Like most of Phobos, Scoped is not there but the "!, template instance" entry answers the other question. :) Ali
Re: Is there a way to adjust lookup paths for modules during compilation?
On 07/31/2019 10:29 AM, Andrey Zherikov wrote: I want my program to add some directories into module lookup process (like adding -I dmd options). List of directories is known at compile time but the choice of what exact directories to add depends on `-version` parameter. Is there a way to achieve this in code? I can actually do this by creating scripts like 'build-version1', 'build-version2' but I'm looking for a way to avoid this. This seems to be a task for the build system: whatever is setting the -version switch should set the -I switch as well. Ali
Re: How to setup D language with Apache httpd cgi?
On Wednesday, 31 July 2019 at 17:04:58 UTC, BoQsc wrote: However I tried to add options (--single) to the dub shebang and apache now throwing: "bad header error" Without "--single" option seems to work. #!/usr/bin/env -vS dub --single /+ dub.sdl: name "application" dependency "arsd-official:dom" version="4.0.2" +/ import std.stdio; import arsd.dom; void main() { writeln(`Content-type: text/html`); writeln(``); writeln(`test`); } split -S: 'dub --single' into:'dub' &'--single' executing: dub arg[0]= 'dub' arg[1]= '--single' arg[2]= '/usr/lib/cgi-bin/example.d' [Wed Jul 31 19:57:56.892522 2019] [cgid:error] [pid 833:tid 140583783876352] [client >127.0.0.1:43598] malformed header from script 'example.d': Bad header: Performing "debug" >build using As already pointed out, as starting point you could compile the application e.g. within folder /tmp and then copy the executable to cgi-bin folder. Please make sure it has executable flag. dub build --single hello.d The application could look like this: #!/usr/bin/env dub /+ dub.sdl: name "application" dependency "arsd-official:cgi" version="4.0.2" subConfiguration "arsd-official:cgi" "cgi" +/ import arsd.cgi; void hello(Cgi cgi) { cgi.setResponseContentType("text/plain"); if("name" in cgi.get) cgi.write("Hello, " ~ cgi.get["name"]); else cgi.write("Hello, world!"); } mixin GenericMain!hello; Kind regards Andre
Re: Is there a way to adjust lookup paths for modules during compilation?
On Wed, Jul 31, 2019 at 08:09:29PM +, Andrey Zherikov via Digitalmars-d-learn wrote: > I found a function that seems could be used for adding import paths: > dmd.frontend.addImport > (https://dlang.org/phobos/dmd_frontend.html#.addImport). But it's not clear > how can I use it: dmd directory is not added to lookup by default and trying > adding it gives errors: [...] That's because you can only call that function from inside dmd code. It's not available for user code to call. T -- Those who don't understand Unix are condemned to reinvent it, poorly.
Re: Is there a way to adjust lookup paths for modules during compilation?
I found a function that seems could be used for adding import paths: dmd.frontend.addImport (https://dlang.org/phobos/dmd_frontend.html#.addImport). But it's not clear how can I use it: dmd directory is not added to lookup by default and trying adding it gives errors: dmd.exe -i -Ic:\D\dmd-2.086.1\src\dmd\ main.d c:\D\dmd-2.086.1\src\dmd\dmd\dsymbol.d(231): Error: undefined identifier Symbol, did you mean class Dsymbol? c:\D\dmd-2.086.1\src\dmd\dmd\dsymbol.d(232): Error: undefined identifier Symbol, did you mean class Dsymbol? c:\D\dmd-2.086.1\src\dmd\dmd\dimport.d(105): Error: function `dmd.dimport.Import.kind` does not override any function c:\D\dmd-2.086.1\src\dmd\dmd\dimport.d(110): Error: function `dmd.dimport.Import.prot` does not override any function c:\D\dmd-2.086.1\src\dmd\dmd\dimport.d(210): Error: function `dmd.dimport.Import.importAll` does not override any function c:\D\dmd-2.086.1\src\dmd\dmd\dimport.d(270): Error: function `dmd.dimport.Import.setScope` does not override any function c:\D\dmd-2.086.1\src\dmd\dmd\dimport.d(313): Error: function `dmd.dimport.Import.isImport` does not override any function c:\D\dmd-2.086.1\src\dmd\dmd\dimport.d(318): Error: function `dmd.dimport.Import.accept` does not override any function c:\D\dmd-2.086.1\src\dmd\dmd\staticassert.d(56): Error: function `dmd.staticassert.StaticAssert.kind` does not override any function c:\D\dmd-2.086.1\src\dmd\dmd\staticassert.d(61): Error: function `dmd.staticassert.StaticAssert.accept` does not override any function c:\D\dmd-2.086.1\src\dmd\dmd\statement.d(2414): Error: function `dmd.statement.LabelDsymbol.isLabel` does not override any function c:\D\dmd-2.086.1\src\dmd\dmd\statement.d(2419): Error: function `dmd.statement.LabelDsymbol.accept` does not override any function c:\D\dmd-2.086.1\src\dmd\dmd\statement.d(2454): Error: undefined identifier code, did you mean import core? c:\D\dmd-2.086.1\src\dmd\dmd\dversion.d(54): Error: function `dmd.dversion.DebugSymbol.toChars` does not override any function c:\D\dmd-2.086.1\src\dmd\dmd\dversion.d(103): Error: function `dmd.dversion.DebugSymbol.kind` does not override any function c:\D\dmd-2.086.1\src\dmd\dmd\dversion.d(108): Error: function `dmd.dversion.DebugSymbol.accept` does not override any function c:\D\dmd-2.086.1\src\dmd\dmd\dversion.d(142): Error: function `dmd.dversion.VersionSymbol.toChars` does not override any function c:\D\dmd-2.086.1\src\dmd\dmd\dversion.d(192): Error: function `dmd.dversion.VersionSymbol.kind` does not override any function c:\D\dmd-2.086.1\src\dmd\dmd\dversion.d(197): Error: function `dmd.dversion.VersionSymbol.accept` does not override any function c:\D\dmd-2.086.1\src\dmd\dmd\doc.d(360): Error: need -J switch to import text file default_ddoc_theme.ddoc Any ideas?
Re: opEquals when your type occurs on the right hand side of an equality test
On 07/31/2019 01:03 PM, NonNull wrote: I am creating a specialized bit pattern (secretly represented as a uint) as a struct S, but want to avoid `alias this` to maintain encapsulation excepting where I overtly say. Specifically, I want to avoid making arithmetic and inequalities available for S. I have written opEquals to compare an S to a uint. How do I write code to compare a uint to an S? I didn't know that it works both ways already: import std.stdio; struct S { bool opEquals(uint u) { writeln("called"); return true; } } void main() { S s; s == 7; 7 == s; } There are two "called"s printed... Ali
Re: Help me decide D or C
n 07/31/2019 12:05 PM, Paul Backus wrote: > I would not recommend D as a beginning language, both because there are > fewer beginner-oriented resources available for it than for C and Python > (the only one I know of is Ali Çehreli's book [1]), and because it's a > bigger, more complicated language. > > [1] http://www.ddili.org/ders/d.en/index.html Ali here... :) Thanks for the link and I agree that D is much larger than C. At least for that reason, learning C first or on the side would still be good for the OP. Regarding "Programming in D", although it covers most[1] of the language, it specifically targets beginners; so, it may not be too difficult for the OP. Just give it a try... :) Ali [1] Unfortunately, copy constructors and some of the other recent features are still missing.
opEquals when your type occurs on the right hand side of an equality test
I am creating a specialized bit pattern (secretly represented as a uint) as a struct S, but want to avoid `alias this` to maintain encapsulation excepting where I overtly say. Specifically, I want to avoid making arithmetic and inequalities available for S. I have written opEquals to compare an S to a uint. How do I write code to compare a uint to an S?
Re: Help me decide D or C
On Wednesday, 31 July 2019 at 18:38:02 UTC, Alexandre wrote: Hi everyone, I would like an honest opinion. I have a beginner level (able to do very small programs) in a few languages such as python, go, C, guile(scheme) and common lisp. I want to pick a language and go deep with it and focus on only one for at least the next 2 years or so. Should I go for C and then when I become a better programmer change to D? Should I start with D right now? The reason I am considering starting with C: since I am a beginner, obvious I will need lots of books, tutorials, videos etc. And I believe C would have more resources and maybe a low level to help with programming in general. And, when I need a more powerful language, I would than learn D. Since you know the good and the ugly of the D programming language I wonder, what you would think would be the best to do right now? Thank you for your help! If you're looking for a language with lots of learning resources available, both C and Python are excellent choices. C is a good choice if you want to learn about how your programs interact with the hardware, and get an idea of how higher-level languages work "under the hood." Python is probably a better choice if you have a specific project in mind that you'd like to work on, like a web application or a game. I would not recommend D as a beginning language, both because there are fewer beginner-oriented resources available for it than for C and Python (the only one I know of is Ali Çehreli's book [1]), and because it's a bigger, more complicated language. [1] http://www.ddili.org/ders/d.en/index.html
Re: Help me decide D or C
On Wednesday, 31 July 2019 at 18:38:02 UTC, Alexandre wrote: Hi everyone, I would like an honest opinion. I have a beginner level (able to do very small programs) in a few languages such as python, go, C, guile(scheme) and common lisp. I want to pick a language and go deep with it and focus on only one for at least the next 2 years or so. Should I go for C and then when I become a better programmer change to D? Should I start with D right now? The reason I am considering starting with C: since I am a beginner, obvious I will need lots of books, tutorials, videos etc. And I believe C would have more resources and maybe a low level to help with programming in general. And, when I need a more powerful language, I would than learn D. Since you know the good and the ugly of the D programming language I wonder, what you would think would be the best to do right now? Thank you for your help! Hi Alexandre, As you are deciding between C and D I can give you a tipp. Almost all C tutorials and knowledge you can use directly in D. Even the C library is available in D. You can program C within D if you like and switch whenever you need or like to higher concepts which will ease the development. Also other C libraries you can use within D. I would say, you loose nothing while starting with D. Kind regards Andre
Help me decide D or C
Hi everyone, I would like an honest opinion. I have a beginner level (able to do very small programs) in a few languages such as python, go, C, guile(scheme) and common lisp. I want to pick a language and go deep with it and focus on only one for at least the next 2 years or so. Should I go for C and then when I become a better programmer change to D? Should I start with D right now? The reason I am considering starting with C: since I am a beginner, obvious I will need lots of books, tutorials, videos etc. And I believe C would have more resources and maybe a low level to help with programming in general. And, when I need a more powerful language, I would than learn D. Since you know the good and the ugly of the D programming language I wonder, what you would think would be the best to do right now? Thank you for your help!
Re: Is there a way to adjust lookup paths for modules during compilation?
On Wednesday, 31 July 2019 at 17:59:00 UTC, bauss wrote: Your best bet is actually not relying on CTFE since IO is very restricted at CTFE in D. Ex. you can only import files that are specified by you. The best thing you can do is have a file that lists every file you need to be able to read at CTFE. I'm not doing IO. I'm looking for something like this: version(version1) { add_import_path("location1"); } else version(version2) { add_import_path("location2"); } And dozens of other modules that do simple 'import somemodule' will get this module from either location1 or location2.
Re: Is there a way to adjust lookup paths for modules during compilation?
On Wednesday, 31 July 2019 at 17:29:58 UTC, Andrey Zherikov wrote: I want my program to add some directories into module lookup process (like adding -I dmd options). List of directories is known at compile time but the choice of what exact directories to add depends on `-version` parameter. Is there a way to achieve this in code? I can actually do this by creating scripts like 'build-version1', 'build-version2' but I'm looking for a way to avoid this. Your best bet is actually not relying on CTFE since IO is very restricted at CTFE in D. Ex. you can only import files that are specified by you. The best thing you can do is have a file that lists every file you need to be able to read at CTFE.
Is there a way to adjust lookup paths for modules during compilation?
I want my program to add some directories into module lookup process (like adding -I dmd options). List of directories is known at compile time but the choice of what exact directories to add depends on `-version` parameter. Is there a way to achieve this in code? I can actually do this by creating scripts like 'build-version1', 'build-version2' but I'm looking for a way to avoid this.
Re: How to setup D language with Apache httpd cgi?
On Wed, Jul 31, 2019 at 05:09:50PM +, BoQsc via Digitalmars-d-learn wrote: [...] > However as pointed out in the above post, I'm unable to use options in > shebang since apache is throwing header error for unknown reasons. [...] Usually, that's a sign that somebody is writing to stdout/stderr that should not be, because apache usually redirects stdout to the actual HTTP output stream. So if dub writes to stdout from within an apache module, that will garble the HTTP output stream and cause header errors and other kinds of errors. You may need to somehow redirect stdout/stderr if this is the case. T -- We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the Internet, we know this is not true. -- Robert Wilensk
Re: How to setup D language with Apache httpd cgi?
On Wednesday, 31 July 2019 at 14:19:20 UTC, bachmeier wrote: is going to compile every time it runs, which makes the program unnecessarily slow If only I could add dub --single --rdmd to the shebang, I think dub might stop compiling every time. However as pointed out in the above post, I'm unable to use options in shebang since apache is throwing header error for unknown reasons.
Re: How to setup D language with Apache httpd cgi?
However I tried to add options (--single) to the dub shebang and apache now throwing: "bad header error" Without "--single" option seems to work. #!/usr/bin/env -vS dub --single /+ dub.sdl: name "application" dependency "arsd-official:dom" version="4.0.2" +/ import std.stdio; import arsd.dom; void main() { writeln(`Content-type: text/html`); writeln(``); writeln(`test`); } split -S: 'dub --single' into:'dub' &'--single' executing: dub arg[0]= 'dub' arg[1]= '--single' arg[2]= '/usr/lib/cgi-bin/example.d' [Wed Jul 31 19:57:56.892522 2019] [cgid:error] [pid 833:tid 140583783876352] [client >127.0.0.1:43598] malformed header from script 'example.d': Bad header: Performing "debug" >build using
Re: How to setup D language with Apache httpd cgi?
is going to compile every time it runs, which makes the program unnecessarily slow, and if it's used heavily, will add quite a load to the server. I finally done it, and I'm not sure if it compiles every time. It opens the page lightning fast since I use SSD drive. I'm not sure how to check if it compiles every time. Right now, I'm logged in as root and chmoded recursively the whole /usr/lib/cgi-bin/ folder and it succeed. #!/usr/bin/env dub /+ dub.sdl: name "application" dependency "arsd-official:dom" version="4.0.2" subConfiguration "arsd-official:cgi" "cgi" +/ import std.stdio; import arsd.dom; void main() { writeln(`Content-type: text/html`); writeln(``); auto document = new Document("paragraph"); document.root.innerHTML = "hey"; writeln(document); //writeln(`CGI D Example`); }
Re: How to setup D language with Apache httpd cgi?
On Wednesday, 31 July 2019 at 07:19:12 UTC, BoQsc wrote: There are some other bad news, I switched from rdmd to dub package manager since I need a package from Adam D. Ruppe. It is all good and well: this one works perfectly. #!/usr/bin/env dub /+ dub.sdl: name "hello" +/ import std.stdio; void main() { writeln(`Content-type: text/html`); writeln(``); writeln(`CGI D Example`); } But, once I add dub dependency, the error appears: Internal Server Error #!/usr/bin/env dub /+ dub.sdl: name "hello" dependency "arsd-official" version="~>4.0.1" +/ import std.stdio; void main() { writeln(`Content-type: text/html`); writeln(``); writeln(`CGI D Example`); } This seems to work well when running not from cgi, so there is no syntax error. I'm curious why you don't just compile the binary and put it in the CGI directory. That's what I've always done. This AFAICT (I don't often use Dub) is going to compile every time it runs, which makes the program unnecessarily slow, and if it's used heavily, will add quite a load to the server. If you use Adam's cgi.d, you can test your program at the command line, and even run a server on localhost to test it in your browser.
Re: How to setup D language with Apache httpd cgi?
On Wednesday, 31 July 2019 at 12:51:09 UTC, Adam D. Ruppe wrote: On Wednesday, 31 July 2019 at 09:09:12 UTC, BoQsc wrote: dependency "arsd-official" version="~>4.0.1" I just changed the thing, so now you will want to use version 4.0.2 and also require the cgi configuration rather than the default (I don't know how to do that in dub). Though personally, when I do cgi stuff in D, I don't bother with rdmd or dub or whatever, I just compile the program separately and copy the binary in to the cgi directory. It is more efficient and simpler to handle in error cases. /+ dub.sdl: name "application" dependency "arsd-official:cgi" version="4.0.2" subConfiguration "arsd-official:cgi" "cgi" +/ Kind regards Andre
Re: How to setup D language with Apache httpd cgi?
Hmm, it seems that once I remove sudo from the shebang, the error disappears and Internal Server Error disappears. example.d - does not work #!/usr/bin/env -S sudo dub /+ dub.sdl: name "hello" +/ import std.stdio; void main() { writeln(`Content-type: text/html`); writeln(``); writeln(`CGI D Example`); } /var/log/apache2/error.log [Wed Jul 31 15:48:07.769766 2019] [cgid:error] [pid 4012:tid 140324198397696] [client >127.0.0.1:51736] End of script output before headers: example.d example.d - Works perfectly, no errors in the log #!/usr/bin/env -S dub /+ dub.sdl: name "hello" +/ import std.stdio; void main() { writeln(`Content-type: text/html`); writeln(``); writeln(`CGI D Example`); }
Re: How to setup D language with Apache httpd cgi?
On Wednesday, 31 July 2019 at 09:09:12 UTC, BoQsc wrote: dependency "arsd-official" version="~>4.0.1" I just changed the thing, so now you will want to use version 4.0.2 and also require the cgi configuration rather than the default (I don't know how to do that in dub). Though personally, when I do cgi stuff in D, I don't bother with rdmd or dub or whatever, I just compile the program separately and copy the binary in to the cgi directory. It is more efficient and simpler to handle in error cases.
Re: How to setup D language with Apache httpd cgi?
On Wednesday, 31 July 2019 at 10:24:38 UTC, BoQsc wrote: On Wednesday, 31 July 2019 at 09:09:12 UTC, BoQsc wrote: On Wednesday, 31 July 2019 at 09:03:47 UTC, BoQsc wrote: And this is the error I get now: [Wed Jul 31 11:51:15.341790 2019] [cgid:error] [pid 870:tid 140153708345088] [client >127.0.0.1:50318] End of script output before headers: example.d And I have no idea how to deal with it. Cgi shows Internal Server Error, because of that "End of script output before headers" error. It seems like apache does not like what dub package manager is doing, as dub does something before cgi script outputs anything. https://stackoverflow.com/questions/22307610/end-of-script-output-before-headers-error-in-apache Please see https://github.com/adamdruppe/arsd/issues/203 Kind regards André
Re: How to setup D language with Apache httpd cgi?
On Wednesday, 31 July 2019 at 10:24:38 UTC, BoQsc wrote: On Wednesday, 31 July 2019 at 09:09:12 UTC, BoQsc wrote: On Wednesday, 31 July 2019 at 09:03:47 UTC, BoQsc wrote: And this is the error I get now: [Wed Jul 31 11:51:15.341790 2019] [cgid:error] [pid 870:tid 140153708345088] [client >127.0.0.1:50318] End of script output before headers: example.d And I have no idea how to deal with it. Cgi shows Internal Server Error, because of that "End of script output before headers" error. It seems like apache does not like what dub package manager is doing, as dub does something before cgi script outputs anything. https://stackoverflow.com/questions/22307610/end-of-script-output-before-headers-error-in-apache As info, the command dub app.d is rewritten to: dub run -q --temp-build --single app.d I wonder whether -q is correct here -q Only print warnings and errors maybe --vquiet should be used instead -vquiet Print no messages If there are any warnings, from dub / dmd these could cause invalid Internal Server Errors. Kind regards André
Re: How to setup D language with Apache httpd cgi?
On Wednesday, 31 July 2019 at 09:09:12 UTC, BoQsc wrote: On Wednesday, 31 July 2019 at 09:03:47 UTC, BoQsc wrote: And this is the error I get now: [Wed Jul 31 11:51:15.341790 2019] [cgid:error] [pid 870:tid 140153708345088] [client >127.0.0.1:50318] End of script output before headers: example.d And I have no idea how to deal with it. Cgi shows Internal Server Error, because of that "End of script output before headers" error. It seems like apache does not like what dub package manager is doing, as dub does something before cgi script outputs anything. https://stackoverflow.com/questions/22307610/end-of-script-output-before-headers-error-in-apache
Re: How to setup D language with Apache httpd cgi?
On Wednesday, 31 July 2019 at 09:03:47 UTC, BoQsc wrote: And this is the error I get now: [Wed Jul 31 11:51:15.341790 2019] [cgid:error] [pid 870:tid 140153708345088] [client >127.0.0.1:50318] End of script output before headers: example.d And I have no idea how to deal with it. Cgi shows Internal Server Error, because of that "End of script output before headers" error. #!/usr/bin/env -S sudo dub run --quiet --single /+ dub.sdl: name "hello" dependency "arsd-official" version="~>4.0.1" +/ import std.stdio; void main() { writeln(`Content-type: text/html`); writeln(``); writeln(`CGI D Example`); } Maybe it is not possible to use dub this way.
Re: How to setup D language with Apache httpd cgi?
On Wednesday, 31 July 2019 at 08:32:43 UTC, BoQsc wrote: Added sudo to the shebang, it started to say that sudo requires tty, meaning that there is no graphical interface for user to input the password. So, I remove the need to type password when using sudo command, by following these instructions: https://www.cyberciti.biz/faq/linux-unix-running-sudo-command-without-a-password/ And this is the error I get now: [Wed Jul 31 11:51:15.341790 2019] [cgid:error] [pid 870:tid 140153708345088] [client >127.0.0.1:50318] End of script output before headers: example.d
Re: How to setup D language with Apache httpd cgi?
On Wednesday, 31 July 2019 at 07:57:01 UTC, BoQsc wrote: [Wed Jul 31 10:44:26.887024 2019] [cgid:error] [pid 846:tid 140090256426752] [client >127.0.0.1:57052] malformed header from script 'example.d': Bad header: Fetching arsd-official 4.0.1 ( /usr/lib/cgi-bin/.dub/packages/: Permission denied Added sudo to the shebang, it started to say that sudo requires tty, meaning that there is no graphical interface for user to input the password. [Wed Jul 31 11:14:53.183607 2019] [cgid:error] [pid 6207:tid 140374439274240] [client >127.0.0.1:57400] End of script output before headers: example.d sudo: no tty present and no askpass program specified Script: #!/usr/bin/env -S sudo dub run --single /+ dub.sdl: name "hello" dependency "arsd-official" version="~>4.0.1" +/ import std.stdio; void main() { writeln(`Content-type: text/html`); writeln(``); writeln(`CGI D Example`); }
Re: How to setup D language with Apache httpd cgi?
On Wednesday, 31 July 2019 at 07:42:22 UTC, BoQsc wrote: This seems to work well when running not from cgi, so there is That was not true, it didn't work even from Linux Shell, I corrected shebang, now it works from Linux Shell. An, unexpected thing: It did require permissions: sudo ./example.d which was not the case with rdmd. cgi still shows Internal Server Error. Maybe cgi cannot run this script due to lacking sudo permissions required by dub? Unsure. #!/usr/bin/env -S dub run --single /+ dub.sdl: name "hello" dependency "arsd-official" version="~>4.0.1" +/ import std.stdio; void main() { writeln(`Content-type: text/html`); writeln(``); writeln(`CGI D Example`); } It seems that /var/log/apache2/error.log shows Permission denied error. [Wed Jul 31 10:44:26.887024 2019] [cgid:error] [pid 846:tid 140090256426752] [client >127.0.0.1:57052] malformed header from script 'example.d': Bad header: Fetching arsd-official 4.0.1 ( /usr/lib/cgi-bin/.dub/packages/: Permission denied
Re: How to setup D language with Apache httpd cgi?
This seems to work well when running not from cgi, so there is That was not true, it didn't work even from Linux Shell, I corrected shebang, now it works from Linux Shell. An, unexpected thing: It did require permissions: sudo ./example.d which was not the case with rdmd. cgi still shows Internal Server Error. Maybe cgi cannot run this script due to lacking sudo permissions required by dub? Unsure. #!/usr/bin/env -S dub run --single /+ dub.sdl: name "hello" dependency "arsd-official" version="~>4.0.1" +/ import std.stdio; void main() { writeln(`Content-type: text/html`); writeln(``); writeln(`CGI D Example`); }
Re: How to setup D language with Apache httpd cgi?
I tried to change shebang, but: Internal Server Error still appears. #!/usr/bin/env dub run --single /+ dub.sdl: name "hello" dependency "arsd-official" version="~>4.0.1" +/ import std.stdio; void main() { writeln(`Content-type: text/html`); writeln(``); writeln(`CGI D Example`); }
Re: How to setup D language with Apache httpd cgi?
There are some other bad news, I switched from rdmd to dub package manager since I need a package from Adam D. Ruppe. It is all good and well: this one works perfectly. #!/usr/bin/env dub /+ dub.sdl: name "hello" +/ import std.stdio; void main() { writeln(`Content-type: text/html`); writeln(``); writeln(`CGI D Example`); } But, once I add dub dependency, the error appears: Internal Server Error #!/usr/bin/env dub /+ dub.sdl: name "hello" dependency "arsd-official" version="~>4.0.1" +/ import std.stdio; void main() { writeln(`Content-type: text/html`); writeln(``); writeln(`CGI D Example`); } This seems to work well when running not from cgi, so there is no syntax error.
Re: How to setup D language with Apache httpd cgi?
On Wednesday, 31 July 2019 at 06:52:46 UTC, 0xEAB wrote: On Wednesday, 31 July 2019 at 06:30:03 UTC, BoQsc wrote: This can be solved by using single quotes in the argument content places #!/usr/bin/env rdmd import std.stdio; void main() { writeln("Content-type: text/html"); writeln(""); writeln("CGI D Example"); } Does the job but is a bad fix. Use `` quotes for the string literal instead. Further info: https://dlang.org/spec/lex.html#wysiwyg - Elias I wasn't aware of Wysiwyg Strings, thanks, seems to work very well. #!/usr/bin/env rdmd import std.stdio; void main() { writeln(`Content-type: text/html`); writeln(``); writeln(`CGI D Example`); }
Re: How to setup D language with Apache httpd cgi?
On Wednesday, 31 July 2019 at 06:55:06 UTC, 0xEAB wrote: On Wednesday, 31 July 2019 at 06:30:03 UTC, BoQsc wrote: On Wednesday, 31 July 2019 at 05:56:46 UTC, BoQsc wrote: what causes the Internal Server Error. Internal Server Error might as well appear when D language syntax is not correct. Maybe you want to use some wrapper around rdmd that does output a proper CGI response on error. Since this error occurs because rdmd's error message as-is is not valid for CGI. - Elias I'm kind of new to everything, I'm not sure how this have to be done.
Re: How to setup D language with Apache httpd cgi?
On Wednesday, 31 July 2019 at 06:30:03 UTC, BoQsc wrote: On Wednesday, 31 July 2019 at 05:56:46 UTC, BoQsc wrote: what causes the Internal Server Error. Internal Server Error might as well appear when D language syntax is not correct. Maybe you want to use some wrapper around rdmd that does output a proper CGI response on error. Since this error occurs because rdmd's error message as-is is not valid for CGI. - Elias