Ways to parse D code.

2020-11-25 Thread Jan Hönig via Digitalmars-d-learn
What is the "easiest" way to parse D code? Given an Expression/Statement/Function/Template I want to put it into a program, and it returns me an AST. D-Scanner seems to do that with `--ast` argument. I would need to dig into it, to get it programmatically, instead of as XML on the

Re: How exactly does Tuple work?

2020-11-08 Thread Jan Hönig via Digitalmars-d-learn
On Sunday, 8 November 2020 at 13:10:33 UTC, Adam D. Ruppe wrote: On Sunday, 8 November 2020 at 10:03:46 UTC, Jan Hönig wrote: Is there some recourse, which explains the `alias this`? If your object is used in a way that doesn't compile, the compiler will change `obj` to

Re: How exactly does Tuple work?

2020-11-08 Thread Jan Hönig via Digitalmars-d-learn
On Saturday, 7 November 2020 at 18:31:18 UTC, Paul Backus wrote: Indexing and slicing are implemented with `alias expand this`, which causes `t[i]` to be lowered to `t.expand[i]`. Is there some recourse, which explains the `alias this`? I still don't understand what it does. I can't imagine

How exactly does Tuple work?

2020-11-07 Thread Jan Hönig via Digitalmars-d-learn
I have a simple question. How exactly does Tuple work? In detail, I am interested in expand and opSlice. For expand, I have found the line: https://github.com/dlang/phobos/blob/master/std/typecons.d#L618 How does that work, where is the rest? What does it do? Similary I can access tuples

Re: Empty functions

2020-10-29 Thread Jan Hönig via Digitalmars-d-learn
On Thursday, 29 October 2020 at 09:01:12 UTC, Jan Hönig wrote: This would mean, that this one should work as well. It does not work as I intended, as `() => {}` has not the return type of `void`. (I don't know how to print: `ReturnType!(() => {})`)

Re: Empty functions

2020-10-29 Thread Jan Hönig via Digitalmars-d-learn
On Thursday, 29 October 2020 at 08:48:59 UTC, rikki cattermole wrote: () => {} Is actually: () => Expression Rule: ref|opt ParameterWithMemberAttributes => AssignExpression https://dlang.org/spec/expression.html#lambdas This would mean, that this one should work as well. And you can![1] I

Empty functions

2020-10-29 Thread Jan Hönig via Digitalmars-d-learn
I have asked this on StackOverflow[1]. I have received a valid answer, which solves my problem, however, I have still not understood, why some versions of it work and some don't. The code is here[2]. I don't understand why `a` compiles just fine, while `b` and `c` don't. I think, that I

Re: What is the difference between enum and shared immutable?

2020-10-29 Thread Jan Hönig via Digitalmars-d-learn
On Wednesday, 28 October 2020 at 22:07:06 UTC, H. S. Teoh wrote: [...] An enum only exists at compile-time, and does not occupy any space. Each time it's referenced, a new instance of the value is created. (This is why it's a bad idea to use enum with an array literal, because every time

What is the difference between enum and shared immutable?

2020-10-28 Thread Jan Hönig via Digitalmars-d-learn
Maybe this is a silly question, but I don't understand completely the difference between an `enum` and a `shared immutable`. I could have: enum x = 1; or shared immutable x = 1; What is the exact difference between those too? My best guess is, that shared immutable gets initialized during

Re: Wanted! Tree Node implementation.

2020-10-12 Thread Jan Hönig via Digitalmars-d-learn
On Wednesday, 7 October 2020 at 14:31:20 UTC, Виталий Фадеев wrote: Wanted! Tree Node implementation. Like a: mixin template TreeNode( T ) { T parent; T firstChild; T lastChild; T prevSibling; T nextSibling; // ForwardRange implementation @property T front() { ...

Re: Why does compose from std.functional return a templated function

2020-09-16 Thread Jan Hönig via Digitalmars-d-learn
On Wednesday, 16 September 2020 at 10:50:06 UTC, Daniel Kozak wrote: On Wed, Sep 16, 2020 at 12:00 PM Jan Hönig via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: ... My main question is why? Is there something, which I am missing, that explains, why it is bene

Why does compose from std.functional return a templated function

2020-09-16 Thread Jan Hönig via Digitalmars-d-learn
I have toyed with the compose template in std.functional and ran into some problems. rikki_cattermole on discord helped me a lot to solve my problem. However, what still remains (for me) to understand is why. Source code for `compose`:

Re: Metaprogramming with D

2020-06-08 Thread Jan Hönig via Digitalmars-d-learn
On Sunday, 7 June 2020 at 00:45:37 UTC, Ali Çehreli wrote: dmd -mixin= ... thanks for the tip! writeln(q{ void foo() { } }); What is the name of this `q` thing? How do i find it? Are there any recent tutorials on it?

Metaprogramming with D

2020-06-06 Thread Jan Hönig via Digitalmars-d-learn
We have two (little) student projects, which should use D for meta-programming/code generation. More specifically string mixins and templates. I understand (at least I think so :)) string mixins. The task is to create a small internal DSL, which is capable of printing out D code, which we

Re: Fighting the DList

2020-05-16 Thread Jan Hönig via Digitalmars-d-learn
On Saturday, 16 May 2020 at 08:11:20 UTC, Jan Hönig wrote: I am convinced that this works. I have another implementation, which should work: https://run.dlang.io/is/tfBgD0 It is not pretty. It is probably not fast, if the `ignore` is too large. I guess it is in O(n^2) if not O(mn^2), where m

Fighting the DList

2020-05-16 Thread Jan Hönig via Digitalmars-d-learn
I want a simple algorithm. Given DList (or a Range, Array... I am not constrained by the container type), I want to combine certain elements depending on some condition. In the toy example, the struct and condition are simpler then in my real scenario, but i think it covers my problem:

Jupyter notebook with Dlang

2020-04-29 Thread Jan Hönig via Digitalmars-d-learn
Today I have been toying around with jupyter. I wanted to know how it works (since I use it with Python all the time). I was trying to couple xeus[3] with drepl[4] together. But now (after using google and not duckduckgo), I have found multiple projects, which attempted similar things. It

Re: Compililng C++ and D together without going mad

2020-04-29 Thread Jan Hönig via Digitalmars-d-learn
On Wednesday, 29 April 2020 at 13:12:50 UTC, Johan wrote: Manually initializing D's runtime is also possible. You need to call rt_init and rt_term: https://dlang.org/phobos/core_runtime.html#.rt_init What I meant is to - add a `int main()` in a D source file - rename your current `main`

Re: Compililng C++ and D together without going mad

2020-04-29 Thread Jan Hönig via Digitalmars-d-learn
On Wednesday, 29 April 2020 at 13:02:36 UTC, Jan Hönig wrote: I will probably need: Also this thing: https://github.com/nlohmann/json

Re: Compililng C++ and D together without going mad

2020-04-29 Thread Jan Hönig via Digitalmars-d-learn
On Wednesday, 29 April 2020 at 11:38:16 UTC, Johan wrote: LDC is a (somewhat complex) project with D and C++ code (and external C++ libraries). I think it will help you if your main() is in D (such that druntime is automatically initialized for you). https://github.com/ldc-developers/ldc

Compililng C++ and D together without going mad

2020-04-29 Thread Jan Hönig via Digitalmars-d-learn
In my pet project, I am using some C++ libraries. The main file/function is also C++. All of it successfully compiles with cmake. Now I want to add some functionality by calling my own D functions (which use some other modules/projects/phobos). My questions is, what is the "proper" building

Re: D on android and d_android

2020-04-07 Thread Jan Hönig via Digitalmars-d-learn
On Tuesday, 7 April 2020 at 14:51:15 UTC, H. S. Teoh wrote: On Tue, Apr 07, 2020 at 12:43:20PM +, Adam D. Ruppe via Digitalmars-d-learn wrote: On Monday, 6 April 2020 at 08:38:03 UTC, Jan Hönig wrote: > Is there some "Hello World!" example for D on Android? [...] > However there is just

Re: D on android and d_android

2020-04-07 Thread Jan Hönig via Digitalmars-d-learn
On Tuesday, 7 April 2020 at 12:43:20 UTC, Adam D. Ruppe wrote: On Monday, 6 April 2020 at 08:38:03 UTC, Jan Hönig wrote: Is there some "Hello World!" example for D on Android? So I did a tiny thing in the repo: https://github.com/adamdruppe/d_android/tree/master/android-dub-test if you open

Re: D on android and d_android

2020-04-06 Thread Jan Hönig via Digitalmars-d-learn
Little off-topic, but I think it should fit here well. Is there some "Hello World!" example for D on Android? Having a simple example is a great springboard to start a project with lot of unknowns. On the weekend I started creating an App (kotlin), really simple stuff. However there is just

Re: Blog post about multidimensional arrays in D

2020-03-30 Thread Jan Hönig via Digitalmars-d-learn
On Friday, 27 March 2020 at 14:18:13 UTC, p.shkadzko wrote: I agree. I was planning to do several follow-ups after this first brief overview. For example, looks like just one "byDim" requires a separate post. The goal was just to show ppl who know nothing or a little about D and Mir that Mir

Re: Best way to learn 2d games with D?

2020-03-17 Thread Jan Hönig via Digitalmars-d-learn
I made a similar search two months ago as well. I recommend a simple library. I landed with https://code.dlang.org/packages/raylib-d It is supposed to be for learning how to do 2d games. It is easy to work with, which was my main search parameter. I need to figure out the logic, physics,

Re: Some impressions/notes from a new D programmer

2020-02-12 Thread Jan Hönig via Digitalmars-d-learn
On Wednesday, 12 February 2020 at 10:39:06 UTC, mark wrote: I've been learning D for a few weeks now. ... I made exactly the same experience in December.

Re: How to use sets in D?

2020-02-07 Thread Jan Hönig via Digitalmars-d-learn
On Friday, 7 February 2020 at 19:37:08 UTC, mark wrote: I am porting code from other languages to D as part of learning D, and I find I've used sets quite a lot. AFAIK D doesn't have a built-in set type or one in the std. lib. However, I've been perfectly successfully using int[E] where E is

Re: Can't compile dlangui

2020-02-07 Thread Jan Hönig via Digitalmars-d-learn
On Friday, 7 February 2020 at 12:04:10 UTC, A.Perea wrote: Hi, I'm trying to compile dlangide, and it fails when compiling the dependency dlangui. Trying to compile dlangui independently gives the same error message (see below for full stack trace) As phobos nor dlangui can be broken, it

Re: books for learning D

2020-01-31 Thread Jan Hönig via Digitalmars-d-learn
On Friday, 31 January 2020 at 10:51:07 UTC, mark wrote: On Wednesday, 29 January 2020 at 11:57:14 UTC, Jan Hönig wrote: On Monday, 13 January 2020 at 16:37:31 UTC, Ron Tarrant wrote: On Monday, 13 January 2020 at 10:28:48 UTC, mark wrote: [...] Actually, Andrei's book has been updated a few

Re: books for learning D

2020-01-29 Thread Jan Hönig via Digitalmars-d-learn
On Monday, 13 January 2020 at 16:37:31 UTC, Ron Tarrant wrote: On Monday, 13 January 2020 at 10:28:48 UTC, mark wrote: I'm just starting out learning D. Andrei Alexandrescu's "The D Programming Language" is 10 years old, so is it still worth getting? (I don't know how much D has changed in

Re: CTFE, string mixins & code generation

2020-01-24 Thread Jan Hönig via Digitalmars-d-learn
On Friday, 24 January 2020 at 18:43:14 UTC, H. S. Teoh wrote: CTFE in general cannot use global variables. Any state you need must be created inside a CTFE function, and accessed from within that calling context. You *can* assign values produced by CTFE to compile-time symbols via 'enum',

Re: CTFE, string mixins & code generation

2020-01-24 Thread Jan Hönig via Digitalmars-d-learn
On Friday, 24 January 2020 at 16:59:53 UTC, Marco de Wild wrote: For CTFE: functions should be pure. Therefore you cannot use global or static variables. Constants (enums) are perfectly fine to use though. I don't know the state of the GC and CTFE. I recall that there might be some complexity

CTFE, string mixins & code generation

2020-01-24 Thread Jan Hönig via Digitalmars-d-learn
I am looking for a detailed explanation or showcase regarding CTFE and string mixins. I want to play with D a little bit regarding code generation. I would like to have a pseudo-AST, consisting of a few classes, to represent some calculation. Think of a loop, some statements, and expressions.

Re: Blog Post #0099: A Special Request

2020-01-22 Thread Jan Hönig via Digitalmars-d-learn
On Tuesday, 21 January 2020 at 22:06:30 UTC, Ron Tarrant wrote: On Tuesday, 21 January 2020 at 18:57:47 UTC, Jan Hönig wrote: I would also like to request a future blog post about animation. I know you have done that in the past, but i am thinking of some animation triggered by user input

Re: Blog Post #0099: A Special Request

2020-01-21 Thread Jan Hönig via Digitalmars-d-learn
On Tuesday, 21 January 2020 at 14:02:59 UTC, Ron Tarrant wrote: Today's post was requested by Joel Christensen, how to have one button affect another. You can find it here: https://gtkdcoding.com/2020/01/21/0099-sfx-button-interactions-i-text-labels.html Hi Ron. Your blog is great. I have

Re: DMD docker image

2020-01-18 Thread Jan Hönig via Digitalmars-d-learn
On Friday, 17 January 2020 at 17:31:29 UTC, Andre Pany wrote: If you really need small images, you could switch to Alpine, but MUSL c could lead to headaches ;) There are also the official docker images https://hub.docker.com/u/dlang2 What is your goal? Do you want to compile s.th. in your

DMD docker image

2020-01-17 Thread Jan Hönig via Digitalmars-d-learn
I have created a docker image. However the image size is not small (~500MB). I wonder if others have a suitable dockerfile. All i want is to install the current dmd release. Does somebody have something similar? Does somebody need something similar? My dockerfile: ``` FROM ubuntu:latest

Re: Intersection of two sets

2019-12-06 Thread Jan Hönig via Digitalmars-d-learn
On Wednesday, 4 December 2019 at 08:01:59 UTC, Per Nordlöw wrote: On Tuesday, 3 December 2019 at 13:43:26 UTC, Jan Hönig wrote: pseudocode: alias set = bool[] set foo = ... set bar = ... set result; One simple optimization is to set* smallest; set* largest; if (foo.length < bar.length) {

Re: Intersection of two sets

2019-12-03 Thread Jan Hönig via Digitalmars-d-learn
On Tuesday, 3 December 2019 at 13:55:51 UTC, Alex wrote: This depends on the available accesses on your sets. In terms of ranges: Are your sets InputRanges, ForwardRange, ... ? 2) Are there some build-in function for handling such sets? This is maybe what you are looking for:

Re: Intersection of two sets

2019-12-03 Thread Jan Hönig via Digitalmars-d-learn
On Tuesday, 3 December 2019 at 15:14:03 UTC, ikod wrote: Never tried, but depending of the nature of your "something" you can try bit sets. There are efficient algorithms for large bit arrays (see "roaring" for example). "roaring" is massive overkill for my case, but thanks for suggesting

Intersection of two sets

2019-12-03 Thread Jan Hönig via Digitalmars-d-learn
It seems i don't google the right keywords. What i want to do: I have two sets. (I didn't find how to do sets, so i have two associative boolean arrays `bool[]`). And i want to join them, via an intersection. I know how to code this. Loop over one AA, if the key is also in the other one,

Floating-Point arithmetic in dlang - Difference to other languages

2019-12-03 Thread Jan Hönig via Digitalmars-d-learn
Today i have stumbled on Hacker News into: https://0.30004.com/ I am learning D, that's why i have to ask. Why does writefln("%.17f", .1+.2); not evaluate into: 0.30004, like C++ but rather to: 0.2 Many other languages evaluate to