On Thursday, 13 May 2021 at 18:31:41 UTC, Ali Çehreli wrote:
On 5/13/21 11:29 AM, Ali Çehreli wrote:
create a dynamic InputRange!string object for dynamic
polymorphism that InputRange provides. And that's achieved by
function inputRangeObject():
Some examples:
http://ddili.org/ders/d.en/ra
On Thursday, 13 May 2021 at 18:29:08 UTC, Ali Çehreli wrote:
On 5/13/21 10:07 AM, Jeff wrote:
> I have a class where I'd like to supply it with an
InputRange!string.
> Yet, for the life of me I can't seem to pass to it a
File.byLine
As Adam said, your range elements need to be converted to
str
sorry, in this code i mean b must be [5, 4]
```d
auto arr = [1, 2, 3, 4, 5];
auto a = new A!int(arr);
auto b = a.retro[0 .. 2]; //5,4
```
How can I implement ranges in the retro range? I'd like to do
this without allocate a new array with .array from std.array, can
I do that?
use like this:
```d
auto arr = [1, 2, 3, 4, 5];
auto a = new A!int(arr);
auto b = a.retro[0 .. 2]; // 4, 5
```
the class:
```d
class A(T)
{
I have the feeling it is a pragmatic definition of pure. (isClose)
Although a compiler message , which does not even be a warning,
is always a nice to have.
On Thursday, 13 May 2021 at 21:41:48 UTC, Imperatorn wrote:
[...]
[1] https://en.wikipedia.org/wiki/Pure_function
Just fyi:
https://dlang.org/articles/safed.html
Replied to the wrong post?
On Thursday, 13 May 2021 at 17:13:40 UTC, kdevel wrote:
On Thursday, 13 May 2021 at 16:40:29 UTC, Imperatorn wrote:
Wouldn't this just this do that? 🤔
```d
string dequote(string s)
{
return s[1..$-1];
}
```
1. Your code throws Range errors if s.length < 2.
2. assert(dequote(`"fo\"o"`) ==
On Thursday, 13 May 2021 at 21:38:25 UTC, Adam D. Ruppe wrote:
On Thursday, 13 May 2021 at 21:30:43 UTC, Marcone wrote:
template foo(alias pred = "a*b"){
void foo(int x, int y){
writeln(x.unaryFun!pred);
First, you really shouldn't use these at all. instead of a
string
On Thursday, 13 May 2021 at 21:38:25 UTC, Adam D. Ruppe wrote:
On Thursday, 13 May 2021 at 21:30:43 UTC, Marcone wrote:
template foo(alias pred = "a*b"){
void foo(int x, int y){
writeln(x.unaryFun!pred);
First, you really shouldn't use these at all. instead of a
string
On Thursday, 13 May 2021 at 17:48:34 UTC, kdevel wrote:
On Thursday, 13 May 2021 at 13:45:50 UTC, Adam D. Ruppe wrote:
On Thursday, 13 May 2021 at 13:30:29 UTC, Alain De Vos wrote:
[...]
pure means it doesn't depend on any mutable info outside its
arguments.
You are only working on the arg
On Thursday, 13 May 2021 at 21:30:43 UTC, Marcone wrote:
template foo(alias pred = "a*b"){
void foo(int x, int y){
writeln(x.unaryFun!pred);
First, you really shouldn't use these at all. instead of a
string, just pass an actual function to the thing as the
predicate.
import std;
template foo(alias pred = "a*b"){
void foo(int x, int y){
writeln(x.unaryFun!pred);
}
}
void main(){
foo(5, 4);
}
"a" works, but "b" not work.
I get this error: Error: undefined identifier `b`
On 5/13/21 12:40 PM, Steven Schveighoffer wrote:
On 5/13/21 3:21 PM, PinDPlugga wrote:
This works but issues a deprecation warning:
```
onlineapp.d(30): Deprecation: returning `this` escapes a reference to
parameter `this`
onlineapp.d(30): perhaps annotate the parameter with `return`
F
On 5/13/21 3:21 PM, PinDPlugga wrote:
This works but issues a deprecation warning:
```
onlineapp.d(30): Deprecation: returning `this` escapes a reference to
parameter `this`
onlineapp.d(30): perhaps annotate the parameter with `return`
Fraction(1, 3)
```
I found several other ways to m
Hi I am working through Programming in D. In one exercise I have
a helper function in a struct
```D
struct Fraction {
auto n = 0L;
auto d = 1L;
// ... other bits ...
ref Fraction reduce() {
import std.numeric : gcd;
v = gcd(n, d);
if (v > 1) {
n /= v;
On 5/13/21 11:29 AM, Ali Çehreli wrote:
create a
dynamic InputRange!string object for dynamic polymorphism that
InputRange provides. And that's achieved by function inputRangeObject():
Some examples:
http://ddili.org/ders/d.en/ranges_more.html#ix_ranges_more.polymorphism,%20run-time
Ali
On 5/13/21 10:07 AM, Jeff wrote:
> I have a class where I'd like to supply it with an InputRange!string.
> Yet, for the life of me I can't seem to pass to it a File.byLine
As Adam said, your range elements need to be converted to string e.g.
with 'text' (the same as to!string). However, you mus
On Thursday, 13 May 2021 at 17:48:34 UTC, kdevel wrote:
Then D's pure does not match up with WP's definition [1] of
pure, at least not
Yeah, D's pure is actually useful without being a huge hassle.
Makes it into a useful building block that can be used inside
other scenarios than the purely p
On Thursday, 13 May 2021 at 13:45:50 UTC, Adam D. Ruppe wrote:
On Thursday, 13 May 2021 at 13:30:29 UTC, Alain De Vos wrote:
Or have I a wrong understanding of pure or the compiler.
pure means it doesn't depend on any mutable info outside its
arguments.
You are only working on the arguments
On Thursday, 13 May 2021 at 17:07:51 UTC, Jeff wrote:
I have a class where I'd like to supply it with an
InputRange!string. Yet, for the life of me I can't seem to pass
to it a File.byLine, even though the documentation states it's
an InputRange.
byLine is not a range of string. It is a range
On Thursday, 13 May 2021 at 16:40:29 UTC, Imperatorn wrote:
Wouldn't this just this do that? 🤔
```d
string dequote(string s)
{
return s[1..$-1];
}
```
1. Your code throws Range errors if s.length < 2.
2. assert(dequote(`"fo\"o"`) == `fo"o`) fails
3. dequote(`"fo"o"`) does not throw.
On Thursday, 13 May 2021 at 16:40:29 UTC, Imperatorn wrote:
Wouldn't this just this do that? 🤔
```d
string dequote(string s)
{
return s[1..$-1];
}
```
The idea would be for situations where it isn't known in advance
whether the string is quoted, if it is quoted properly, and
whether ther
On Thursday, 13 May 2021 at 14:10:08 UTC, cc wrote:
Does something to dequote (unquote? or what would you call it?)
a string exist in the standard library? I didn't see one in
std.string, just wondering before reinventing the wheel.
Something like:
```d
assert(dequote(`"foo"`) == "foo");
asse
I have a class where I'd like to supply it with an
InputRange!string. Yet, for the life of me I can't seem to pass
to it a File.byLine, even though the documentation states it's an
InputRange.
```
class Foo {
private InputRange!string source;
this(InputRange!string s) {
source = s;
On Thursday, 13 May 2021 at 14:10:08 UTC, cc wrote:
Does something to dequote (unquote? or what would you call it?)
a string exist in the standard library? I didn't see one in
std.string, just wondering before reinventing the wheel.
Something like:
```d
assert(dequote(`"foo"`) == "foo");
asse
13.05.2021 16:30, Alain De Vos пишет:
Shouldn't the compiler error it is not pure ?
Or have I a wrong understanding of pure or the compiler.
The function is pure. If you call it several times passing the same
argument it will return the same result.
https://run.dlang.io/is/futqjP
On Thursday, 13 May 2021 at 14:10:08 UTC, cc wrote:
Does something to dequote (unquote? or what would you call it?)
a string exist in the standard library? I didn't see one in
std.string, just wondering before reinventing the wheel.
Something like:
```d
assert(dequote(`"foo"`) == "foo");
asse
Does something to dequote (unquote? or what would you call it?) a
string exist in the standard library? I didn't see one in
std.string, just wondering before reinventing the wheel.
Something like:
```d
assert(dequote(`"foo"`) == "foo");
assert(dequote(`'foo'`) == "foo");
assert(dequote(`"foo's
On Thursday, 13 May 2021 at 13:30:29 UTC, Alain De Vos wrote:
Or have I a wrong understanding of pure or the compiler.
pure means it doesn't depend on any mutable info outside its
arguments.
You are only working on the arguments there so it is ok.
Shouldn't the compiler error it is not pure ?
Or have I a wrong understanding of pure or the compiler.
On Thursday, 13 May 2021 at 12:56:49 UTC, Alain De Vos wrote:
Writing an inc function is a fascinating voyage.
A function on module level did not worked because it had no
this context.
This works:
```
void main(){
ref int inc2(ref int x) return pure nothrow @nogc @safe{
++x;
re
Writing an inc function is a fascinating voyage.
A function on module level did not worked because it had no this
context.
This works:
```
void main(){
ref int inc2(ref int x) return pure nothrow @nogc @safe{
++x;
return x;
}
int x=0;
inc2(inc2(x));
writeln(x);
```
The thi
On Thursday, 13 May 2021 at 11:21:58 UTC, Alain De Vos wrote:
I wanted to use the inc function (increment by one) but it is
not recognised.
So searched google "inc dlang" but that returned nothing
informative.
Normally I would issue a "grep" in some files to find if a
function exists.
Is "i
On Thursday, 13 May 2021 at 11:21:58 UTC, Alain De Vos wrote:
[...] how can I do an extensive search in the library to
functions when i know more or less their name , but don't know
their exact place as module or package.
An alternative to the official documentation is
[dpldocs](http://dpldoc
I wanted to use the inc function (increment by one) but it is not
recognised.
So searched google "inc dlang" but that returned nothing
informative.
Normally I would issue a "grep" in some files to find if a
function exists.
Is "inc" part as function of the library someonewhere and more
impo
On Thursday, 13 May 2021 at 11:21:58 UTC, Alain De Vos wrote:
important, a practical question, how can I do an extensive
search in the library to functions when i know more or less
their name , but don't know their exact place as module or
package.
In the search bar at the top of the page, e
On Thursday, 13 May 2021 at 11:21:58 UTC, Alain De Vos wrote:
I wanted to use the inc function (increment by one) but it is
not recognised.
So searched google "inc dlang" but that returned nothing
informative.
Normally I would issue a "grep" in some files to find if a
function exists.
Is "i
On Wednesday, 12 May 2021 at 20:55:07 UTC, Christian Köstlin
wrote:
if you want to do a separate package later on, you only have to
change a little in your project setup, code can stay the same.
kind regards,
Christian
That's nice. :)
On Thursday, 13 May 2021 at 03:03:37 UTC, Tim wrote:
```
unittest{
auto p = rotate2D([0.0, 10.0], PI_2);
assert(p == [-10.0, 0.0]);
}
```
I suggest
```
unittest
{
auto p = rotate2D([0.0, 10.0], PI_2);
assert(isClose(p[0], -10.0));
assert(isClose(p[1], 0.0, 0.0, 1e-6));
}
``
39 matches
Mail list logo