Re: trait to get the body code of a function?

2018-07-29 Thread Mr.Bingo via Digitalmars-d-learn
So, does anyone want to take up the challenge of writing such a function that can safely get the function body? I guess D CTFE'able D parser would be required and basically use what I've given above. I've seen a few lexers around but not messed with them. This will at least fill in a gap.

Re: How to best implement a DSL?

2018-07-29 Thread Mr.Bingo via Digitalmars-d-learn
On Saturday, 28 July 2018 at 14:59:31 UTC, Robert M. Münch wrote: Hi, I'm seeking for ideas/comments/experiences how to best implement a DSL in D. What I would like to do is something like this: ... my D code ... my-dsl { ... my multi-line DSL code ...

Re: trait to get the body code of a function?

2018-07-26 Thread Mr.Bingo via Digitalmars-d-learn
On Thursday, 26 July 2018 at 13:27:09 UTC, Alex wrote: On Thursday, 26 July 2018 at 11:54:39 UTC, Mr.Bingo wrote: The string itself could be useful however... Whatever OP has in mind with this string... Having a code block is useful in many ways simply because not having it is the most

Re: trait to get the body code of a function?

2018-07-26 Thread Mr.Bingo via Digitalmars-d-learn
On Thursday, 26 July 2018 at 10:20:04 UTC, Alex wrote: On Thursday, 26 July 2018 at 07:32:19 UTC, Mr.Bingo wrote: If all you need is the string you can write a template function that imports the file and searches for the function and returns it's body. It's not very robust but it can work

Re: trait to get the body code of a function?

2018-07-26 Thread Mr.Bingo via Digitalmars-d-learn
On Tuesday, 24 July 2018 at 04:43:33 UTC, Guillaume Lathoud wrote: Hello, __traits and std.traits already offer access to function information like input parameters, e.g. in std.traits: ParameterIdentifierTuple ParameterStorageClassTuple Even if that might sound strange, is there a compile

Re: Cleanup class after method?

2018-07-04 Thread Mr.Bingo via Digitalmars-d-learn
On Wednesday, 4 July 2018 at 15:47:25 UTC, JN wrote: Imagine I have a very short-lived class: void print(File f) { PrinterManager pm = new PrinterManager(); pm.print(f); } My understanding is that PrinterManager will be GC allocated, and when it goes out of scope, the GC will possibly

Re: Recursive Algebraic

2018-06-30 Thread Mr.Bingo via Digitalmars-d-learn
The problem is that it seems that when one has a parameterized type, you must completely specify the parameters when using Algebraic, Algebraic!(T, Vector!int, Vector!(double, 3), Vector!(double, 3), ...)[] data; to be able to encapsulate an Algebraic on Vector(as a collection of all fixed

Recursive Algebraic

2018-06-30 Thread Mr.Bingo via Digitalmars-d-learn
I'm trying to create a vector of vectors(more general than vectors or matrices). The idea is that a Vector can contain another Vector or another type. Vector can be specified to be fixed in length or dynamic for efficiency. Vector!(T, N) creates a vector of leaf type T and length N. If N =

Re: Why tuples are not ranges?

2018-06-28 Thread Mr.Bingo via Digitalmars-d-learn
On Thursday, 28 June 2018 at 18:03:09 UTC, Ali Çehreli wrote: On 06/28/2018 10:00 AM, Mr.Bingo wrote: > But is this going to be optimized? Not our job! :o) > That is, a tuple is a range! Similar to the array-slice distinction, tuple is a container, needing its range. > It is clearly easy

Re: Why tuples are not ranges?

2018-06-28 Thread Mr.Bingo via Digitalmars-d-learn
On Thursday, 28 June 2018 at 16:02:59 UTC, Alex wrote: On Thursday, 28 June 2018 at 14:35:33 UTC, Mr.Bingo wrote: Seems like it would unify things quite a bit. Yeah... this is, because you can't popFront on a tuple, as the amount of entries is fixed. You can, however, popFront on every

Why tuples are not ranges?

2018-06-28 Thread Mr.Bingo via Digitalmars-d-learn
Seems like it would unify things quite a bit. import std.typecons, std.range, std.array, std.algorithm, std.stdio; void main() { auto t = tuple(3,4,5,6); //auto t = [3,4,5,6]; writeln(t.map!(a => 3*a).sum()); }

Re: Code failing unknown reason out of memory, also recursive types

2018-06-25 Thread Mr.Bingo via Digitalmars-d-learn
On Monday, 25 June 2018 at 14:41:28 UTC, rikki cattermole wrote: Let me get this straight, you decided to max out your memory address space /twice over/ before you hit run time, and think that this would be a good idea? Well, that cause was suppose to allocate a dynamic array instead of a

Re: overload .

2018-06-25 Thread Mr.Bingo via Digitalmars-d-learn
On Monday, 25 June 2018 at 13:58:54 UTC, aliak wrote: On Monday, 25 June 2018 at 13:37:01 UTC, Mr.Bingo wrote: One can overload assignment and dispatch so that something like A.x = ... is valid when x is not a typical member but gets resolved by the above functions. Therefore, I can create

Code failing unknown reason out of memory, also recursive types

2018-06-25 Thread Mr.Bingo via Digitalmars-d-learn
import std.stdio; union Vector(T, size_t N = size_t.max) { import std.range, std.typecons, std.meta, std.algorithm, std.conv, std.math; static if (N == size_t.max) // For size_t.max sets N to be infinite/dynamic; { mixin("Tuple!("~"T,".repeat(N).join()~") data;");

overload .

2018-06-25 Thread Mr.Bingo via Digitalmars-d-learn
One can overload assignment and dispatch so that something like A.x = ... is valid when x is not a typical member but gets resolved by the above functions. Therefore, I can create a member for assignment. How can I create a member for getting the value? A.x = 3; // Seems to get

Re: Determine if CTFE or RT

2018-06-25 Thread Mr.Bingo via Digitalmars-d-learn
On Monday, 25 June 2018 at 10:49:26 UTC, Simen Kjærås wrote: On Monday, 25 June 2018 at 09:36:45 UTC, Martin Tschierschke wrote: I am not sure that I understood it right, but there is a way to detect the status of a parameter: My question was different, but I wished to get a ctRegex! or

Re: Determine if CTFE or RT

2018-06-25 Thread Mr.Bingo via Digitalmars-d-learn
On Monday, 25 June 2018 at 07:02:24 UTC, Jonathan M Davis wrote: On Monday, June 25, 2018 05:47:30 Mr.Bingo via Digitalmars-d-learn wrote: The problem then, if D can't arbitrarily use ctfe, means that there should be a way to force ctfe optionally! If you want to use CTFE, then give an enum

Re: Determine if CTFE or RT

2018-06-24 Thread Mr.Bingo via Digitalmars-d-learn
On Monday, 25 June 2018 at 05:14:31 UTC, Jonathan M Davis wrote: On Monday, June 25, 2018 05:03:26 Mr.Bingo via Digitalmars-d-learn wrote: The compiler should be easily able to figure out that foo(3) can be precomputed(ctfe'ed) and do so. It can already do this, as you say, by forcing enum

Re: Determine if CTFE or RT

2018-06-24 Thread Mr.Bingo via Digitalmars-d-learn
On Sunday, 24 June 2018 at 20:03:19 UTC, arturg wrote: On Sunday, 24 June 2018 at 19:10:36 UTC, Mr.Bingo wrote: On Sunday, 24 June 2018 at 18:21:09 UTC, rjframe wrote: On Sun, 24 Jun 2018 14:43:09 +, Mr.Bingo wrote: let is(CTFE == x) mean that x is a compile time constant. CTFE(x)

Re: Determine if CTFE or RT

2018-06-24 Thread Mr.Bingo via Digitalmars-d-learn
On Sunday, 24 June 2018 at 18:21:09 UTC, rjframe wrote: On Sun, 24 Jun 2018 14:43:09 +, Mr.Bingo wrote: let is(CTFE == x) mean that x is a compile time constant. CTFE(x) converts a x to this compile time constant. Passing any compile time constant essentially turns the variable in to a

Determine if CTFE or RT

2018-06-24 Thread Mr.Bingo via Digitalmars-d-learn
let is(CTFE == x) mean that x is a compile time constant. CTFE(x) converts a x to this compile time constant. Passing any compile time constant essentially turns the variable in to a compile time constant(effectively turns it in to a template with template parameter) void foo(size_t i) {

Re: how to determine of a module or any other symbol is visible?

2018-06-18 Thread Mr.Bingo via Digitalmars-d-learn
On Monday, 18 June 2018 at 09:10:59 UTC, rikki cattermole wrote: On 18/06/2018 9:03 PM, Mr.Bingo wrote: In the code I posted before about CRC, sometimes I get a visibility error for some modules. I would like to be able to filter those out using traits. Is there any way to determine if a

how to determine of a module or any other symbol is visible?

2018-06-18 Thread Mr.Bingo via Digitalmars-d-learn
In the code I posted before about CRC, sometimes I get a visibility error for some modules. I would like to be able to filter those out using traits. Is there any way to determine if a module is visible/reachable in the current scope? The modules that are causing the problems are imported

Re: cyclic redundancy

2018-06-18 Thread Mr.Bingo via Digitalmars-d-learn
I got tired of waiting for a solution and rolled my own: static this() { import std.meta, std.stdio; // Find all ___This functions linked to this module auto Iterate()() { string[string] s; void Iterate2(alias m, int depth =

cyclic redundancy

2018-06-18 Thread Mr.Bingo via Digitalmars-d-learn
I have static this scattered throughout. Some are module static this and some are struct and class. In a test case I have reduced to a struct that uses a static this and I get a cycle... even though, of course, the static this does nothing accept internal things. It is very annoying to