Programming thread

any language that makes you have to look up its syntax so you can nest a construct is more retarded than redditors meme perl as being
That particular syntax is the only one in Python that I have to look up at all; most of it is just pseudocode nailed down a little better so a machine can actually make use of it and I rather enjoy Python
lisp invented this in the 1200s when monks working by candlelight discovered how to write parentheses
Yes and it's still substantially easier in Python as opposed to this:
CPAN has all these great modules but so much of what's in them should be in Perl's base which is why I look forward to learning Raku (Perl but having learned from Perl 5's numerous mistakes)
sloppy as fuck but mildly informative
why declare variables as nonlocal though is python a statically typed language now
I don't see the relation between nonlocal and static typing
 
Yes and it's still substantially easier in Python as opposed to this:
https://stackoverflow.com/questions/12766411/how-can-one-print-values-of-nested-hashes-in-perl CPAN has all these great modules but so much of what's in them should be in Perl's base which is why I look forward to learning Raku (Perl but having learned from Perl 5's numerous mistakes)
most languages with hash tables somehow get a function that recursively crawls hash tables and prints them and it stops being a problem quickly
if it doesn't have such a function then you can write one, it's not a super big deal
most of them are lackluster when compared to the lisp family's write function, which can serialize almost any object you throw at it into text that results in an identical object when passed into read
javascript comes closest with its json functions
I don't see the relation between nonlocal and static typing
other languages with a similar ethos to python let me mutate from inside a closure without having to tell the interpreter that i'm going to mutate it
if you're going to do that then why not also make every other variable const by default? that would be consistent and make sense though
 
most languages with hash tables somehow get a function that recursively crawls hash tables and prints them and it stops being a problem quickly
if it doesn't have such a function then you can write one, it's not a super big deal
It isn't but then it still becomes something I have to import
most of them are lackluster when compared to the lisp family's write function, which can serialize almost any object you throw at it into text that results in an identical object when passed into read
This seems like a Common Lisp thing specifically. I'm curious, can it even do procedures and objects?
javascript comes closest with its json functions
Python's base also has a JSON module, aptly named json
other languages with a similar ethos to python let me mutate from inside a closure without having to tell the interpreter that i'm going to mutate it
if you're going to do that then why not also make every other variable const by default? that would be consistent and make sense though
Not sure I follow your reasoning
 
sloppy as fuck but mildly informative
why declare variables as nonlocal though is python a statically typed language now
Because Python's perverse scoping rules take assignment to any variable not explicitly declared as nonlocal to be declaration of an implicit local variable in the current (in this case, nested) function. This is how Python people talk:

Python:
>>> def make_counter():
...     count = 0
...     def counter():
...         nonlocal count
...         count += 1
...         return counter
...     
>>> counter = make_counter()
>>> counter()
1
>>> counter()
2
>>> counter()
3

In this example, count holds a reference to an integer value, which is immutable. To update the value of count, you use a nonlocal statement that tells Python you want to reuse the variable from the non-local scope.



When your variable points to a mutable object, you can modify the variable’s value in place:

Python:
>>> def make_appender():
...     items = []
...     def appender(new_item):
...         items.append(new_item)
...         return items
...     return appender
...

>>> appender = make_appender()

>>> appender("First item")
['First item']
>>> appender("Second item")
['First item', 'Second item']
>>> appender("Third item")
['First item', 'Second item', 'Third item']
Use of a nonlocal declaration has nothing to do with whether the object bound to the nonlocal variable is mutable or not, it depends on whether you're assigning a new object to the variable or not. The second example doesn't need a nonlocal declaration because it's mutating the list that's already bound, but if it were binding a different list to the variable it would need a nonlocal declaration to avoid creating a local variable that masks the nonlocal. This confusion between variables and values is pervasive in the Python userbase.

Speaking of this affecting all Python example code, I've examined the source code for threading.local and found that the post from guy with line noise for a user name is right: What you're supposed to do is bind an instance of threading.local to a global variable, and then all of the "variables" it implements are secretly hash tables that get indexed by the current thread every time you access them. None of the example code I've ever seen actually uses it this way and the official documentation is dogshit as usual. The main "feature" this seems to buy you is that the thread-local namespaces are tightly bound to a module and loosely bound to a thread (whereas having a dictionary in each thread object mapping modules to thread-local namespaces does the opposite). The only "advantage" of doing this is that each module can set defaults for its thread-local variables, which are then used for every freshly-spawned thread as opposed to having each module just set the thread-locals to their default values at import time and then having each child thread's thread-local namespaces start out as copies of the parent's, which would actually be useful. Otherwise, all you get is additional lookup overhead, a conceptual model that's different for the sake of being different, and a lot more "spooky action at a distance", and if I wanted I wanted spooky action at a distance, I would be using Ruby on Rails.
 
  • Horrifying
Reactions: Creative Username
This seems like a Common Lisp thing specifically. I'm curious, can it even do procedures and objects?
most languages in the lisp family can write out any data you can express as a literal in the syntax you would expect as a literal, and i assume common lisp is exactly the same
it may or may not have support for various weird pieces of data like lambdas and records but it can express anything you can make out of cons pairs, even circular structures i think
Python's base also has a JSON module, aptly named json
yeah most languages can read and write json but the interesting thing here is that javascript is partially made of json (but not fully made out of json like how most lisps are made out of s-expressions)
Not sure I follow your reasoning
my reasoning is why the goddamn fuck do i have to type nonlocal in the first place

the point here is that python may be useful but it's very ugly, perhaps even more ugly than perl has a reputation for being
Use of a nonlocal declaration has nothing to do with whether the object bound to the nonlocal variable is mutable or not, it depends on whether you're assigning a new object to the variable or not. The second example doesn't need a nonlocal declaration because it's mutating the list that's already bound, but if it were binding a different list to the variable it would need a nonlocal declaration to avoid creating a local variable that masks the nonlocal. This confusion between variables and values is pervasive in the Python userbase.
jesus fucking christ i'm getting the migraine again where's my copy of the Revised Report i need to read about a language that doesn't completely suck balls
 
  • Thunk-Provoking
Reactions: Belisarius Cawl
the lisp family's write function, which can serialize almost any object you throw at it into text that results in an identical object when passed into read
From the Prolog end of things, there are predicates that can do this (write_canonical), but you'd never bother, because you'd just declare the terms as persistent ( https://www.swi-prolog.org/pldoc/man?section=persistency ), tell the engine where you want them saved, and the engine handles the rest.
 
  • Informative
Reactions: Belisarius Cawl
  • Informative
Reactions: Belisarius Cawl
my reasoning is why the goddamn fuck do i have to type nonlocal in the first place

the point here is that python may be useful but it's very ugly, perhaps even more ugly than perl has a reputation for being
I'm pretty sure it's a wrinkle of how scoping works in Python and appears to be quite uncommon. I actually didn't even know about it until that article. (Knew about Python's lexical closures in the context of accessing variables in lexical scope but not changing them.) To make things a bit more concrete, I'm looking at a venv I made in the context of rendering a mapping webshit and matplotlib (~111K LOC) uses nonlocal 15 times, mostly for tests. Of the others that use it at all (which is a tiny minority of the whole venv), the number is typically much lower, as with only 2 instances for numpy (~179K LOC). I have a very hard time seeing Python as less readable and uglier than Perl just because of nonlocal.
a lot of common lisp implementations let you dump core images and resume them too
R also has this feature, possibly due to its Lisp heritage, but you're advised not to use it for the purposes of reproducibility
 
Back