Re: dual with statement
On Friday, 25 July 2014 at 21:10:56 UTC, monarch_dodra wrote: Functionally nothing more than an alias? EG: { alias baz = foo.bar; ... } Yes, it is all just alias. So with ( (d,e,a,b,c) as (ar.rm.a, ar.rm.b, ar.r.a, ar.r.b, ar.r.c)){ d = a + c; e = (c==0)?0:(a+b)/c; } could be instead { alias d = ar.rm.a; alias e = ar.rm.b; alias a = ar.r.a; alias b = ar.r.b; alias c = ar.r.c; d = a + c; e = (c==0)?0:(a+b)/c; } I guess this means I don't need WITH.
Re: dual with statement
On Friday, 25 July 2014 at 01:54:53 UTC, Jay Norwood wrote: I don't recall the exact use case for the database expressions, but I believe they were substituting a simple symbol for the fully qualified object. The sql with clause is quite a bit different than I remembered. For one thing, I have the order reversed, so it would have been with (a as something.x.y). It looks more like they are more like creating a temporary tuple from some more complicated selection. It isn't clear what the implementation is, but just the that it might be a more concise way of stating things so that the expressions inside the body can be simple So, my prior example with (ar.rm.a as d) with (ar.rm.b as e) with (ar.r.a as a) with (ar.r.b as b) with (ar.r.c as c){ d = a + c; e = (c==0)?0:(a+b)/c; } would reduce to something maybe simpler to read. The sql seems to be using this as a foreach type operation, but I was just interested in the name substitution so that the expressions inside the with block could be simpler, as well as get rid of the struct member name clashes. with ( (d,e,a,b,c) as (ar.rm.a, ar.rm.b, ar.r.a, ar.r.b, ar.r.c)){ d = a + c; e = (c==0)?0:(a+b)/c; }
Re: dual with statement
On Friday, 25 July 2014 at 01:54:53 UTC, Jay Norwood wrote: On Thursday, 24 July 2014 at 20:16:53 UTC, monarch_dodra wrote: Or did I miss something? Yes, sorry, I should have pasted a full example previously. The code at the end is with the Raw_met members renamed (they were originally a and b but clashed). So, if Raw_met members were still a and b ... with(ar.r as v) with (ar.rm as res){ res.a = v.a + v.c; res.b = (v.c==0)? 0: (v.a + v.b)/ v.c; I don't recall the exact use case for the database expressions, but I believe they were substituting a simple symbol for the fully qualified object. So they would have done something analogous to this ... Isn't: with(foo.bar as baz) { ... } Functionally nothing more than an alias? EG: { alias baz = foo.bar; ... } Or mix of both. I don't see a need for as.
dual with statement
I was playing around with use of the dual WITH statement. I like the idea, since it makes the code within the with cleaner. Also, I got the impression from one of the conference presentations ... maybe the one on the ARM debug ... that there are some additional optimizations available that the compiler processes the WITH statement block. Anyway, a problem I ran into was if two structures had the same member names, for example struct ar.r and ar.psm in this case below. In this case, there was no way for the compiler to determine from which structure to get the member. void calc_per_sec_met(ref All ar){ with (ar.r) with(ar.psm) { double per_sec = proc_cyc/ref_clock; d = (a+c)*per_sec; e = (c==0)?0:(a+b)/c; } } ok, so I guess I could make all the member names unique in the different structures, but that's kind of ugly. Also, what happens if using two structs of the same type in a WITH statement. Seems like something like this would help, which I believe I've seen used in database queries ... with (ar.r1 as r1) with (ar.r2 as r2){ auto sum = r1.a + r2.a; }