Touch the firehose of ds106, the most recent flow of content from all of the blogs syndicated into ds106. As of right now, there have been 92764 posts brought in here going back to December 2010. If you want to be part of the flow, first learn more about ds106. Then, if you are truly ready and up to the task of creating web art, sign up and start doing it.

Day 2: Yoda and the Force

Posted by
|

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

90625940814410473677823303307239140923197851329113221824296863220044970068645509
93246375076371501935333599813394212683206115848648472453400357772572383667501093
385936060929761542844946126175849821644929827377137645617322689545974480885953961
29847989624898842849907125339464849759947426057219293652377306987719181500079310
85974973177034356114417937152940023506131558066041406348999101538095882739172335
013034579959598283024908613959119194984161024626341057680409397960065718837371918
97839107271594019385942983821400380276042807535466869836717367347514413265689046
545427183438924988463593921892482734208227337173170750625896987185425352922444073
56836697747041764191783792806707769376827161654372084824620199445809746616650038
96379717550230091860956540478399532843436703043494740202064896184241210020472261
57741272622767033931488274959123907075844661340243789141081220147175609767908861
456786263056602414699848566916282271990543887207108983318495411290453178079603056
362831273795831511797710353666931510120735210179794022584261185014692066503514530
841541531180651345966140594104702639113855196093984500267117870605756713114880683
87484928286425435097378839575458013290715529032497854520217213816515662049632218
706941135077944683681461371395289527234276957715244337183164434558104317558801019
3195304083090741722485038840000854007617317072781177716707165909601945282847841
1078791172965304788977644537761550920109447597309069120825598240321401440279044
5534483800285271289090576698767757392742944293079360807612167500509571357409146
214638948314684738135632512198476479666800891472260381274380179779764143906506153
372054194242754995991895919560062729404176466931935943896360997850284984897017817
477533642245166169650262697540359875815727582035457768219031733698915892252429468
37042650415533754338507618259957660669064032521737154166210965206202895199019206
0900003619680276450687259284082001

Is the 9001st number in the Fibonacci sequence.  Found it in like half a second.  Mind = blown.

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) 8) 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.

Add a comment

ds106 in[SPIRE]