Sets:
set := make(map[string]bool)
// add to set
set["a"] = true
| module IntMap = Map.Make(Int) | |
| type data = int IntMap.t | |
| let empty = IntMap.empty | |
| let set x pos data = IntMap.add pos x data | |
| let get pos data = match IntMap.find_opt pos data with | |
| | None -> 0 | |
| | Some x -> x | |
| let read ic = | |
| let next_instr () = try Some (Scanf.bscanf ic "%d%c" (fun i _ -> i)) |
I hereby claim:
To claim this, I am signing this object:
| #!/bin/bash -e | |
| # depot_tools | |
| git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git | |
| echo "export PATH=$PWD/depot_tools:$PATH" >> $HOME/.bashrc | |
| source ~/.bashrc | |
| # get chromium | |
| mkdir chromium | |
| cd chromium |
| #!/usr/bin/env python2.7 | |
| import itertools | |
| import sys | |
| def contains(filename, string): | |
| '''Determine whether a file contains a string.''' | |
| with open(filename) as f: | |
| for num, line in zip(itertools.count(1), f.readlines()): | |
| if string in line: |
| # what if we have a list, and we want to do something for each item. | |
| nums = [12, 5, 7, 18, 127, -1337] | |
| # we will print out each number squared | |
| # this means: repeatedly take one element from the list "nums" | |
| # call it "num" | |
| # and do the stuff in the for loop body. | |
| for num in nums: | |
| print num * num |
| # let's say we want to keep track of a person. | |
| # me. | |
| daniel = { | |
| 'fname': 'Daniel', | |
| 'lname': 'Connelly', | |
| 'age': 25, | |
| 'city': 'Atlanta' |
| # sometimes we want to keep track of lots of things, without naming | |
| # each one individually | |
| # we want to read some names from the user | |
| # what if we want to hold onto all of the names and do something with | |
| # them later? | |
| # for instance, we want to print them in reverse |
| # ----------------------------------------------------------------------------- | |
| # A brief tutorial on functions | |
| # by Daniel Connelly ([email protected]) | |
| # ----------------------------------------------------------------------------- | |
| # Sometimes we want to re-use a piece of programming logic. Copy-and-paste is | |
| # not necessarily a good approach, as it is prone to errors and duplicates | |
| # work. A good maxim is "Don't Repeat Yourself." Let's see how we can use | |
| # functions to eliminate repetition. |