Re: std.conv.to

2022-06-17 Thread Salih Dincer via Digitalmars-d-learn
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 (!)

Re: std.conv.to

2022-06-17 Thread Ali Çehreli via Digitalmars-d-learn
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

Re: std.conv.to

2022-06-17 Thread harakim via Digitalmars-d-learn
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));

Re: std.conv.to

2022-06-17 Thread Salih Dincer via Digitalmars-d-learn
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?

Re: Need Help with Encapsulation in Python!

2022-06-17 Thread Soham Mukherjee via Digitalmars-d-learn
[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 =

Re: Need Help with Encapsulation in Python!

2022-06-17 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
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

Re: Need Help with Encapsulation in Python!

2022-06-17 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
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.

Need Help with Encapsulation in Python!

2022-06-17 Thread Soham Mukherjee via Digitalmars-d-learn
``` 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

Re: nested function overloading

2022-06-17 Thread bauss via Digitalmars-d-learn
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

Re: nested function overloading

2022-06-17 Thread Chris Katko via Digitalmars-d-learn
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

Re: std.conv.to

2022-06-17 Thread bauss via Digitalmars-d-learn
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() {

Re: std.conv.to

2022-06-17 Thread harakim via Digitalmars-d-learn
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),

std.conv.to

2022-06-17 Thread harakim via Digitalmars-d-learn
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() {

Re: UFCS limit

2022-06-17 Thread Antonio via Digitalmars-d-learn
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 :-)

Re: UFCS limit

2022-06-17 Thread Antonio via Digitalmars-d-learn
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

Re: nested function overloading

2022-06-17 Thread bauss via Digitalmars-d-learn
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

nested function overloading

2022-06-17 Thread Chris Katko via Digitalmars-d-learn
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.

Re: UFCS limit

2022-06-17 Thread bauss via Digitalmars-d-learn
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