an adventure: a Lisp-style linked list

2025-09-03 Thread Ethan Carter
# -*- mode: python; python-indent-offset: 2 -*- ## As an exercise, I decided to implement a Lisp-style linked list ## using a class List. I'm a bit surprised by the result: it seems ## polymorphism forces me to write a recursive procedure in two ## halves: one half in the List class itself and th

Re: Drop into REPL when your program crashes.

2025-09-10 Thread Ethan Carter
Annada Behera writes: > Hi, > > Recently I have been increasingly adding this piece of code as > a preamble to a lot of my code. > > import (sys, os, ipdb) > > def debug_hook(exc_type, exc_value, traceback): > if exc_type is KeyboardInterrupt: > sys.__excepthook__(exc_

Re: an adventure: a Lisp-style linked list

2025-09-10 Thread Ethan Carter
pa@see.signature.invalid (Pierre Asselin) writes: > Ethan Carter wrote: > >> def __init__(self, d, ls): >> self.head = d >> self.tail = ls > > Why not > def __init__(self, d, ls=None): > > and avoid the need for a List.Empty ? Thank

Re: Python: The Documentary | An Origin Story

2025-09-12 Thread Ethan Carter
Lawrence D’Oliveiro writes: > Interviews with GvR and many others about their part in the origins and > rise to prominence of what currently seems to be the world’s most popular > programming language. In 4K! > > Thanks. FWIW, the Computer History

not understanding the result of functools.reduce

2025-08-22 Thread Ethan Carter
# -*- mode: python; python-indent-offset: 2 -*- from functools import reduce ## I'm puzzle with this result of reduce. Can you spot where my mind ## is going wrong? ## ## The problem I want to solve with /reduce/ (merely for the sake of ## exercise) is to collapse a list of lists to a list of b

Re: not understanding the result of functools.reduce

2025-08-22 Thread Ethan Carter
r...@zedat.fu-berlin.de (Stefan Ram) writes: > Ethan Carter wrote or quoted: >>## The question is how to write such an operator. I wrote this one: >>def op(x, b): >> return isinstance(x, int) or b > > The main snag with your op function and how you're using &g

can you improve this text-only beginner copy program?

2025-08-27 Thread Ethan Carter
The program below only copies text files on purpose---because we haven't learned about binary files in this course yet. (So I could catch a UnicodeDecodeError while writing.) If an exception is raised while writing, I need to delete the file that was created. Can you think of anything I'm missin

Re: can you improve this text-only beginner copy program?

2025-08-27 Thread Ethan Carter
r...@zedat.fu-berlin.de (Stefan Ram) writes: > Ethan Carter wrote or quoted: >>Can you think of anything I'm missing? > > The correctness of a program as a solution to an assignment > depends on the exact wording of the assignment, so it's a > bit dif