(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
#This script reads all files in all directories of the folder taken from the openClassroom site and generates the dictionary, which we can then store in a file | |
folders = ["spam-train","spam-test","nonspam-train","nonspam-test"] | |
import os,sys | |
#We need a dictionary to store word occurences. What we can do is create a default dict and then update the frequencies. Write it all into a file all at once. | |
from collections import * | |
dictionary = defaultdict(int) | |
fdict = open(sys.argv[2],'w') #File to write all the entries in the dictionary | |
for root,dirnames,filenames in os.walk(sys.argv[1]): | |
for d in dirnames: #For each directory | |
for f in os.listdir(d): |
package controllers | |
import org.squeryl.PrimitiveTypeMode._ | |
import org.squeryl.{Session} | |
import play.api._ | |
import play.api.mvc._ | |
import models._ |
@Command(command="save", aliases="s,sv") | |
public void save() { | |
player.save(); | |
} | |
public void setup() { | |
list<Method> commands = getAllAnnotatedMethods(); | |
for(Method m : commands) { | |
commandmap.put(m.getAnnotation().command(), m); | |
} |
[email protected] | Stefanie | House | |
---|---|---|---|
[email protected] | Dinah | Erickson | |
[email protected] | Melisa | Reynolds | |
[email protected] | Lily | Carson | |
[email protected] | Millard | Rubio | |
[email protected] | Octavia | Santana | |
[email protected] | Royal | Bender | |
[email protected] | Laverne | Hutchins | |
[email protected] | Sherman | Wilder | |
[email protected] | Thelma | Burris |
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import subprocess | |
__all__ = ["transform"] | |
__version__ = '0.3' | |
__author__ = 'Christoph Burgmer <[email protected]>' | |
__url__ = 'http://github.com/cburgmer/upsidedown' |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
The thing that students have the hardest time on when learning functional programming is how to process a recursive structure while maintaining some sort of "state", the result if you will. I'll attempt here to demystify the process.
Functional programming languages almost always use a lot of recursively defined structures. Depending on the language those can be implemented in various ways, but in any case the end result is the same. A structure of this type is either an "atom", i.e. an irreducible thing, or a "compound" consisting of substructures of the same form.
For example a "list" is either an Empty/Nil list (the "atom") or it is formed as a Cons of a value and another list (compound form). That other "sublist" can itself be empty or another cons and so on and so forth. A tree is similar. It is either empty, or it consists of a triple of a value and two sub-trees, left and right.
Almost every problem we encounter is a question about doing something with all entries in a structure. To solve these prob