From kragen at pobox.com Thu Feb 7 03:37:02 2008 From: kragen at pobox.com (Kragen Javier Sitaker) Date: Thu Feb 7 03:37:02 2008 Subject: hexadecimal words for magic numbers Message-ID: <20080205120310.GA13497@canonical.org> I was looking through a list of words you can spell (more or less) in hexadecimal in 32 bits, with the idea that some of them might be useful for cute magic numbers in a runtime system I'm writing. These are the ones that might plausibly be relevant to some part of the inside of a software system, organized by topic: Containers: 1ad1e, ce11, 1a550 Indirection and naming: acce55, cf, deca1, 1abe1, 1abe11ed Commands: bade Size: c01055a1, f1ea, 5cad5 Scope: 10ca1 Brokenness: add1ed, ed5e1, ab5ce55, debac1e, deba5ed, defaced, feca1, faeca1, fece5, faece5, 10c0, 105e, Eb01a, bad, badc0de, Ada, a55, ba115, d0d0 Kludginess: c0bb1ed, decaf Uselessness: f1ab Non-brokenness: fab1ed, 5a1eab1e, ab1e, c001, b1e55ed Usability: affab1e Temporariness: 5caff01d Exceptions: b00, 5c01d Sentinels: cab005e Logic: fa15e, B001e, ca5e Hierarchy: b055, dad Collections: cab00d1e Arrays: ce11ed Trees: ba0bab, 1eaf Things that have been deleted: cea5ed, dead, decea5ed, effaced, de1, fe11ed, c105ed, faded, ebbed Things that are hard to describe: d00dad, 0ddba115 Weak references: feeb1e Run-time modules: 10adab1e Internationalization: 10ca1e, Babe1 Things lacking some usual feature: ba5e1e55, face1e55, deaf, 5eed1e55, 5e1f1e55, ba1d Recursion: ca5cade5 Graphical things: d00d1e, ea5e1, 5ca1ed Subroutines: c0de, ca11ab1e, d0ab1e Activation records: ca11ed Encoding: c0ded, dec0ded Ownership: deeded, 1ea5ed, ceded Security and denials of service: 5afe, f100ded, 5ea1ed, f0e Databases: DB OO terms: facade, c1a55, 5e1f, ba5e Large binary objects: b10b Higher-order programming: f01d Deception: f001ed Compacting garbage collectors: c0a1e5ce Ian Piumarta's design: c01a Dates or base-10 numbers: decade Things that are very determined or fault-tolerant: 0b5e55ed Information leakage: b1abbed, b1ed, b1eed Strings: babb1e, ba11ad Things that don't make sense: Dada, baff1ed Miscellaneous: aba5ed, a1fa1fa, ba5eba11, f005ba11, befa115, b1a2ed, 5eceded, ab0de, ab1de5, added, bedded, befe11, 1eaded, 5eaf00d From kragen at pobox.com Fri Feb 15 04:37:17 2008 From: kragen at pobox.com (Kragen Javier Sitaker) Date: Fri Feb 15 04:37:18 2008 Subject: freedom of communication will stop wars Message-ID: <20080215093717.GA9292@canonical.org> Until now, I've mostly thought of freedom of communication as being practically important because it is necessary for the investigation of truth. But now I think there is a second reason, which may be more important: the avoidance of conflict. First I will explain the view I've traditionally held, and then what changed it. Freedom of communication is necessary for the investigation of truth -------------------------------------------------------------------- Freedom of communication is necessary for the investigation of truth, by which I mean collectively finding out which ideas about the world are true and which are false. Some ideas, for example the idea that the sun is a hot object, are true; other ideas, such as the idea that the sun is made of stone, are false. Most ideas are partly true and partly false --- they are not a perfectly accurate description of the real world, but they bring us closer to understanding them. For example, the idea that the sun is made of stone is partly correct in that it considers the sun as a material object, rather than a god riding across the sky in a chariot. Generally people come to believe ideas as they learn about the world by being exposed to evidence for different ideas, including the evidence that other (presumably reasonable) people have believed certain things, and believing the things that seem to have the strongest support. Everyone believes some true ideas, some false ideas, and a large number of ideas that are partly true and partly false. (Some ideas that cannot be said to be either true or false to any degree, such as the idea that dragons exhale fire, or the idea that sushi is tasty. I am not talking about ideas of this class here. There are some people who believe that all ideas belong to this class. That is an example of a false idea, I believe quite strongly.) Some ideas that are rather controversial include the idea that democracy inevitably results in material ruin through increasingly generous government donatives (paid for by increasingly heavy taxes); the idea that giving more investigative power to the police inevitably makes everyone safer; and the idea that any individual person in Australia is much more likely to get shot in a street crime than to experience a military coup in their country during their lifetime. Our ability to distinguish candidate ideas that are true instead of candidates ideas that are false depends on our access to the relevant evidence. For example, if a person has no way of finding out how frequent military coups are in world history, or how frequent street-crime shootings in street crimes are in Australia, then their beliefs about the relative probabilities of the two events will inevitably derive from less reliable evidence, such as the beliefs of the people they respect, or what they see on TV. In a society with limited freedom of communication, powerful people can limit the availability of evidence that supports beliefs that they do not want other people to hold. For example, in a democracy, gun control policy is largely determined by whether people think it's more likely that the availability of guns will benefit them (for example, by preventing a military coup or foreign conquest) or harm them (for example, by making it easier for criminals to shoot them). Police work is dangerous; strict gun control policies make police work much safer. Police departments and police unions invariably favor strict gun control policies, in my experience. Perhaps this is is because strict gun control policies dramatically reduce their members' risk of dying by violence. It would be easy to imagine a person who believed that strict gun control policies were good and very important --- for example, because many of their friends were police officers, or because their husband had been shot in a street crime --- encouraging the public to worry about the danger of being shot in street crimes, regardless of the magnitude of the actual danger. If that person were in a position of power to interfere with free communications, they could use that power to make it more difficult to find out that the risk is extremely small in their country, or to learn about the existence of countries such as Switzerland and Israel with high gun ownership and extremely low homicide rates, or to learn about the historically relatively large risk of military coups; because people with access to that evidence are less likely to support strict gun-control policies. In case you're wondering what I'm talking about, according to the WHO's 2004 Burden Of Disease report, the homicide rate in Australia in 2002 was 1.5 per 100 000 population; in the US it was 5.4; in South Africa, 43.2; in Brazil, 32.6. Some of these deaths aren't from guns. If you were immune to aging and all other causes of death other than homicide, your life expectancy in a country like 2002 Australia would be 67000 years; in the 2002 US, it would be 18500 years; in 2002 South Africa, 2300 years; in 2002 Brazil, 3100 years. Even South Africa can expect military coups much more often than every 2300 years. The only countries I could find with higher homicide rates are those in the middle of some kind of war. Consequently, it is much more likely that an average resident of any of these countries will live through a military coup than that they will be murdered, unless the murder rates increase to rates not currently present anywhere in the world. See the Geneva Institute of International Studies's Small Arms Survey for details about gun ownership. The gun-control advocate might actually have an incentive to persuade people to believe ideas that they themselves do not hold, in order to support policies that the gun-control advocate thinks are good and important. My point in this essay is not to attack gun control; this part of the essay is concerned with people's ability to form correct ideas about the reality of the world. Whether strict gun-control laws are good is not a question about the reality of the world at all; people who agree about all the facts may still come to different conclusions on the matter due to differences in values. My point is that many people have incentives to make other people believe ideas that aren't true, for perfectly honorable reasons; and consequently, that giving one group of people the power to deny to the public access to evidence is likely to result in the public believing a lot of things that aren't true. I think that people believing things that aren't true is a bad thing, but I am not going to defend that point here. I am only pointing out that, if you believe that it is good and important for people to believe things that are true instead of things that are false, you should also believe that freedom of communication is good and important. The counterargument is that perhaps people in power (either in general, or in some particular situation) are better equipped to weigh the evidence than the people whose perceptions of the world they are controlling. There are counterarguments to this in many situations, but my purpose in this part of the essay has been to outline my previous beliefs about the importance of freedom of communication, and this part is already too long. Freedom of communication avoids conflict ---------------------------------------- I just watched the TED Talk announcing Pangea Day, in which the filmmaker Jehane Noujaim passionately advocated that we speak to one another in film so that we can empathize with one another. She pointed out that the emotional power of images allows us to see the world through one another's eyes, and that war arises because of a lack of this empathy. Perhaps this sounds like a fuzzy liberal idea, but last year I read Robert McNamara in Foreign Affairs advocating a very similar idea. War, he said, comes from a lack of empathy between the leaders on the opposite sides of the conflict; if they understood one another's mentality, they would be able to avoid it. He said he has spent a substantial amount of his time recently engaged in adversarial oral history exercises, where leaders from different sides of past conflicts meet and discuss what really happened. The film "The Fog of War" explains much of this as well. Given McNamara's well-known biases in favor of violence and objective facts, I assert that this is not merely a fuzzy liberal idea. Noujaim talked in particular about the absurd picture of the Iraq war presented on US news channels in the lead up to the war --- how the upcoming conflict was portrayed as bloodless, and how the Iraqi people were expected to welcome the Americans as liberators --- and how dramatically it differed from the picture seen by her family members living in the Middle East watching Al Jazeera. I also recently read an extremely right-wing 2006 article entitled, "The Counterrevolution in Military Affairs: Fashionable thinking about defense ignores the great threats of our time," by Ralph Peters, in the Weekly Standard. (2006-02-06, volume 11, issue 20.) Before he begins inveighing against Marxist European intellectuals and their supposed collusion with Islamist terrorists, Peters repeatedly laments the failure of the intelligentsia to understand the feelings of religious extremists and "our" failure to understand the heroism of suicide bombers, and argues that it will be our undoing. So if this kind of empathy --- the kind of cross-cultural understanding that would allow people to empathize with their counterparts in other countries --- can avoid war, then what is preventing it from happening today? Al-Jazeera is difficult to get in the US (most cable networks don't show it, and when they first launched their English web site, Akamai pulled out of their hosting contract at the last minute under political pressure) and CNN and Fox News are illegal in large parts of the Middle East. Some places, they aren't even available. This is the primary obstacle we face in cultivating cross-cultural empathy: the communications facilities capable of showing these images are under the control of small elites, and those elites are using that power to limit what can be seen. It may be that, even if Al-Jazeera were available on every cable network in the US, it still wouldn't be enough. Maybe not enough Americans would watch it, or maybe the English version would be so different from the Arabic version that they wouldn't really understand, or maybe mass media alone isn't enough. But we have other media available today. YouTube is a first step, although it readily responds to spurious claims of copyright infringement by peremptorily censoring whatever material is claimed to be infringing, a dismayingly common practice; and for reasons of network efficiency, the video quality is very poor. Online communities allow us to form relationships with people elsewhere who share interests with us, and to travel without breaking our ties with those we have left behind. BitTorrent allows us to reliably share our own films at full resolution with tens of thousands of people, with the cost of distribution being equitably spread among the people who participate, rather than falling largely on a single entity as with YouTube. These peer-to-peer, decentralized media allow us to share experiences with people in other parts of the world as never before. I don't know if this will bring an end to wars in the world, but it will certainly diminish them. There are those who would limit the reach, the effectiveness, and the reliability of these new media. Comcast, a large US ISP, has recently been caught forging packets in an effort to disrupt BitTorrent traffic, perhaps because the easy sharing of video footage competes with the cable TV service they also sell. The governments of Saudi Arabia, China, Iran, England, and Australia, among others, maintain lists of web sites that domestic ISPs are obligated to block access to, often because they provide windows into experiences those governments do not want their people to empathize with. These restrictions on the freedom to communicate impede cross-cultural empathy, and thus make war much more likely. So every man, woman, or child who dies in a future war will have died in large part because of restrictions like these on the freedom to communicate. From kragen at pobox.com Sun Feb 24 19:16:55 2008 From: kragen at pobox.com (Kragen Javier Sitaker) Date: Sun Feb 24 19:16:56 2008 Subject: IRC bots with object-oriented equational rewrite rules Message-ID: <20080225001654.GA27320@canonical.org> Thinking about my "object-oriented equational rewrite rules" and IRC bots. > http://lists.canonical.org/pipermail/kragen-tol/2007-March/000855.html Suppose we think of definitions like c = (f - 32) * 5 / 9 as defining properties that exist on every object that meets their qualifications (and isn't shadowed by some previously-existing c). Then we could think of something like this: todayweather = { f: 95, windspeed: 37 } as defining a property 'todayweather' that exists on every object. And then you could plausibly ask, on an object that has only the properties that all objects have (the Ur-Object), what are the properties that have a c property? c? { todayweather: 36.1, normalweather: 25 } Namespaces ---------- If you're doing this on an IRC bot on a casual channel, you could have a namespace per nick, and only enumerate properties in your own namespace. So there might be [kragen]c and [Isomer]c; but I could refer to properties from other namespaces explicitly if I wanted to; simply importing: f = [isomer]f or using without importing: c = ([isomer]f - 32) * 5 / 9 Actual Programs --------------- Let's hold off for now on any way to make these properties (as opposed to their value on a particular object) first-class in the language. But let's have self-quoting keywords, like in Prolog or Erlang (lower-case), or Common Lisp or Ruby (with colons). I'm pretty sure that if I use lower-case for auto-quoting, I'll end up with Very Important-Looking Programs, so I'm thinking I'll use backquote (`) instead. Let's start with a little syntactic sugar for lists. Let's say that if we have some semicolon-terminated expressions inside parentheses, with the last semicolon optional, it is syntactic sugar for a list made of conses: ( a; ) => { x: a, y: `nil } ( a; b; c ) => { x: a, y: { x: b, y: {x: c, y: `nil } } } () => `nil Even without first-class properties, we can still write: (`nplusone; n).apply = n + 1 such that we can write (`nplusone; 3).apply and get 4. Given that, we can write map: (fn; ()).map = () (fn; {x, y}).map = {x: (fn; x).apply, y: (fn; y).map} And filter: (fn; ()).filter = () (fn; {x, y}).filter = (fn; x; (fn; x).apply; y).filter2 (fn; x; `t; y).filter2 = { x: x, y: (fn; y).filter } (fn; x; `f; y).filter2 = (fn; y).filter It's pretty brutally obvious that we need some special syntax for cons here. Let's try infix @. (fn; ()).map = () (fn; x @ y).map = (fn; x).apply @ (fn; y).map (fn; ()).filter = () (fn; x @ y).filter = (fn; x; (fn; x).apply; (fn; y).filter).filter2 (fn; x; `t; y).filter2 = x @ y (fn; x; `f; y).filter2 = y ().length = 0 length = 1 + y.length x.reverse = ((); x).reverse2 (a; ()).reverse2 = a (a; x @ y).reverse2 = (x @ a; y).reverse2 That works OK, and I could imagine people typing it in IRC. It would probably be good to eliminate the argument-order dependencies as much as possible, and reduce the number of properties defined on all lists of length two or three. In the below, {foo, bar} is short for {foo: foo, bar: bar}, and any free variables are required properties of the object the property is defined on. {list: ()}.map = () map = (fn; list.x).apply @ {fn, list: list.y}.map {list: ()}.filter = () {list: x @ y}.filter = {fn, x, include: (fn; x).apply, y: {fn, list: y}.filter}.filter2 {include: `t}.filter2 = x @ y {include: `f}.filter2 = y ().length = 0 length = 1 + y.length x.reverse = { reversed: (), left: x }.reverse2 {left: ()}.reverse2 = reversed {left: x @ y}.reverse2 = { reversed: x @ reversed, left: y }.reverse2 Those aren't quite so brief, but they're still within the length where people could plausibly type them in a conversation. So how about strings? Let's suppose that strings support the interface of lists of one-character strings, work properly in pattern-matching, and that one-character strings additionally have a .ord property that tells you their ASCII code. Can we split words on spaces? " ".space? = `t {ord}.space? = `f ({space?: `t} @ y).words = y.words ({space?: `f, x} @ y).words = {wletters: (x;), left: y}.word {left: {space?: `t} @ rest}.word = wletters.reverse @ rest.words {left: x @ rest}.word = {wletters: x @ wletters, left: rest}.word {left: ()}.word = (wletters.reverse;) That's not too bad. It compares favorably to Scheme in total code volume: (define (words string) (words-of-list (string->list string))) (define (words-of-list clst) (map list->string (words-list clst))) (define (words-list clst) (let ((x (car clst)) (y (cdr clst))) (if (char-whitespace? x) (words-list y) (word (list x) y)))) (define (word wletters left) (cond ((null? left) (list (reverse wletters))) ((char-whitespace? (car left)) (cons (reverse wletters) (words-list (cdr left)))) (else (word (cons (car left) wletters) (cdr left))))) The Scheme is 10 lines, 59 words, 498 characters, in place of 7 lines, 47 words, 299 characters. So from there I think you could quite reasonably, e.g. implement ternary trees and compute a time-efficient inverted index of a big bag of strings. Say, old chat lines, or a small number of HTML documents. Precedence ---------- When you have more than one rule that's applicable to finding a property value, you have to decide what to do. Should you use the first rule, use the second rule, or combine them somehow? Aardappel used specificity ordering. I think you should do the same here, given that the "source code" is a bunch of people chatting. But it would probably be helpful if the specificity ordering were partial, so that the users would have to resolve potential conflicts manually. Syntax ------ The question of syntax is a little ugly but probably soluble. The normal namespace syntaxes are as follows: Syntax Precedents Why Not isomer/f Unix used for division isomer\f MS-DOS painful memories isomer.f C++, Java, Python used for property access isomer:f MacOS, XML used for property definition isomer::f C++, Perl too verbose isomer f Smalltalk not verbose enough [ISOMER]F VMS forgotten isomer'f Ada, Perl4 painful memories, unbalanced ' isomer$f R, DCL painful memories, ugly There are some other alternatives, especially if we involve Latin-1: isomer|f isomer?f isomer?f isomer?f isomer?f isomer->f isomer>f isomer?f isomer?f isomer?f isomer?f isomer?f isomer?f isomer?f isomer?f isomer?f isomer=>f isomer=-f isomer:-f isomer--f isomer-)f isomer-?f isomer?f isomer*f isomer~f isomer!f isomer[]f isomer()f f isomer isomer_f @isomer.f