Re: Is there a way to not escape slashes when parsing JSON?

2022-02-21 Thread bachmeier via Digitalmars-d-learn
On Tuesday, 22 February 2022 at 00:44:58 UTC, jmh530 wrote: On Tuesday, 22 February 2022 at 00:36:38 UTC, bachmeier wrote: [snip] Yes. std.random is another. I gave up out on the current one. Luckily I already had external libraries for that before I started using D. Have you tried mir.rand

Re: Is there a way to not escape slashes when parsing JSON?

2022-02-21 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 22 February 2022 at 00:36:38 UTC, bachmeier wrote: [snip] Yes. std.random is another. I gave up out on the current one. Luckily I already had external libraries for that before I started using D. Have you tried mir.random?

Re: Is there a way to not escape slashes when parsing JSON?

2022-02-21 Thread bachmeier via Digitalmars-d-learn
On Monday, 21 February 2022 at 22:58:17 UTC, Ali Çehreli wrote: On 2/21/22 09:34, bachmeier wrote: > I may have to look for an alternative > JSON library for D. std.json is not the most fun independent of this issue. std.json is a very good module. At work, we had to write additional code to c

Re: Offline D documentation/tutorial

2022-02-21 Thread LorenDB via Digitalmars-d-learn
On Wednesday, 16 February 2022 at 20:07:09 UTC, Christian Köstlin wrote: 1. I was pointed by Seb to https://devdocs.io/d/ which offers an offline mode via html5. Thanks, that looks promising!

Re: Is there a way to not escape slashes when parsing JSON?

2022-02-21 Thread Ali Çehreli via Digitalmars-d-learn
On 2/21/22 14:58, Ali Çehreli wrote: > std.json is a very good module. Correction: std.json is NOT a very good module. Ali

Re: how to return map(fn)

2022-02-21 Thread Ali Çehreli via Digitalmars-d-learn
On 2/21/22 12:44, steve wrote: > I had a look at the source code for map but it seems to return a private > struct, which doesn't help. What map and other Phobos algorithms return are called Voldemort types for the reason you state: They are unmentionable. The usual way is to return 'auto' and

Re: SumType alias can't be deduced?

2022-02-21 Thread Emmanuelle via Digitalmars-d-learn
On Monday, 21 February 2022 at 20:18:46 UTC, Paul Backus wrote: This is a long-standing limitation of the D compiler's template argument deduction: it cannot "see through" `alias` templates to deduce the underlying type. Oh, that’s an unfortunate limitation but at least there’s a workaround.

Re: Is there a way to not escape slashes when parsing JSON?

2022-02-21 Thread bauss via Digitalmars-d-learn
On Monday, 21 February 2022 at 15:13:52 UTC, Kagamin wrote: On Monday, 21 February 2022 at 09:04:06 UTC, bauss wrote: Why are we even escaping them by default, it should be the other way around, that slashes are only escaped if you ask for it; that's how it literally is in almost every JSON lib

Re: Is there a way to not escape slashes when parsing JSON?

2022-02-21 Thread Ali Çehreli via Digitalmars-d-learn
On 2/21/22 09:34, bachmeier wrote: > I may have to look for an alternative > JSON library for D. std.json is not the most fun independent of this issue. std.json is a very good module. At work, we had to write additional code to cover its defficiencies. Looking forward to versioning in Phob

Re: Is there a way to not escape slashes when parsing JSON?

2022-02-21 Thread bachmeier via Digitalmars-d-learn
On Monday, 21 February 2022 at 17:50:56 UTC, bachmeier wrote: I looked at the source for `parseJSON` and I see references only to `JSONOptions.strictParsing` and `JSONOptions.specialFloatLiterals`. I may be missing something, but I don't see any option to iterating over every element and unes

how to return map(fn)

2022-02-21 Thread steve via Digitalmars-d-learn
following this example in the documentation of map: ``` import std.algorithm.comparison : equal; import std.conv : to; alias stringize = map!(to!string); assert(equal(stringize([ 1, 2, 3, 4 ]), [ "1", "2", "3", "4" ])); ``` I would like to write a function that takes as its parameter a functi

Re: SumType alias can't be deduced?

2022-02-21 Thread Paul Backus via Digitalmars-d-learn
On Monday, 21 February 2022 at 18:43:18 UTC, Emmanuelle wrote: If you run this, the compiler should emit this error: ```d onlineapp.d(14): Error: template `onlineapp.foobar` cannot deduce function from argument types `!()(SumType!(int, Unit))` onlineapp.d(8):Candidate is: `foobar(T)(Opt

Re: Differences between lambda function and regular functions in higher order functions

2022-02-21 Thread steve via Digitalmars-d-learn
thanks a lot both! Yes I'm aware that map exists already. This was didactic. I had tried to find out whether lambdas generate function pointers but also couldn't figure that one out :D

SumType alias can't be deduced?

2022-02-21 Thread Emmanuelle via Digitalmars-d-learn
See https://run.dlang.io/is/hNaSFh: ```d import std.sumtype; struct Unit {} alias Option(T) = SumType!(T, Unit); void foobar(T)(Option!T option) {} void main() { foobar(Option!int(123)); } ``` If you run this, the compiler should emit this error: ```d onlineapp.d(14): Error: template `on

Re: Is there a way to not escape slashes when parsing JSON?

2022-02-21 Thread bachmeier via Digitalmars-d-learn
On Monday, 21 February 2022 at 17:32:23 UTC, bachmeier wrote: On Monday, 21 February 2022 at 04:02:23 UTC, Steven Schveighoffer wrote: On Monday, 21 February 2022 at 03:42:55 UTC, bachmeier wrote: I tried this ```d import std.json, std.stdio; void main() { writeln(parseJSON(`{"a": "path/f

Re: Is there a way to not escape slashes when parsing JSON?

2022-02-21 Thread bachmeier via Digitalmars-d-learn
On Monday, 21 February 2022 at 09:04:06 UTC, bauss wrote: Why are we even escaping them by default, it should be the other way around, that slashes are only escaped if you ask for it; that's how it literally is in almost every JSON library. Escaping slashes as a default is a huge mistake IMHO

Re: Is there a way to not escape slashes when parsing JSON?

2022-02-21 Thread bachmeier via Digitalmars-d-learn
On Monday, 21 February 2022 at 04:02:23 UTC, Steven Schveighoffer wrote: On Monday, 21 February 2022 at 03:42:55 UTC, bachmeier wrote: I tried this ```d import std.json, std.stdio; void main() { writeln(parseJSON(`{"a": "path/file"}`, JSONOptions.doNotEscapeSlashes)); } ``` but the outp

Re: DDoc Reference Links point to /docs/docs instead of /docs?

2022-02-21 Thread Vijay Nayar via Digitalmars-d-learn
On Monday, 21 February 2022 at 16:58:43 UTC, Adam D Ruppe wrote: On Monday, 21 February 2022 at 15:35:41 UTC, Vijay Nayar wrote: I'm a bit surprised I've never heard of `adrdox` before now. yeah i don't advertise much. it is what runs on my dpldocs.info website though which auto-generates doc

Re: DDoc Reference Links point to /docs/docs instead of /docs?

2022-02-21 Thread Adam D Ruppe via Digitalmars-d-learn
On Monday, 21 February 2022 at 15:35:41 UTC, Vijay Nayar wrote: I'm a bit surprised I've never heard of `adrdox` before now. yeah i don't advertise much. it is what runs on my dpldocs.info website though which auto-generates docs for dub packages. Regarding ddoc, should I submit a bug report

Re: DDoc Reference Links point to /docs/docs instead of /docs?

2022-02-21 Thread Vijay Nayar via Digitalmars-d-learn
On Monday, 21 February 2022 at 13:18:01 UTC, Adam D Ruppe wrote: tbh ddoc is pretty bad, you should try my `dub run adrdox` instead which also creates html but its links actually work. I gave it a try and I must say that the documentation is formatted in a very good way, and as you said, all t

Re: Is there a way to not escape slashes when parsing JSON?

2022-02-21 Thread Kagamin via Digitalmars-d-learn
On Monday, 21 February 2022 at 09:04:06 UTC, bauss wrote: Why are we even escaping them by default, it should be the other way around, that slashes are only escaped if you ask for it; that's how it literally is in almost every JSON library. Really? I always see escaped slashes in JSON, e.g. wi

Re: DDoc Reference Links point to /docs/docs instead of /docs?

2022-02-21 Thread Adam D Ruppe via Digitalmars-d-learn
tbh ddoc is pretty bad, you should try my `dub run adrdox` instead which also creates html but its links actually work.

Re: Why writeln can't be converted to nothrow with just catching of StdioException

2022-02-21 Thread bauss via Digitalmars-d-learn
On Monday, 21 February 2022 at 10:57:07 UTC, Basile B. wrote: On Monday, 21 February 2022 at 10:53:56 UTC, Basile B. wrote: On Monday, 21 February 2022 at 10:49:13 UTC, partypooper wrote: Do I completely not understand what is `nothrow` or why I can't make function nothrow with just catching St

Re: Why writeln can't be converted to nothrow with just catching of StdioException

2022-02-21 Thread partypooper via Digitalmars-d-learn
On Monday, 21 February 2022 at 11:21:52 UTC, Mike Parker wrote: On Monday, 21 February 2022 at 11:07:55 UTC, Basile B. wrote: [...] This has nothing to do with which exceptions types a function throws. The compiler doesn't dig into that. You have to catch `Exception`. ```D import std.stdio

Re: Why writeln can't be converted to nothrow with just catching of StdioException

2022-02-21 Thread Basile B. via Digitalmars-d-learn
On Monday, 21 February 2022 at 11:12:38 UTC, partypooper wrote: On Monday, 21 February 2022 at 11:07:55 UTC, Basile B. wrote: Yeah there must be another one then. Something actionnable is the documentation. What about Mike Parker answer? if nothrow fails that's because things are checked. We

Re: Crosscompiling LDC's druntime for Android on Windows

2022-02-21 Thread kinke via Digitalmars-d-learn
On Monday, 21 February 2022 at 00:24:54 UTC, Fry wrote: I'm following the azure pipeline's commands for how it's being built here: https://github.com/ldc-developers/ldc/blob/master/.azure-pipelines/2-posix-build_cross_android.yml#L64 You can check the CI logs for the expanded cmdlines, e.g., f

DDoc Reference Links point to /docs/docs instead of /docs?

2022-02-21 Thread Vijay Nayar via Digitalmars-d-learn
Greetings everyone, I have a question regarding the use of [relative links](https://dlang.org/spec/ddoc.html#reference_links) in DDoc. According to the specification, you can include a reference to an object that is in scope using square brackets, e.g. `[Object]`. One of my current projects

Re: Why writeln can't be converted to nothrow with just catching of StdioException

2022-02-21 Thread Mike Parker via Digitalmars-d-learn
On Monday, 21 February 2022 at 11:07:55 UTC, Basile B. wrote: Yeah there must be another one then. Something actionnable is the documentation. This has nothing to do with which exceptions types a function throws. The compiler doesn't dig into that. You have to catch `Exception`. ```D impo

Re: Why writeln can't be converted to nothrow with just catching of StdioException

2022-02-21 Thread Mike Parker via Digitalmars-d-learn
On Monday, 21 February 2022 at 11:11:28 UTC, partypooper wrote: So with such behavior there is no reason at all to make make function nothrow, if it uses throw functions in its body? I'm not sure what you mean. If a function throws an exception, it can't be nothrow. And as much as I already

Re: Why writeln can't be converted to nothrow with just catching of StdioException

2022-02-21 Thread partypooper via Digitalmars-d-learn
On Monday, 21 February 2022 at 11:07:55 UTC, Basile B. wrote: Yeah there must be another one then. Something actionnable is the documentation. What about Mike Parker answer?

Re: Why writeln can't be converted to nothrow with just catching of StdioException

2022-02-21 Thread partypooper via Digitalmars-d-learn
On Monday, 21 February 2022 at 11:04:46 UTC, Mike Parker wrote: On Monday, 21 February 2022 at 10:49:13 UTC, partypooper wrote: Do I completely not understand what is `nothrow` or why I can't make function nothrow with just catching StdioException? D does not have checked exceptions like Java,

Re: Why writeln can't be converted to nothrow with just catching of StdioException

2022-02-21 Thread Basile B. via Digitalmars-d-learn
On Monday, 21 February 2022 at 11:05:42 UTC, partypooper wrote: On Monday, 21 February 2022 at 10:58:26 UTC, Basile B. wrote: more likely UTFException actually Additionaly catching UTF and Conv exceptions doesn't help. Yeah there must be another one then. Something actionnable is the docume

Re: Why writeln can't be converted to nothrow with just catching of StdioException

2022-02-21 Thread partypooper via Digitalmars-d-learn
On Monday, 21 February 2022 at 10:58:26 UTC, Basile B. wrote: more likely UTFException actually Additionaly catching UTF and Conv exceptions doesn't help.

Re: Why writeln can't be converted to nothrow with just catching of StdioException

2022-02-21 Thread Mike Parker via Digitalmars-d-learn
On Monday, 21 February 2022 at 10:49:13 UTC, partypooper wrote: Do I completely not understand what is `nothrow` or why I can't make function nothrow with just catching StdioException? D does not have checked exceptions like Java, so the compiler doesn't have anyway to verify that any function

Re: Why writeln can't be converted to nothrow with just catching of StdioException

2022-02-21 Thread Basile B. via Digitalmars-d-learn
On Monday, 21 February 2022 at 10:49:13 UTC, partypooper wrote: Do I completely not understand what is `nothrow` or why I can't make function nothrow with just catching StdioException? This doesn't work ```d nothrow void hello() { try { writeln("Hello, World!") } catch (StdioException)

Re: Differences between lambda function and regular functions in higher order functions

2022-02-21 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 21 February 2022 at 10:04:16 UTC, steve wrote: I am trying to implement a simple map function. I found code to do this in another post but it only seems to work with lambda functions and I do not understand why. Any help would be greatly appreciated ``` import std.stdio; T[] map_v

Re: Why writeln can't be converted to nothrow with just catching of StdioException

2022-02-21 Thread Basile B. via Digitalmars-d-learn
On Monday, 21 February 2022 at 10:53:56 UTC, Basile B. wrote: On Monday, 21 February 2022 at 10:49:13 UTC, partypooper wrote: Do I completely not understand what is `nothrow` or why I can't make function nothrow with just catching StdioException? This doesn't work ```d nothrow void hello() {

Re: Why writeln can't be converted to nothrow with just catching of StdioException

2022-02-21 Thread Basile B. via Digitalmars-d-learn
On Monday, 21 February 2022 at 10:53:56 UTC, Basile B. wrote: On Monday, 21 February 2022 at 10:49:13 UTC, partypooper wrote: Do I completely not understand what is `nothrow` or why I can't make function nothrow with just catching StdioException? This doesn't work ```d nothrow void hello() {

Re: Why writeln can't be converted to nothrow with just catching of StdioException

2022-02-21 Thread Basile B. via Digitalmars-d-learn
On Monday, 21 February 2022 at 10:49:13 UTC, partypooper wrote: Do I completely not understand what is `nothrow` or why I can't make function nothrow with just catching StdioException? This doesn't work ```d nothrow void hello() { try { writeln("Hello, World!") } catch (StdioException)

Why writeln can't be converted to nothrow with just catching of StdioException

2022-02-21 Thread partypooper via Digitalmars-d-learn
Do I completely not understand what is `nothrow` or why I can't make function nothrow with just catching StdioException? This doesn't work ```d nothrow void hello() { try { writeln("Hello, World!") } catch (StdioException) {} } ``` This doest work ```d nothrow void hello() { try {

Re: Differences between lambda function and regular functions in higher order functions

2022-02-21 Thread partypooper via Digitalmars-d-learn
On Monday, 21 February 2022 at 10:04:16 UTC, steve wrote: I am trying to implement a simple map function. I found code to do this in another post but it only seems to work with lambda functions and I do not understand why. Any help would be greatly appreciated ``` import std.stdio; T[] map_v

Differences between lambda function and regular functions in higher order functions

2022-02-21 Thread steve via Digitalmars-d-learn
I am trying to implement a simple map function. I found code to do this in another post but it only seems to work with lambda functions and I do not understand why. Any help would be greatly appreciated ``` import std.stdio; T[] map_vals(T,S)(scope T function(S) f, S[] a){ auto b = new T[

Re: Is there a way to not escape slashes when parsing JSON?

2022-02-21 Thread bauss via Digitalmars-d-learn
On Monday, 21 February 2022 at 03:42:55 UTC, bachmeier wrote: I tried this ``` import std.json, std.stdio; void main() { writeln(parseJSON(`{"a": "path/file"}`, JSONOptions.doNotEscapeSlashes)); } ``` but the output is ``` {"a":"path\/file"} ``` Is there a way to avoid the escaping of