jak writes:
[...]
>> --8<---cut here---start->8---
>> def powers_of_2_in(n):
>>if remainder(n, 2) != 0:
>> return 0, n
>>else:
>> s, r = powers_of_2_in(n // 2)
>> return 1 + s, r
>> --8<---cut here---end--
Alan Bawden writes:
> jak writes:
>
>Alan Bawden ha scritto:
> > Julieta Shem writes:
>>
>> How would you write this procedure?
>> def powers_of_2_in(n):
>> ...
>>
>> def powers_of_2_in(n
How would you write this procedure?
--8<---cut here---start->8---
def powers_of_2_in(n):
s = 0
while "I still find factors of 2 in n...":
q, r = divmod(n, 2)
if r == 0:
s = s + 1
n = n // 2
else:
return s, n
--8<---c
Julieta Shem writes:
[...]
> I agree. By the way, I once read or watched an interview with Guido van
> Rossum and and he was asked why not to tail-call optimize Python and the
> answer he gave --- IIRC --- was that tail-call optimization makes it
> harder for a beginner to unders
Greg Ewing writes:
> On 8/11/23 2:26 pm, Julieta Shem wrote:
>> For the first time I'm trying to write a tail-recursive
>> square-and-multiply and, even though it /seems/ to work, I'm not happy
>> with what I wrote and I don't seem to understand it so well.
For the first time I'm trying to write a tail-recursive
square-and-multiply and, even though it /seems/ to work, I'm not happy
with what I wrote and I don't seem to understand it so well.
--8<---cut here---start->8---
def sam(b, e, m, acc = 1):
if e == 0:
r...@zedat.fu-berlin.de (Stefan Ram) writes:
> Julieta Shem writes:
>>r...@zedat.fu-berlin.de (Stefan Ram) writes:
>>>Later, I looked at a book in a bookstore; it was a book
>>>about programming by Barbara Liskov that came out after the
>>>LSP was already me
Greg Ewing writes:
> On 4/11/22 1:29 am, Julieta Shem wrote:
>> Perhaps I can reduce the
>> class Pair to just being a pair as we know it, made of two things, then
>> we create a class called Sequence, which is really a composition of
>> Pairs, comes with a length meth
r...@zedat.fu-berlin.de (Stefan Ram) writes:
> Julieta Shem writes:
>>I'll definitely look up the Liskov
>>substitution principle and try to understand it.
>
> I found the LSP to be very confusing:
>
> First, it's wa
r...@zedat.fu-berlin.de (Stefan Ram) writes:
> Julieta Shem writes:
[...]
> 2. a. 1. Remark
>
> One can observe this ease especially when one defines a new
> class with a standard verb and then standard procedures
> "magically" use this new method,
Chris Angelico writes:
> On Thu, 3 Nov 2022 at 21:44, Alan Gauld wrote:
>> Also Python is not a purely OOP language, in that you can write
>> functional and procedural code in Python if you wish. In
>> Smalltalk thats notionally impossible because everything
>> is an object. And all programming
Greg Ewing writes:
> On 3/11/22 1:37 pm, Julieta Shem wrote:
>> The code for computing the length of a Pair (which is really a linked
>> list) happens to be the same for computing the length of a Stack.
>
> I would question whether that should be a method of Pair at all,
r...@zedat.fu-berlin.de (Stefan Ram) writes:
> Julieta Shem writes:
>>That's very interesting. Would you share the complete thread of e-mail?
>>I would love to read it word for word.
>
> Yes, with pleasure! A quotation from my corresponding web page:
>
> (For
r...@zedat.fu-berlin.de (Stefan Ram) writes:
> Greg Ewing writes:
>>I don't see any overlap between these at the conceptual level.
>
> It might come from early LISP dialects. In early LISPs, the
> only basic means to combine data into a larger assembly of
> data was the dotted pair and NULL
Alan Gauld writes:
> On 01/11/2022 17:58, Julieta Shem wrote:
[...]
>>> IS-A relationship, so Stack inheriting Pair would mean that a Stack
>>> was a Pair. That is not really true.
>>
>> That's another interesting observation. I do not have much
>
Dennis Lee Bieber writes:
> On 2 Nov 2022 09:56:28 GMT, r...@zedat.fu-berlin.de (Stefan Ram) declaimed
> the following:
>
>
>> Now, in the next program, I have removed the subclassings,
>> there is no inheritance from the base class "Language"
>> anymore. Yet the polymorphism in "f" still work
r...@zedat.fu-berlin.de (Stefan Ram) writes:
> Julieta Shem writes:
>>Any book recomendations on getting this thing mathematics-clear?
>
> OOP cannot be mathematics-clear because it is an /attempt/ to
> abstract from several different programming languages.
>
> When
Greg Ewing writes:
> On 2/11/22 9:54 am, Julieta Shem wrote:
>> But we've left behind a more basic requirement --- the Stack
>> class wishes for all the methods already written in some class called
>> Pair,
>
> Is that *really* what you want, though?
>
> To
r...@zedat.fu-berlin.de (Stefan Ram) writes:
> r...@zedat.fu-berlin.de (Stefan Ram) writes:
>>The crucial feature OOP adds to this is polymorphism ("late binding").
>
> If polymorphism is so crucial, the idea of subclasses
> has something to it! [...]
I wonder what Rich Hickey would say here
r...@zedat.fu-berlin.de (Stefan Ram) writes:
> Julieta Shem writes:
>>clarify. If I wish for an empty stack, I wish I could just say
>>>>> Stack()
>>Stack()
>>and if I wish for a nonempty stack, I'd write
>>>>> Stack(1, Stack(2
Alan Gauld writes:
> On 30/10/2022 14:01, Julieta Shem wrote:
>
>> I wrote the classes
>>
>> class Empty:
>> ...
>> class Pair:
>> ...
>>
>> (*) How to build a stack?
>>
>> These Lisp-like sequences are clearly a st
Chris Angelico writes:
> On Mon, 31 Oct 2022 at 14:38, Julieta Shem wrote:
>>
>> Chris Angelico writes:
>>
>> > The most straight-forward way to represent this concept in an
>> > object-oriented way is subclassing.
>> >
>> > cla
Chris Angelico writes:
> On Mon, 31 Oct 2022 at 09:05, Julieta Shem wrote:
>>
>> Julieta Shem writes:
>>
>> [...]
>>
>> >> . If you should, however, be talking about the new "type hints":
>> >> These are static and
Julieta Shem writes:
[...]
>> . If you should, however, be talking about the new "type hints":
>> These are static and have "Union", for example, "Union[int, str]"
>> or "int | str".
>
> I ended up locating such featur
r...@zedat.fu-berlin.de (Stefan Ram) writes:
> Julieta Shem writes:
>>My desire seems to imply that I need a union-like data structure.
>
> You only need to worry about such things in languages with
> static typing. For example, to have a function that can
> sometime
I have a question about a particular case I'm working on. I'm studying
OOP. To ask the question, I'm going to have to introduce you my context
here, so you'll need to bear with me. If you'd like to see the question
right away, go to the section ``My difficulty in encapsulating a
union''.
(*) In
26 matches
Mail list logo