![]() ![]() Note that the lengths of the two lists are different: letters has 26 elements and ranges has 24, which means that the last two elements of letters (‘y’ and ‘z’) get dropped in the zipped list. This produces a Map from letters to lists of three numbers. Next, we zip the letters with the ranges and create a Map from the pairs using toMap. (The sliding function is a beautiful thing, especially for natural language processing problems.) scala> val ranges = (1 to 26).toList.sliding(3).toList Let’s start by creating the sliding list of number ranges. Also, what is “_” and what is “x”? (By which I mean, what are they in terms of the logic of the program? We know they are ways of referring to the elements being mapped over, but they don’t help the human reading the code understand what is going on.) ![]() ![]() That did it, but that one-liner isn’t clear at all, so we should break things up a bit. scala> letters.zip((1 to 26).toList.sliding(3).toList).toMap.mapValues(_.map(x => letters(x-1)).sorted.reverse) (Did I mention this was a pointless task in and of itself?) Here’s a one-liner that can do it. Okay, now here’s our (pointless) task: we want to create a map from every letter (from ‘a’ to ‘x’) to a list containing that letter and the two letters that follow it in reverse alphabetical order. Letters: List = List(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z) scala> val letters = "abcdefghijklmnopqrstuvwxyz".split("").toList.tail We begin by creating a list of all the letters in the alphabet. It’s not a very meaningful example, but it serves the purpose without being very complex. of what you can do to give your code more breathing space. This isn’t just for others - you are likely to be a reader of your own code, often months after you originally wrote it, and you want to be kind to your future self. In fact much to the contrary: it is crucial to use strategies that allow readers of your code to see the logic behind your statements. Also, some students indicated that they had gotten the impression that one should try to pack everything onto one line if possible, and that breaking things up was somehow less advanced or less Scala-like. So taking a step back, it is important to break operation sequences up a bit, but it isn’t always obvious to beginners how one can do so. It works well in the REPL and when you have lots of text to explain what is going on around the piece of code in question, but it seems to have given a bad model for writing actual code. I do admit to a fair amount of guilt in using such sequences of operations in class lectures and even in some of these tutorials. These map-over-mapValues-over-map sequences of statements can be almost incomprensible, both for some other person reading the code, and even for the person writing the code. It was instigated by patterns I was noting in my students’ code namely, that they were packing everything into one-liners with map after map with map after map, etc. This post isn’t so much a tutorial as a comment on coding style with a few pointers on how code blocks in Scala work. Other posts are on this blog, and you can get links to those and other resources on the links page of the Computational Linguistics course I’m creating these for. Additionally you can find this and other tutorial series on the JCG Java Tutorials page. This is part 12 of tutorials for first-time programmers getting into Scala.
0 Comments
![]() Steve wants the ground to open up and swallow him. The girls pick flowers while Steve and Eddie talks. i cant believe i wrote steven in the summary anyway its fixedĪfter having seen Steve's favourite movie of all time, the group goes out into the woods.eddie really really wants to kiss steve.nancy picks flowers for jonathan so he's mentioned.Language: English Words: 3,351 Chapters: 1/1 Comments: 8 Kudos: 349 Bookmarks: 19 Hits: 4034 Nancy then takes Robin with her and leaves him alone with Eddie. It seems his friends have invaded his house to make sure he's okay. Steve has a nightmare in the night and takes shelter in the tub. can you believe they haven't kissed yet.do i think robin would leave so easily no but eddie's got this.Language: English Words: 1,086 Chapters: 1/1 Comments: 6 Kudos: 294 Bookmarks: 10 Hits: 3036 What does it take to get these two together? Nancy is way in over her head. Robin has an interesting talk with her boys at Family Video and realises that they're both stupid and possibly deaf when Steve drops a comment about Corroded Coffin and Eddie doesn't pick up on it because he's an idiot. more focused on robin's panic than the steddie of it all.alternate title she knows and i know she knows.He shoots and he scores and the crowd goes wild Language: English Words: 1,895 Chapters: 1/1 Comments: 2 Kudos: 360 Bookmarks: 14 Hits: 4446 And Steve, well, Steve wouldn't ever turn Nancy down now, would he? So the four end up at a diner, at Nancy's suggestion, but she's flirting with Eddie and Robin is losing her mind. ![]() ![]() steve is chill because nothing phases himĮddie would never decline an invite from Steve.Robin Buckley & Eddie Munson & Nancy Wheeler.Language: English Words: 1,177 Chapters: 1/1 Comments: 10 Kudos: 432 Bookmarks: 21 Hits: 5190 He really doesn't like it when Jonathan questions why he's looking at Eddie. Nancy has invited the teen gang for an outing in the mall but Steve's on the fence and doesn't really like it. alternative title when i look at him and he doesn't look at me thank fck.is that what the kids are calling it these days.last three characters don't have a big role.Pluttskutt Fandoms: Stranger Things (TV 2016) |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |