HOLY CRAP THEY HAVE ITERATION IN CLOJURE
Not only that, but it’s like…easier to design loops it seems. It does automatic iteration through a given list. With multiple lists, it does action on every possible combination.
For instance, if we have two lists, list1 and list2, we can print off all possible combinations of members by doing: (for [x list1, y list2] (println (x y))). This form of evaluation is good if one wants to do quick brute force to search a possible solution set. It’s easily programmed and understood. Members of list1 and list2 are mapped to x and y, respectively, and then they are printed out.
It’s also really easy to do manipulate and find items at specific indexes within the sequence, for example
ANOTHER BIG DEAL: CLOJURE IS A FUNCTIONAL LANGUAGE THAT CAN IMPLEMENT INTERFACES AND CLASSES!!1!
Long story short: protocol:interface::defrecord:class
-> means “go in this order from left to right.” Left to right operator, brakes the parenthetical rules!
For instance, if you wanted to multiply the mod of 9 and 5 by 2 and then divide the result by 8, you would normally put
(/ (* (mod 9 5) 2) to get the result of 1
but when you use ->…
(-> (mod 9 5) (* ,,, 2) (/ ,,, 8)) gives the same result, 1 (I put the commas in the other expressions because a. they’re read as whitespace b. it’s where the result of the last expression goes). The prefix notation of lisps can be very confusing and difficult to read, thus making it difficult to decipher the meaning of an expression without some careful thought. The -> operator makes things so much easier, and more readible! It can help to reduce the number of parenthesis you need if you use it properly.
MACROS? WHAT THE HECK ARE MACROS? After reading, we’ve had some trouble trying to figure out when/where they’d be useful, let alone how to implement one. So I ran to wikipedia, and thus far it’s been the only helpful source: ”in computer science is a rule or pattern that specifies how a certain input sequence should be mapped to an output sequence according to a defined procedure.
After reading the article, I’m starting to make some sense of it. For instance, a lot of us use macros (though not self-defined) on a day-to-day basis. Common macros for windows users: CTRL + C to copy, CTRL + X to cut, CTRL + V to paste, CTRL + Z to undo, CTRL + N to open a new window or instance of an application, and so many more for text editing and manipulation. All of these “shortcut key” combinations are macros. However, I can’t seem to wrap my head around the concept of a user defined macro. I know it will allow a user to define the order in which input it processed, but in what contexts can this be important? Perhaps the object-orientedness I’ve been brought up in during school has closed my mind a little bit.
This book has been a firehose of information, without a lot of resources to explain some of the concepts. When I can find examples around, they’re difficult to understand! People seem to be working towards solving problems I’ve never even thought could be problems in the first place. I’ve got a feeling Day 3 won’t get any better.