3 ms·
> It's a little funny comparing a language with another language+plus-its-entire-ecosystem This is pretty much my point: any ‘reimplement this weird built-in t
by Veedrac 7y ago
> It's a little funny comparing a language with another language+plus-its-entire-ecosystem
This is pretty much my point: any ‘reimplement this weird built-in thing in $OTHER_LANG’ is going to involve overheads unless $OTHER_LANG also has that thing. I don't think keeping most types out of prelude should be a downside; you can always ‘from myprelude import * ’ if you disagree.
> How would you do this in Python?
I don't really know what "persists the unique index of f" means, but this seems similar to shelve. I can misuse that to give the same effect as what you showed.
with shelve.open('x') as db: db.setdefault("f", len(db))
>>> 0
with shelve.open('x') as db: db.setdefault("g", len(db))
>>> 1
with shelve.open('x') as db: db.setdefault("h", len(db))
>>> 2
with shelve.open('x') as db: db.setdefault("f", len(db))
>>> 0
- geocar 7y ago> I don't think keeping most types out of prelude should be a downside I don't understand what that means. > I don't really know what "persists the unique index of f" means, but this seems similar to shelve. I can misuse that to give the same effect as what you showed. I think you got it, but it seems like a lot of typing! How many characters do you have to change if you want it purely in memory? In k I just write: `x?`f
- Veedrac 7y ago‘Prelude’ is the set of standard functions and types that you don't have to import to use. Python comes with a rich standard library, but most require imports to use. > How many characters do you have to change if you want it purely in memory? When the question is if ‘K can reduce line count by a factor 1000’, shorter keywords hardly cut it. ‘setdefault’ is wordier than ‘?’, but as something you're only going to use on occasion, so what? And d.setdefault(_, len(d)) is something you'll use maybe once a year. shelve acts like a dict, so you can do the setdefault dance the same way on in-memory dicts.
- geocar 7y ago> ‘Prelude’ is the set of standard functions and types that you don't have to import to use. Python comes with a rich standard library, but most require imports to use. I might not understand this about python. $ python3 Python 3.7.6 (default, Dec 30 2019, 19:38:26) [Clang 11.0.0 (clang-1100.0.33.16)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> Counter Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'Counter' is not defined Should that have worked? Is there something wrong with my Python installation? > but as something you're only going to use on occasion, so what? And d.setdefault(_, len(d)) is something you'll use maybe once a year. If it takes that many keystrokes, you're definitely only going to use it once per year! This is the normal way you make enumerations in q/k. The low number of source-code bytes is the major feature in k. I've written some on why this is valuable, but at the end of the day, I don't really have anything more compelling than try it you might like it, and it works for me. This is something I'm working on though. - https://news.ycombinator.com/item?id=8476113 https://news.ycombinator.com/item?id=8476113 - https://news.ycombinator.com/item?id=10876975 https://news.ycombinator.com/item?id=10876975
- Veedrac 7y agoCounter is not in Python's prelude. Therefore you have to import it in order to use it. My comment about prelude was in response to you saying I was using Python's “language+plus-its-entire-ecosystem”. This is not true; Counter is part of the standard library that comes with the language. It is not from a third-party package. > If it takes that many keystrokes, you're definitely only going to use it once per year! This is the normal way you make enumerations in q/k. You don't use this frequently in other languages because you almost never care about the index of a value in a hash table (because it's ridiculous), and you almost never want to brute-force unique a list (because it's a footgun).
- geocar 7y ago> you saying I was using Python's “language+plus-its-entire-ecosystem”. This is not true; Counter is part of the standard library that comes with the language. It is not from a third-party package. I'm not sure I agree "third-party package" is a good/useful place to draw the line, but I don't think it's terribly important. Sorry. > you almost never care about the index of a value in a hash table (because it's ridiculous) So I want to query all of the referrer urls I've seen recently. I only see a few of them, so I want to have a table of all the URLs, and another table with one row per event (landing on my page). In SQL, you might have a foreign-key operation, but in q, I can also make the enumeration directly. I don't really care about the value of the index, just that I have one.