On Friday, 17 June 2022 at 18:40:59 UTC, Ali Çehreli wrote:
On 6/17/22 10:04, Salih Dincer wrote:
> Isn't foo and bar the same thing? I don't understand what's
the
> difference!
> ```d
>auto foo = to!Foo("123"); //??
>auto bar = Foo("321");
> ```
Yes, they are the same thing.
But (!)
On 6/17/22 10:04, Salih Dincer wrote:
> Isn't foo and bar the same thing? I don't understand what's the
> difference!
>auto foo = to!Foo("123"); //??
>auto bar = Foo("321");
Yes, they are the same thing.
The OP was looking for a generic way of converting any type to any other
type
On Friday, 17 June 2022 at 12:53:53 UTC, bauss wrote:
Just add a constructor to your type that takes the value of
what you want to convert.
Working example:
```d
struct Foo
{
int value;
this(int v)
{
value = v;
}
this(string v)
{
this(to!int(v));
On Friday, 17 June 2022 at 12:53:53 UTC, bauss wrote:
Just add a constructor to your type that takes the value of
what you want to convert.
Isn't foo and bar the same thing? I don't understand what's the
difference! By the way, what's the question? Is this the answer
to the question?
[Here](https://www.scaler.com/topics/python/encapsulation-in-python/), they
mentioned a way of simulating encapsulation of class level like this:
```
def private(*values):
def decorator(cls):
class Proxy:
def __init__(self, *args, **kwargs):
self.inst =
On Friday, 17 June 2022 at 14:14:57 UTC, Ola Fosheim Grøstad
wrote:
On Friday, 17 June 2022 at 13:58:15 UTC, Soham Mukherjee wrote:
Is there any better way to achieve encapsulation in Python?
Please rectify my code if possible.
One convention is to use "self._fieldname" for protected and
On Friday, 17 June 2022 at 13:58:15 UTC, Soham Mukherjee wrote:
Is there any better way to achieve encapsulation in Python?
Please rectify my code if possible.
One convention is to use "self._fieldname" for protected and
"self.__fieldname" for private class attributes.
```
self.a = 1
self.b = 2
self.c = 3
pass
def __getattribute__(self, name):
if sys._getframe(1).f_code.co_argcount == 0:
if name in self.privates:
raise Exception("Access to private attribute \"%s\" is
not allowed" % name)
else:
return
On Friday, 17 June 2022 at 13:04:47 UTC, Chris Katko wrote:
On Friday, 17 June 2022 at 12:19:33 UTC, bauss wrote:
On Friday, 17 June 2022 at 12:09:33 UTC, Chris Katko wrote:
I don't need this functionality, but I wanted to be sure.
Does function overloading not work with nested functions? I
On Friday, 17 June 2022 at 12:19:33 UTC, bauss wrote:
On Friday, 17 June 2022 at 12:09:33 UTC, Chris Katko wrote:
I don't need this functionality, but I wanted to be sure.
Does function overloading not work with nested functions? I
got a compiler error (something like "function already
On Friday, 17 June 2022 at 12:48:56 UTC, harakim wrote:
On Friday, 17 June 2022 at 12:31:45 UTC, harakim wrote:
I can generically convert a string to a type using to!type. I
have a read function that does that. I have simplified the
example below:
```d
int readNumber()
{
On Friday, 17 June 2022 at 12:31:45 UTC, harakim wrote:
I can generically convert a string to a type using to!type. I
have a read function that does that. I have simplified the
example below:
```d
int readNumber()
{
return read!int(val => to!int(val),
I can generically convert a string to a type using to!type. I
have a read function that does that. I have simplified the
example below:
```d
int readNumber()
{
return read!int(val => to!int(val), "number");
}
string readTime()
{
On Friday, 17 June 2022 at 12:26:05 UTC, Antonio wrote:
UFCS vs Functional curring... nice battle :-)
**UFCS & CFTE** vs **Functional currying**... nice battle :-)
On Friday, 17 June 2022 at 01:04:28 UTC, Paul Backus wrote:
On Thursday, 16 June 2022 at 23:59:06 UTC, Antonio wrote:
Is it there any way to apply UFCS on the returned method in
the same expression?
Nope. The way UFCS works is that allows you to call free
functions using member-function
On Friday, 17 June 2022 at 12:09:33 UTC, Chris Katko wrote:
I don't need this functionality, but I wanted to be sure.
Does function overloading not work with nested functions? I got
a compiler error (something like "function already defined")
when I tried it.
According to the spec then
I don't need this functionality, but I wanted to be sure.
Does function overloading not work with nested functions? I got a
compiler error (something like "function already defined") when I
tried it.
On Friday, 17 June 2022 at 05:17:20 UTC, Tejas wrote:
On Friday, 17 June 2022 at 01:04:28 UTC, Paul Backus wrote:
Nope. The way UFCS works is that allows you to call free
functions using member-function syntax, and member-function
syntax is always `object.memberName`, so UFCS only works for
18 matches
Mail list logo