1,874 karma · joined July 19, 2010
.models
| (.[]
| if .title == "farmers"
then
(.fields | .[] | if .name == "Fruits" then .key else empty end)
as $fruits
| (.fields | .[] | if .name == "Full name" then .key else empty end)
as $name
| .entities
| .[]
| if .[ $name ] == "Bob, the farmer" then .[ $fruits ] else empty end
else empty end)
as $fruits
| .[]
| if .["title"] == "fruits"
then
( .fields | .[] | if .name == "Name" then .key else empty end) as $fruit_name
| .entities | [ .[] | {(._id): .[$fruit_name]} ] | add as $lookup
| $fruits | .[] | $lookup[.]
else empty
end
(I'm not claiming this is the best way to write that query, but it's the first one I came up with.)The strength of the two is that Terra can be manipulated using Lua as a metalanguage: for example, you could write a Lua function which produces Terra code, which is then executed. In some sense, this is like C, which has a lower-level language (C) and a corresponding high-level language which can manipulate that lower-level language (the C preprocessor). In this case, though, Lua is much more powerful and flexible than CPP, and Terra is also a smaller, simpler language than C.
It gets more powerful, though, because the Lua parts don't just have to exist at compile-time. You could use Lua at run-time to produce Terra code, which in turn can get executed immediately, producing object code specialized to a given situation or machine: for example, you might write a language, use Lua to parse it, and then convert it to Terra to produce object code which is then invoked immediately: this effectively just-in-time compiles your code. Or, you could write an algorithm in Terra with specific constants that aren't known until run-time, and then use Lua to stitch those constants in before running the algorithm: for example, to take advantage of specific machine features or parameters.
These examples also assume that you have only "compile" and "run" stages; you could also write programs with more stages: for example "compile source", "specialize for machine", and "run" could be three distinct stages. Terra/Lua would afford you the flexibility to stage your computations in this way.
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n-1)
def factorial(n):
return 1 if n == 0 else n * factorial(n-1)
def factorial(n):
return eval('*'.join(map(str, range(1, n+1))))
def factorial(n):
return reduce(lambda x, y: x * y, range(1, n+1))
def factorial(n):
def facts():
n, r = 1, 1
while True:
r, n = n*r, n+1
yield r
return next(islice(facts(), n-1, None))
The difference is: historically, Haskell was an experimental language, a test-bed for trying out new and weird ideas, which meant that experimentation with style has been pretty normal thing. Haskell "culture" encouraged being clever, because that's how you found new, interesting ideas. On the other hand, Python doesn't have that legacy: most of the implementations above are non-idiomatic because they're too clever.So yes, you can write things lots of ways in Haskell. But, if you had production code in Haskell, you wouldn't try to be clever, in the same way that you wouldn't (or shouldn't) try to be clever in production code in Python. You'd write simple, straightforward code, just like
fact n = prod [1..n][^1]: Ivor the Proof Engine is here, although apparently not actively updated any more: https://github.com/edwinb/Ivor
The paper itself is titled, appropriately, More ties than we thought: https://peerj.com/articles/cs-2/
("a" / "aa") "a"
in a traditional BNF setting, this grammar could match the string aa or the string aaa. However, this PEG will only accept the string aa, and cannot match the string aaa.(This is because of how backtracking works in PEGs—or, more precisely, how it doesn't work. With the input string aaa, we'll first try to match ("a" / "aa") against the input in a left-biased way, which succeeds because "a" matches. Then we'll try to match the second expression—"a"—which also matches. Now we are done with the grammar but still have the last a in the input, so the grammar fails. There were untried alternatives, but they only appeared in earlier parts of the grammar which had already 'succeeded', so we never go back and try them.)
Additionally, both LR and PEG parsers take linear time to parse a given input, but PEG/packrat parsing has much larger constant factors. On small examples, this might not be a big deal (what's 0.2 seconds compared to 0.02 seconds when loading a file?) but when doing large amounts of parsing it can definitely be a minus on the PEG/Packrat side.
Wilkins was trying to derive a language in which each word functioned as an index into a universal ontology of concepts, so that the concept represented by a word could be deduced by breaking apart the structure of the word itself. This is an interesting (if quixotic) experiment, but it's really concerned with building an a priori language.
The study of linguistic universals is the study of properties of natural languages: for example, all languages have pronouns is a linguistic universal, because it is a property that is true of all natural human languages. This is clearly not something that Wilkins was working towards: he was building a new language for the purpose of perfecting and clarifying communication. His Real Character had little—if anything—to do with analysis of the properties of natural language, and therefore also has little to do with the study of linguistic universals.
For example, natural languages are infamously redundant—for example, gender agreement between nouns and adjectives and even (in some languages) verbs—but that's because they developed so that they could be understood even if you were shouting over the wind or otherwise didn't hear part of the sentence. Programming languages have no such restrictions, and as such, optimizing a programming language for the same kind of redundancy as a natural language would lead to needless tedium like
int x = int_addition(int 2, int 3);
but in the context of a programming language, this kind of redundancy ends up being needless bookkeeping without presenting any of the same advantages of redundancy in natural language.That doesn't mean that your conclusions are wrong—I think some parameter orderings are better than others! But I think that's true for reasons orthogonal to the findings in this paper.
Linguists have studied linguistic universals for a long time, which are properties that all human languages have. For example, one could try to imagine (in the style of Borges) a language which had no nouns, and in which all sentences are formed of relationships between verbs—but no natural language has this feature: all natural languages have nouns and verbs.
There are also implicational universals, which are of the form, if [some language] has property X, then it will also have property Y, and tendencies, which are broad driving trends that might have individual exceptions. An example of the latter is that languages that place the verb at the end of the sentence usually have postpositions rather than prepositions, but this has exceptions (e.g., Latin.)
What's being studied here is a tendency in sentence structure: languages usually structure their syntax such that they can minimize the dependency length, or the distance between syntactically releated words in a sentence. This has long been hypothesized, but this paper gives evidence for it in the form of a large cross-language survey. Which is cool! But by no means does it have major implications for CS in any way. (At least, no more than any of the copious previous research on linguistic universals.)
EDIT: I should also add that this area of research is not new. In fact, linguist Joseph Greenberg published an article called 'Some universals of grammar with particular reference to the order of meaningful elements' in 1963. This is continuing research and, while good research, not particularly groundbreaking or pioneering.
Even if you have alternatives, there are still situations in which you might want to use a Pratt parser. It's much easier to understand the internals of this kind of parser than understand the shift/reduce rules of an LL(k) grammar, and Pratt parsers have the nice property that you can easily modify them at runtime, making it easy to switch to alternate grammars in particular contexts—e.g., directly parsing SQL within particular delimiters is a pretty trivial task that is somewhat more difficult with a BNF-style grammar.
EDIT: Actually, a better final example would be user-defined operators with arbitrary precedence and branching. There is no way of expressing this directly in a BNF-style grammar, but it is trivial with a Pratt parser.
foo = cast[ptr Foo](alloc(sizeof(Foo)))
# do stuff with foo
dealloc(foo)
EDIT: Here's the documentation on the site itself. Most things are 'traced' by the GC, but by using alloc and dealloc you can work with 'untraced' (i.e. manually allocated) memory: http://nim-lang.org/0.11.0/manual.html#types-reference-and-p...So the OCaml implementation shouldn't make it any more difficult to discover which implicit is in use in a given context, because if an implicit is used, then it must necessarily be unique and there will be no ambiguity.
-- This might not be the best/cleanest way of writing it, as my
-- Idris is a little rusty, but this will work:
mkMap : (size: Int) -> (if size > threshold then HashMap else TreeMap)
mkMap size with (size > threshold)
| True = newHashMap
| False = newTreeMap
So yes, although again, other tradeoffs are made to allow this kind of radical expressiveness.Think about what it means if a type variable has no typeclass constraint: the type t isn't just a specific unknown type, it's literally any type. Similarly, C t => t isn't a specific unknown instance of a typeclass, it's any instance of that typeclass. If we tell Haskell that we're returning an instance C t => t and then try to give some concrete type, Haskell won't allow it, because it wants that type to encompass any possible type that implements C, not just the one we happened to use.
One way of making the above code work in Haskell is to use an existential type, which expresses that we're talking about some (not any) map type, but we'd have to wrap it inside a different constructor:
-- this expresses that a SomeMap constructor contains some kind
-- if Map, but we can't tell which one:
data SomeMap = SomeMap (forall m. Map m => m)
-- We can now express this by hiding the choice of Map inside the
-- SomeMap type:
mkMap :: Int -> SomeMap
mkMap size | size > threshold = SomeMap newHashMap
| otheriwse = SomeMap newTreeMap
which is, again, a solution with some advantages and some disadvantages. class Map m where {- some implementation -}
instance Map HashMap where {- ... -}
instance Map TreeMap where {- ... -}
mkMap :: Int -> {- ??? -}
mkMap size | size > threshold = newHashMap
| otherwise = newTreeMap
What is the type of mkMap? It won't actually type-check in Haskell. It can't be (Map m) => m, because it needs to have a concrete type. We could do some kind of type-level work, relect the size variable into the type level, and have a type family that decides whether the resulting type is a HashMap or a TreeMap—but that has the same problem as the OCaml example, where we're using a different language (the language of type-level computation) to talk about something that'd be simple with value-level programming.One place where you could write this easily is in a dynamically typed language:
def mkMap(size):
if size > threshold:
return HashMap()
else:
return TreeMap()
That is exactly why this kind of research is interesting: we'd like to capture the flexibility of idioms that dynamic languages can sometimes afford us, with the extra safety and security guarantees of a static type system!Both trees and hash tables can be used to implement map-like data structures. You could, in ML, have an abstract signature for Map types that gets implemented sometimes by a concrete TreeMap implementation and sometimes by a concrete HashMap implementation. HashMap would be a better choice if the expected number of entries is larger, and the TreeMap would be better if the expected number of entries is smaller, so what we'd like to do is write something like
module Map = if size > threshold then HashMap else TreeMap
so that we choose what concrete implementation we want at runtime—but we can't really do that, because the language we use to talk about modules in ML is distinct from the language we use to talk about values. That is to say, the size > threshold part can't coexist in the same expression with the HashMap and TreeMap part. Some MLs have added the ability to wrap modules in values, so you can write it this in OCaml: module Map = (val (if size > threshold
then (module HashMap : MAP)
else (module TreeMap : MAP))) : MAP
but it's a bit awkward because of the explicit moving-back-and-forth between value-level and module-level, and the interaction between the two languages has some rough edges (which the paper explains more thoroughly, if you're interested.)The motivation for 1ML is that we'd like to use the same language to talk about both modules and values. That way, we could write the first, simpler definition without having to worry about the fact that we're manipulating distinct 'things'. Of course, there are other tradeoffs involved in the 1ML solution, but it's an interesting, compelling experiment.
Furthermore, writing extensions for emacs is much more pleasant than writing extensions for Eclipse, and is done much more widely. And, emacs has been around long enough that you have literally decades worth of extensions already available to you. Additionally, emacs is used widely enough that people are quick to add emacs support for new things: if I pick up a new esoteric language tomorrow, I can be 99% sure that there's no Eclipse support for it, but I can be 100% sure that there's already an emacs mode for it and it's probably on the emacs package manager already, to boot.
All this is both a plus and a minus, in some ways: learning emacs is probably not worth it unless you're willing to put the time and effort into building up your emacs configuration into something IDE-like, but if that's what you want to do, then emacs can do truly amazing things. So yes, what you said rings more or less true for vanilla emacs, but you're radically underselling emacs as a platform for building better things.
My personal experience with Less Wrong-style rationalism, to simplify the situation aggressively, is that it has a core of good, useful tools (Bayesian reasoning, strict positivism, utilitarianism) that I have no problem with. However, when pushed too far, those tools tend to break down—but the rationalist answer to that breakdown is all too often to embrace the model and discount the reality. This general refusal to regard their core tools with suspicion results in beliefs which are paradoxically irrational: when faced with e.g., utilitarianism condoning torture to prevent mild discomfort, the rationalist response is not, "Perhaps human experience does not map straightforwardly to integers—we should re-examine our tools," but rather, "As our mathematical tools are of course correct, we must believe in this conclusion." This belief in math-over-matter is a major part (though not the only factor) in my skepticism towards the kind of rationalism promoted by Less Wrong.
Perhaps also germane is that I am not personally a believer in Less Wrong-style rationality, and so the intellectual content of the work was not relevant to me except in the detached way that philosophical or political or religious schools can be interesting to non-adherents (which is one reason I read as much as I did.) Whether the story accomplishes its actual goal, then, is something I can't judge, but I can say that, as a non-rationalist (irrationalist?) I didn't find it to be a good or engaging story.
But as I said in my previous comment, this is my own reaction, and I include it for informative reasons, not because I think others should necessarily share it!
Among other things, I've often seen people try to sell HPMOR as, "Harry Potter fanfiction in which Harry applies the scientific method to the magical world of Harry Potter!" And that shows up a little [^1] but is by and large not the content of the work. Harry does very few experiments to verify his hypotheses and is actually a broadly incurious character. For example: Harry is nominally interested in eliminating death, but never once investigates the many magical mechanisms which seem to eliminate death, preferring to just talk about it instead. Similarly, he comes up with hypotheses as to how magic works, but never bothers to investigate them beyond speculation.
Additionally, a lot of the "solutions" to problems Harry has are relatively unsatisfying: Harry often circumvents a problem by "clever" applications of the rules, but because the rules of magic as given both in Rowling and in Yudkowsky are ill-defined and even self-contradictory, this seems less clever and more like arbitrary author fiat. Harry is also given a small time machine early on in the plot, and so more often than not, the solution to his problems is, "Use the time-turner again."
Finally, I personally found the writing style to be generally in need of editing—not terrible but certainly not polished—but I consider that to be a smaller problem than the above plot-related issues. EDIT: All this doesn't mean that you shouldn't like it! These are just problems that I had with the work.
[^1]: The bit where Harry tries to experimentally prove that P=NP is probably my favorite part of the entire thing.
[^1]: Various extensions to Scheme are proposed as numbered SRFIs; the extension in question is SRFI 49, as defined by http://srfi.schemers.org/srfi-49/srfi-49.html
enum fields = { x, y, z };
int point[] = {
[x] = 1,
[y] = 2,
[z] = 3
};
This is used pretty extensively in the QEMU codebase, which is where I first learned it.I assume they'll move it over to the Federated wiki at some point, but you can still view everything on the old wiki.
The elevator pitch for tech-minded people is that wikis are to SVN as federated wikis are to git. Instead of a shared wiki that people modify, each user has their own wiki which consists of both pages they've made or forked, so information propagates back and forth between users. It's a really compelling idea and I hope they can make it work.