4 ms·
That's actually not simple at all because it assumes an implementation, that is, a machine with RAM that changes. For instance, what does = mean between domain
by innguest 12y ago
That's actually not simple at all because it assumes an implementation, that is, a machine with RAM that changes.
For instance, what does = mean between domain and email.split ? Who is equal to who? That question is a question that students sometimes have. You have to explain that Time is implicit in the code, and that an equal sign works by making the thing on the left equal to what the thing on the right was just before this line. So now there's a concept of Time and that's how things start to get very complicated, because it is implicit in your code.
Then, what does ".append" mean? I mean, you call append, but now you don't assign the result to any variable? And what would it mean if you said domains = domains.append(domain), then we really need to have a talk about the hidden Time.
So it only seems simple because it's familiar to you; so in fact I believe it's not simple at all.
But this I believe it's simple, and my fishing boat engine above would've benefited from this:
https://www.fpcomplete.com/tutorial-preview/4217/4k7kq6jGUE https://www.fpcomplete.com/tutorial-preview/4217/4k7kq6jGUE
If you look at that code (you can also click play to run it) and then look at the explanation again, could you please tell me what doesn't seem simple?
Edit: let's not forget your Python example uses a map, disguised as a for loop. That for is a keyword, but backstage it's just map where email is the element, emails is the list, and everything you write inside that scope is the function that gets passed the element each time (except in your case the function (i.e. the loop body) can also see the whole list, which is prone to bugs).
- chris_mahan 12y agoThanks. I looked at the code you provided. it makes still very little sense to me. You're right though that my using python language features like lists and file open and loops is like function, but I understand those, so I can use them.
- chris_mahan 12y agoAlso, a machine with RAM that changes. Well, yes, and files that change too. I'm completely ok with that.
- chris_mahan 12y ago"Edit: let's not forget your Python example uses a map, disguised as a for loop" Mmmm, really? A map? Like Google maps? Like a paper map? unfamiliar terminology. Seriously, I learned how to use for loops in 1984. Been using them ever since. Maybe that's the problem. Too old to learn new tricks.
- innguest 12y agoIt's not unfamiliar, you got it right, the map I'm talking about is exactly like that maps you described, in that they both contain directions (all the possible origin-destination relationships between all the places) and you can draw arrows from one place to another (thereby defining a "route" that represents the act of starting to walk from point A and arriving at point B). If you cared to learn you would benefit a lot from it. Oh, but the moral of the story is that because the computer understands those maps, then I can simply tell it what I have (point A, origin) and what I want (point B, destination) without telling it how to do it. Then the computer goes and writes that code for me! The same code you're now still writing manually. Because you don't want to learn a new "trick". :)
- chris_mahan 12y agoThat still made no sense, sorry.
- dragonwriter 12y ago> Mmmm, really? A map? Like Google maps? Like a paper map? unfamiliar terminology. No, a map like the Python built-in function "map". Though, really, the for loop in your Python sample isn't a map done as a for loop, its a reduce done as a for loop. (Again, like the Python built-in "reduce".)
- sanderjd 12y agoYou can learn these tricks, but it's ok if you don't want to, as long as you don't mind that many of us like doing things this way, and recognize that you may well run into these concepts in other peoples' code at some point.
- chris_mahan 12y agoFor completeness, I should add that I don't know what "reduce" means in this context.
- dllthomas 12y agohttps://docs.python.org/2/library/functions.html#reduce https://docs.python.org/2/library/functions.html#reduce Reduce (also frequently called "fold") turns a list of items into a single item (of maybe the same type or maybe a different type). It does this based on a function that tells you how to update that single item as it looks at each list item in turn. For instance: def fn(a,b): return str(b) + a + str(b) reduce(fn, [1,2,3], "0") That says: Start with "0" (we call this the accumulator value) Read the first element of the list (1) Pass "0" and 1 to fn Turn 1 into "1" Stick it on the front and back of "0" Return "101". Use "101" as our new accumulator value. Read the next element of the list (2) Pass "101" and 2 to fn Turn 2 into "2" Stick it on the front and back of "101" Return "21012". Use "21012" as our new accumulator value. Read the next element of the list (3) Pass "21012" and 3 to fn Turn 3 into "3" Stick it on the front and back of "21012" Return "3210123". Use "3210123" as our new accumulator value. Notice that we've reached the end of the list, return our latest accumulator value.