Week 20140504
Dan Grossman
- Syntax, semantics, idioms, libraries, tools
- records:
#field_name record_name
- tuples are syntax sugers of records (field_name = 1, 2, 3...)
-
datatype
bindings:Constant of int | Add of expr * expr
- pattern matching:
case x of =>
- one-of (Option); each-of (Records)
- type synonym:
type name = t
.type card = suit * rank
- polymorphic datatype:
datatype 'a option = NONE | SOME of 'a
-
val p = e
.p
--> patterns fun f p = e
-
exception
,raise
e1 handle exn => e2
- tail optimization: remove caller from call stack
- the wrath of premature optimization
Foundation by Isaac Asimov
(Notes generated by my little Kindle script
- If you're born in a cubicle and grow up in a corridor, and work in a cell, and vacation in a crowded sun-room, then coming up into the open with nothing but sky over you might just give you a nervous breakdown.
- I don't care an electron
- And when Onum Barr stepped into his little garden early the next morning, he found a box at his feet. It contained provisions, concentrated provisions such as one would find aboard ship, and alien in taste and preparation. But they were good, and lasted long.
- The whole war is a battle between those two systems, between the Empire and the Foundation; between the big and the little.
Max sub-array problem
def max_sub_array(l): max_ending_here = max_so_far = l[0] begin = begin_temp = end = l[0] for i in range(1, len(l)): if l[i] > l[i] + max_ending_here: max_ending_here = l[i] begin_temp = i else: max_ending_here += l[i] if max_ending_here >= max_so_far: max_so_far = max_ending_here begin = begin_temp end = i return max_so_far, begin, end
Comments
Comments powered by Disqus