Earlier quoted context omitted.
It is different from how Ruby and Javascript handle default arguments. I'm surprised Python does that, since I would expect function arguments to be reset to their defaults each call. That's a major side effect.
It's pretty odd behavior, yeah. It's easy to work around (set the default to None and then set the actual default in the function body), but I don't know if I've _ever_ seen anyone want it to behave as it does now.
SICP in Python
131–136 of 136 posts
Re: SICP in Python
#132Earlier quoted context omitted.
It's pretty odd behavior, yeah. It's easy to work around (set the default to None and then set the actual default in the function body), but I don't know if I've _ever_ seen anyone want it to behave as it does now.
It does make sense to evaluate the default value for the parameter at the point of definition for serveral reasons. First of all, the default value does not have to be a literal value, and if you wanted it to be evaluated at call time the function would need to capture all of the default values in a closure. default = 10 def foo(x=default): return x default = 20 assert foo() == 10 I think tat makes a lot of sense. It…
The default isn't a literal value when it is [], by the way.
If [] were a literal, then this would not be safe or correct:
def fun():
local = []
local.append(3)
The fact is that whenever [] is evaluated, it produces a fresh list each time. It's a constructor for an empty list, exactly like set() for an empty set. It just has slicker syntactic sugar.Python just calls that a literal because it looks like one.
Looking is being, in Python. Except for all the pitfalls.
Re: SICP in Python
#133Earlier quoted context omitted.
It's pretty odd behavior, yeah. It's easy to work around (set the default to None and then set the actual default in the function body), but I don't know if I've _ever_ seen anyone want it to behave as it does now.
It does make sense to evaluate the default value for the parameter at the point of definition for serveral reasons. First of all, the default value does not have to be a literal value, and if you wanted it to be evaluated at call time the function would need to capture all of the default values in a closure. default = 10 def foo(x=default): return x default = 20 assert foo() == 10 I think tat makes a lot of sense. It…
wildly_changing_variable = random_initializer();
stable_snapshot = wildly_changing_variable
def foo(arg = stable_snapshot):
...
Don't touch stable_snapshot and everything is cool. This is the rare case. Of course def foo(arg = wildly_changing_variable)
means we want the current value.I don't understand your "closure" comments; either way, things are being lexically closed. It's a question of when evaluation takes place, not in what scope or under what scoping discipline.
In fact, Python's treatment requires the implementation to have a hidden storage that is closed over; the equivalent of my stable_snapshot variable has to be maintained by the implementation. The definition-time evaluation has to stash the value somewhere, so to that it can use that one and not the current.
Re: SICP in Python
#134Earlier quoted context omitted.
> The pdf starts out with a curious little 'texinfo foreword'. Being able to type `info sicp` in one's shell? Yes, mostly in Emacs, but you could also do it in your shell. :) https://www.neilvandyke.org/sicp-texi/ The Texinfo format happened a couple years ago, in the early days of the Web, and let people on modest computers who couldn't run a Web browser work through SICP on their screens (no need for expense of pri…
[Late reply -- forgot to hit the button. ;] Thank you for the pointer and, more so, your contributions. That screenshot of SICP in Emacs -- running side-by-side with the built-in Guile interpreter -- induces peculiar sensations. An echo of how things could've been and possibly still are in some obscure(d) corners of the Net. An interactive learning environment that at least points in the right direction. It certainly…
Regarding the Emacs screenshot, here's another, from an early attempt to make Emacs more off-she-shelf usable for Scheme programming: https://www.neilvandyke.org/quack/
An actually better experience in Emacs (and part of what got me psyched to learn Lisps) is for Emacs Lisp programming: with a properly configured/installed Emacs, you can be browsing the documentation with rapid navigation, bringing up hypertext docstrings from your code , with links to the source code (perhaps the source code of Emacs itself), evaluating code that affects your running environment from both REPL and editor, etc. It's different than the Smalltalk-80 environment (which I also used, and wrote a little Smalltalk browser for), but there is some overlap. Modern IDEs let you do some of that, and some other things, but sometimes not as well, and Emacs people had this for a few decades.
Re: SICP in Python
#1351. The purpose of course it self has changed, the current course 6.01 in MIT attempts to introduce grads to breadth of the software engineering rather than depths of software engineering. 6.001 course was for the later purpose.
2. He says entire debate is superficial as both the course have different purpose.
It's a lengthy interview.
Re: SICP in Python
#136I read interview of Hal Abelson, in that interview he explains the reason behind moving away from scheme to python to teach concepts of SICP. 1. The purpose of course it self has changed, the current course 6.01 in MIT attempts to introduce grads to breadth of the software engineering rather than depths of software engineering. 6.001 course was for the later purpose. 2. He says entire debate is superficial as both th…