fadmmatt | 15 years ago | on: 7 lines of code, 3 minutes: Implement a programming language from scratch
fadmmatt's comments
fadmmatt | 15 years ago | on: 7 lines of code, 3 minutes: Implement a programming language from scratch
This kind of stuff also showed up in my program analysis and advanced compiler classes, too.
One of the class projects was to implement first-class macros, and we used an interpreter that looked a lot like the one from this article:
http://matt.might.net/articles/metacircular-evaluation-and-f...
(/article author)
fadmmatt | 15 years ago | on: 7 lines of code, 3 minutes: Implement a programming language from scratch
fadmmatt | 15 years ago | on: 7 lines of code, 3 minutes: Implement a programming language from scratch
Lisp macros need knowledge of the structure of the s-expression.
Certainly one can Church encode s-expressions and provide defmacro.
Gensym is trickier. Hygiene might be really challenging.
I might actually try that out.
(/article author)
fadmmatt | 16 years ago | on: The Secret Lives of Professors (What Being a Professor is Really Like)
Being a pre-tenure professor is way more terrifying than being an entrepreneur was.
And, depending on the field, between 25% and 75% of your salary as a professor will come from being able to procure external funding.
If you can't convince the funding agencies to pay you, then tenure buys you an office, a teaching load and health care.
It's been terrifying for me because my hit rate is about the same as Matt's. I've had very little luck getting funding for my research.
And, at the last funding panel I served on, the funding rate was down to 5%. My own fund-seeking overhead is now at 60% of my time, and I'm still not getting any.
Either we have too many scientists, or not enough science funding. I don't think the current system is sustainable.
fadmmatt | 16 years ago | on: Self-inlining anonymous functions in C++
fadmmatt | 16 years ago | on: Goto considered awesome: Goto in Scala using delimited continuations
In short, you can use the macros to hide the context-switching (yielding).
You could, for instance, force every function to perform a context switch right after its called. Since languages like Scheme encode even loops with function call, you're guaranteed to eventually hit a switch point. (And, if you allow other looping constructs, you could use macros to hide a yield inside them as well.)
fadmmatt | 16 years ago | on: Goto considered awesome: Goto in Scala using delimited continuations
I realized when going over that material, however, that most students didn't know what a continuation was, or how to use them, so I created a "by-example" tutorial:
http://matt.might.net/articles/programming-with-continuation...
It covers exceptions, backtracking-search, the magic "amb" function, magic sat-solving, generators and cooperative threads.
fadmmatt | 16 years ago | on: Lambda-style anonymous functions for C++ in less than 500 lines of code
[](int x, int y) { return x + y; }
instead of this:
lambda<int> (x,y) --> x + y
Ironically, the template hack could be shorter in many cases.
fadmmatt | 16 years ago | on: Lambda-style anonymous functions for C++ in less than 500 lines of code
I'd love to use Haskell, but I'm helping out on an exascale DoE project, and C++ is all we're allowed to use. Ugh.
Of course, lambdas don't make C++ more powerful, but that's just reductio ad Turing tar-pit.
You can turn that argument around, too: there's no problem you can solve with C++ that you can't solve with lambdas alone:
http://matt.might.net/articles/church-encodings-demo-in-sche...
If programming languages were about computational power, we would have stopped with Fortran.
Programming languages are about the freedom of expressions.
fadmmatt | 16 years ago | on: RIP: Robin Milner
I don't know if there's a free copy online anywhere.
The Damas-Milner paper is the sequel; it presents an alternate algorithm for type inference.
Benjamin Pierce's "Orange Book" is one of the best references now.
fadmmatt | 16 years ago | on: RIP: Robin Milner
It ignited a wave of research into type theory that continues to this day, yet in many ways, Hindley-Milner is still the most significant contribution to the field.
I remember reading his original paper on polymorphic typing for my qualifiers and being struck by the elegance and approachability of his writing.
Well worth a read.
fadmmatt | 16 years ago | on: Red-Black Trees in a Functional Setting (Okasaki, 1993)
http://matt.might.net/articles/implementation-of-immutable-p...
fadmmatt | 16 years ago | on: Are 80% of Harvard Students First Borns?
fadmmatt | 16 years ago | on: Tell HN: U.S. gov't blacklisted all DNS entries pointing to Linode machines
By the way, he can't get to Hacker News.
fadmmatt | 16 years ago | on: Tell HN: U.S. gov't blacklisted all DNS entries pointing to Linode machines
fadmmatt | 16 years ago | on: What are the semantics of your favourite programming language?
It depends on how you're encoding things. You might want to supply the I in I/O as an extra parameter to the transfer function.
Or, you could kick off the execution with the state containing a (possibly infinite) sequence representing all of the I/O events it will encounter during execution.
For the most part, transfer functions operate on just states.
* Can you convert a denotational semantics to an operational semantics (and vice versa)? Is there any value in doing this?
Yes, Olivier Danvy has a strong research program in this area. He has a battery of techniques that allow you to (almost) mechanically calculate one kind of semantics from another.
In many cases, calculating an operational semantics from a denotational semantics is the easiest way to prove their equivalence.
fadmmatt | 16 years ago | on: What are the semantics of your favourite programming language?
http://matt.might.net/articles/writing-an-interpreter-substi...
Short version:
* A denotational semantics is a function M : Program -> (Value -> Value) that maps a program to a mathematical function.
* An operational semantics is a relation (=>) between consecutive machine states. That is, if state => state' holds, then the machine transitions from state to state'.
* The relation in a "big-step" operational semantics need not be decidable. Big-step relations are usually recursive.
* The relation in a "small-step" operational semantics must be decidable.
* When you implement a transition relation, =>, it's usually implemented as a function. That is, if you have a relation R \subseteq State x State, you can encode this as a "transfer function" f : State -> 2^State.
fadmmatt | 16 years ago | on: Markets are efficient if and only if P = NP
He argued that economic agents rarely finding a satisfying solution to their constraints, and instead choose a "satisficing" or "good-enough" solution.
Simon also noted that the satisficing solution found by humans is often close to the optimal solution.
He got (and deserved) a Nobel prize for these two observations.
I find work of the flavor "X reduces to P = NP, so Nyah!" to be deeply unsatisfying and misleading.
For problems of human importance, good-enough solutions to NP problems can often be found in a reasonable amount of time.
In fact, state-of-the-art SAT solvers are mind-bogglingly fast (on average). They can find solutions in seconds, where the theoretical worst case solution time is many-fold the expected lifetime of the universe.
Generating a hard instance of SAT is actually hard to do. One of the few reliable techniques we know of is to encode prime factorization into a circuit. This is good news for crypto, but bad news for anyone looking to show the real-world intractability of a process by reducing it to P=NP. Few processes in nature actually mimic prime factorization or graph isomorphism.
fadmmatt | 16 years ago | on: How L1-minimization can recover highly degraded images