On 07/26/2016 11:42 AM, drug wrote:
> Another option is `makeIndex` (std.algorithm.sorting) and then sorting
> of that index.
That's an interesting option; at least I don't have to touch the range.
Thanks.
--
Bahman
On 07/26/2016 10:41 AM, Jonathan M Davis via Digitalmars-d-learn wrote:
>> So it may be something about what kind of range I'm passing to `sort`.
>> Am I right?
>
> sort requires a random access range. Without knowing exactly which
> algorithms your using, I can't say for sure that that's the prob
On 07/26/2016 10:11 AM, Bahman Movaqar wrote:
> Alright...further experiments. The following works:
>
> sort!((pp1, pp2) => cmp(pp1.price, pp2.price) > 0)(theRange)
>
> So it may be something about what kind of range I'm passing to `sort`.
> Am I right?
>
I meant
sort!((pp1, pp2) =>
On 07/26/2016 09:35 AM, Bahman Movaqar wrote:
> I have a range which is the result of a couple of chained range
> operations, and each element is:
>
> Tuple!(string, "product", double, "price")
>
> Now I'd like to sort the range by "price" using:
>
> sort!((pp1, pp2) => cmp(pp1.price, p
I have a range which is the result of a couple of chained range
operations, and each element is:
Tuple!(string, "product", double, "price")
Now I'd like to sort the range by "price" using:
sort!((pp1, pp2) => cmp(pp1.price, pp2.price) > 0)(theRange)
But I get a compile time error:
sou
On 07/25/2016 05:47 PM, Adam D. Ruppe wrote:
> On Monday, 25 July 2016 at 13:09:22 UTC, Bahman Movaqar wrote:
>> From what I could gather, it's not possible to check for `null` at
>> runtime for reference based types. Am I right?
>
> No, it is only possible to check for null for reference based t
On 07/25/2016 05:07 PM, Bahman Movaqar wrote:
> Suppose I have the following function:
>
> public auto max(alias comp, Range)(Range r)
> in {
> assert(r !is null && !r.empty);
> }
> body {
> // ...
> }
>
> When the function after a series of chained `map` operation
Suppose I have the following function:
public auto max(alias comp, Range)(Range r)
in {
assert(r !is null && !r.empty);
}
body {
// ...
}
When the function after a series of chained `map` operations, I get the
following error:
Error: incompatible types for ((r
On 07/17/2016 12:38 AM, Seb wrote:
> There is no need for a module, but dub by default only checks files in
> the 'source' folder.
The file is already in the 'source' folder.
> For such simple tests you could also run them directly with rdmd
> -unittest. There is an additional -main flag if you d
On 07/15/2016 04:16 PM, Jerry wrote:
> Unittests have to be inside a module to be run on DMD atleast.
> So putting module foo at top should fix it.
Strange. Still not getting picked up.
$ dmd --version
DMD64 D Compiler v2.071.0
Copyright (c) 1999-2015 by Digital Mars written by Walte
The test I have in 'app.d' don't get picked up by 'dub test' in a
freshly created project by 'dub init'.
$ dub test
Generating test runner configuration '__test__library__' for
'library' (library).
Performing "unittest" build using dmd for x86_64.
dplay ~master: building configurat
Following up my D practices, I've created a 'groupBy' template[1] for
Stockman (my practice project).
I'd like to ask you more experienced folks to please take a look at it.
As this is my first template, I'd like to know if I am doing anything
idiomatically/logically wrong.
PS: I've also impleme
On 07/12/2016 04:21 PM, Edwin van Leeuwen wrote:
> On Tuesday, 12 July 2016 at 11:40:48 UTC, Bahman Movaqar wrote:
>> On 07/12/2016 01:01 PM, Mike Parker wrote:
>>> Do you have some sample code that shows the error?
>>
>> Yes. I'm working on Stockman[1] a playground to learn D.
>> In file `etl.d`,
On 07/12/2016 04:23 PM, ag0aep6g wrote:
> On 07/12/2016 01:40 PM, Bahman Movaqar wrote:
>> Yes. I'm working on Stockman[1] a playground to learn D.
>> In file `etl.d`, line 110 [2], if I change the line to
>> auto refInvoice = group[1].takeOne();
>> the file will not compile. I have attached
On 07/12/2016 01:01 PM, Mike Parker wrote:
> Do you have some sample code that shows the error?
Yes. I'm working on Stockman[1] a playground to learn D.
In file `etl.d`, line 110 [2], if I change the line to
auto refInvoice = group[1].takeOne();
the file will not compile. I have attached the
On 07/12/2016 11:06 AM, Mike Parker wrote:
> The 'Group' type is an implementation detail -- a type used internally
> -- that you aren't supposed to care about. All you need to care about is
> that it's a range. The documentation for chunkBy [1] explains what the
> return type is.
>
> [1] https://
On 07/12/2016 11:07 AM, Mike Parker wrote:
> auto foo(R)(R r) { ... }
That did it. Thanks.
Out of curiosity, does the same pattern apply to functions which take
`tuple`s as input arguments?
--
Bahman
When using `chunkBy` (unary pred) the result is a list of tuples. Each
tuple holds a key and a `Group` which belong to that key.
Where can I find the docs for this `Group` type (I have already tried
searching library on dlang.org)?
Thanks,
--
Bahman
What should be signature of `foo` in the following piece of code?
auto foo(range r) {
// do something with the `r`
}
void main() {
foo([1,2,3].map!(x => x*x));
}
Right now I use `.array` to convert the range before passing:
auto foo(int[] r) {
// do someth
On 07/11/2016 07:15 PM, Ali Çehreli wrote:
> Both AAs and slices behave like reference types even when passed by
> value: When a function adds an element, the argument sees that element
> as well. This is not the case when the argument is an empty (more
> correctly, null) AA or slice:
>
> void foo
On 07/11/2016 03:02 PM, Mike Parker wrote:
> You can do it in D with custom format specifiers. See:
>
> https://wiki.dlang.org/Defining_custom_print_format_specifiers
Thanks for the pointer. I'll keep that in mind.
--
Bahman
On 07/11/2016 06:30 PM, Steven Schveighoffer wrote:
> Untested, but you could try MySt[][string].init.
That did it. Thanks.
> But passing empty AA by value sometimes can be surprising. I'm not sure
> if it will work.
Could you elaborate more?
--
Bahman
I'm processing a list of structs (MySt) with `reduce` to produce an
associate array of type `MySt[][string]`.
Right now I'm using the following (slimmed down) code:
MySt[][string] result;
return reduce!(
function MySt[][string](MySt[][string] acc, MySt val) {
// do something
On 07/11/2016 02:44 PM, ketmar wrote:
> On Monday, 11 July 2016 at 09:31:49 UTC, Ali Çehreli wrote:
>> What makes you expect that format should have that feature? :)
I somehow recalled I could do that in C and then there was the "minimum
field width" in the docs, so I thought it's possible I'm jus
I'm sure I'm missing something very simple but how can I create a string
like "" using `format`?
I check the docs on `format` and tried many variations including
`format("%.*c\n", 4, '-')` but got nowhere.
I'd appreciate any hint/help on this.
--
Bahman Movaqar
http://BahmanM.com - https://
On 09/12/2015 04:04 PM, Bahman Movaqar wrote:
> Oops! Here's one using only `InputRange` interface:
I believe I need to warn you that I'm just learning D; so take my
solution at your own risk :-)
--
Bahman Movaqar
On 09/12/2015 03:09 PM, "Nordlöw" wrote:
> InputRange please, not RandomAccessRanges ;)
Oops! Here's one using only `InputRange` interface:
T[][] collate(T)(T[] a)
{
alias CollateResult = Tuple!(T[][], "result", T, "tlHd");
CollateResult _collate(CollateResult collres)
On 09/12/2015 02:47 PM, "Nordlöw" wrote:
> How do I most elegantly iterate all the adjacent pairs in an
> `InputRange` using Phobos?
>
> Something like
>
> [1,2,3,4] => [(1,2), (2,3), (3,4)]
That's call `collate`ing IIRC.
A quick solution would be using `std.range.transposed`:
auto a = [1,2
On 09/12/2015 12:52 PM, NX wrote:
> What if I told you, you should search the official reference before
> asking such things in the forum?
I did search the net for terms such as "d lang back quoted string" or "d
lang multi line string" or "d lang string interpolation" before asking here.
However t
Is there any or they are just simply syntactically equivalent?
Are there any official docs on this?
--
Bahman Movaqar
http://BahmanM.com - https://twitter.com/bahman__m
https://github.com/bahmanm - https://gist.github.com/bahmanm
PGP Key ID: 0x6AB5BD68 (keyserver2.pgp.com)
signature.asc
Descr
On Friday, 11 September 2015 at 21:06:32 UTC, Ali Çehreli wrote:
On 09/11/2015 02:04 PM, Ali Çehreli wrote:
The same keyword has a different use with
templates:
And the official documentation:
http://dlang.org/template.html#TemplateAliasParameter
Thanks again!
On Friday, 11 September 2015 at 18:39:15 UTC, Ali Çehreli wrote:
>> import std.stdio;
>>
>> bool isEven(int n) {
>> return !(n % 2);
>> }
>>
>> int readValidInt(alias validator)(string prompt) {
readValidInt() is a function template that takes two
information:
1) The validator as its alia
On Friday, 11 September 2015 at 19:51:09 UTC, Dave Akers wrote:
That's enough for me, I suppose.
I am thinking of having a family of functions in my
structs/classes as `as` family, such as `asDouble`, `asFooBar`.
Would it be possible to create it as an 'as' template?
Hmm...there's already th
On Friday, 11 September 2015 at 16:33:52 UTC, Meta wrote:
The only ways to get implicit conversion between two types in D
are through `alias this`, inheritance, or implementing an
interface.
That's enough for me, I suppose.
I am thinking of having a family of functions in my
structs/classes a
On Friday, 11 September 2015 at 16:31:46 UTC, Adam D. Ruppe wrote:
explicit is the only way to go. That's easy to do, just write
like a .get method or something that does the conversion and
returns it.
Fair enough. Type conversion is one of those spots that I'd like
it to as explicit as poss
As only one `alias this` is possible for any type, how should one
implement multiple implicit type converters?
Actually I'm looking for something similar to Groovy's `asType`
method[1]. An example in Groovy:
Point p = new Point(1, 1)
assert (p as BigDecimal[]) == [1, 1]
assert (p
On Friday, 11 September 2015 at 06:14:18 UTC, Ali Çehreli wrote:
On 09/06/2015 12:05 PM, Bahman Movaqar wrote:
> alias bool function(int n) validator_t;
There is the relatively newer alias syntax which is more
intuitive:
alias Validator = bool function(int n);
Great. This is easily re
On Wednesday, 9 September 2015 at 13:16:49 UTC, cym13 wrote:
True. But is pumping the output of `filter` as the seed into
`reduce` really considered weird usage!?
I don't think it is really weird per se, I just can't think of
a case where there isn't a better way to do it. I find it
complete
On Wednesday, 9 September 2015 at 08:29:20 UTC, cym13 wrote:
You are using reduce in a weird way here...
Oh? Perhaps it was all because of the lame example I used :-)
The real problem I was trying to solve, source of which I just
pushed[1], was the `select` method on line 130. Is this
idiom
On Wednesday, 9 September 2015 at 09:08:28 UTC, Atila Neves wrote:
No, it doesn't. It needs to know what the compile-time
interface is, i.e. what it can do with that type. If the type
in question happens to be an InputRange, then the consumer
function would be:
void func(R)(R range) if(isInpu
On Wednesday, 9 September 2015 at 07:59:57 UTC, Sebastiaan Koppe
wrote:
What is going wrong is that the types aren't the same. That is,
the type of the seed you supplied - `typeof(foobars)` - isn't
the type that your function returns - `typeof(acc.filter!...)`.
Alright. So, `reduce` initial s
On Tuesday, 8 September 2015 at 18:45:33 UTC, Jonathan M Davis
wrote:
If you're returning a range, you should be returning auto.
@Jonathan, @cym13 and @Meta
It's reasonable to use `auto`. However there are times when you
need to pass the `auto` value to another function and the
receiving fun
On Tuesday, 8 September 2015 at 10:08:03 UTC, cym13 wrote:
Filter is a template and returns a FilterResult range which is
used to lazily compute the result. This behaviour is the same
for map and the majority of functions in std.algorithm.
Ah...now it makes sense why use a proxy to the results
From what I can gather the output of `std.algorithm.iteration :
filter` is a `FilterResult` type.
I need a bit of help dealing with this type:
1. Why this type is there in the first place instead of simply
using the type of input range?
2. Where is the documentation for this type? The docum
On Monday, 7 September 2015 at 14:54:04 UTC, Jacob Carlborg wrote:
On 2015-09-07 16:44, Bahman Movaqar wrote:
Does this mean that in the following piece of code, what is
passed to
`add` is actually a copy of `rec1`?
auto rec1 = SalesRecord("p10", 1.0, 10);
coll.add(rec1);
Yes. struc
On Monday, 7 September 2015 at 14:28:06 UTC, Namespace wrote:
On Monday, 7 September 2015 at 14:12:25 UTC, Bahman Movaqar
wrote:
Structs are value types and therefore you return only a copy
currently.
Does this mean that in the following piece of code, what is
passed to `add` is actually a co
On Monday, 7 September 2015 at 14:26:57 UTC, mzf wrote:
On Monday, 7 September 2015 at 14:12:25 UTC, Bahman Movaqar
wrote:
struct is a value type,you can convert to ref type by "ref":
struct Test
{
int a;
Test add1()
{
a++;
return thi
I need some help understand the behaviour of my code[1].
Specifically I have trouble with `add` method on line 79.
My impression is that since it returns `this`, multiple
invocations can be chained like `obj.add(X).add(Y).add(Z)`.
However the test on line 92 fails and if I do a `writeln`, on
On Monday, 7 September 2015 at 12:16:14 UTC, anonymous wrote:
On Monday 07 September 2015 14:12, Bahman Movaqar wrote:
Thanks. This is indeed helpful. OT but where can I view the
documentation for `unittest` and `assert`?
unittest: http://dlang.org/unittest.html
assert: http://dlang.org/exp
On Monday, 7 September 2015 at 12:06:09 UTC, anonymous wrote:
On Monday 07 September 2015 13:57, Bahman Movaqar wrote:
$ dub test
[...]
core.exception.AssertError@source/e002.d(111): unittest
failure
[...]
From that one line I left intact above, you should also be able
to figure ou
On Monday, 7 September 2015 at 11:49:32 UTC, anonymous wrote:
void f(int a) {}
void g(int* a) {}
void main()
{
int xm;
immutable int xi;
f(xm); /* ok, obviously */
f(xi); /* ok */
int* ym = &xm;
immutable int* yi = ξ
g(ym); /* ok, obviously */
g(yi); /* doesn't c
I am working on a simple project created with DUB[1].
When unit tests the output reads really cryptic to me; for
example:
$ dub test
Generating test runner configuration '__test__library__' for
'library' (library).
Target dunit 1.0.11 is up to date. Use --force to rebuild.
Bui
On Monday, 7 September 2015 at 10:55:13 UTC, anonymous wrote:
On Monday 07 September 2015 12:40, Bahman Movaqar wrote:
I can see some serious advantages of this, most notable of
which is minimum side-effect and predictability of the code.
However I suppose it's going to impact the performance
It seems to me a good practice to mark all functions that I write
as `pure` and define all the variables as `immutable`, unless
there is a reason not to.
I can see some serious advantages of this, most notable of which
is minimum side-effect and predictability of the code. However I
suppose it
On Monday, 7 September 2015 at 03:55:01 UTC, Meta wrote:
The name validator_t is not idiomatic in D. Something like
ValidatorFun should be preferred. Same for intReader_t;
ReadIntFun is probably preferred, or even IntReader (but that
would imply that it's a struct/class in my mind).
Noted. Th
On Sunday, 6 September 2015 at 19:22:41 UTC, welkam wrote:
I dont know much about functional programming, but what stops
you defining
int readInt(string prompt, validator_t validator) { ... }
as a free standing function and just call it from both parts of
your code? What is the benefit of ind
I'm just learning D, so please bear with me if I'm asking
something naive.
Consider the following code skeleton:
// in part A of the application...
//
-
alias bool function(int n) validator_t;
bool isEven(int n) { ...
57 matches
Mail list logo