Tuesday, March 31, 2009

Sunday, March 29, 2009

Lasers DS - A game I made (and will hopefully continue working on)

I competed in the PittGeeks 3rd Annual Game Coding Competition on Friday and Saturday and my entry was a game for the DS made with devkitARM. It's a game where you have to use mirrors to reflect a laser into a target. It's currently pretty simplistic but I've already got some more complex features implemented and plan on adding more. Here are some screens:

First level.


Showing the splitter/joiner mirror.




The (unfortunately C++) source is available from SVN at http://www.jfbillingsley.com/lasers/. You'll need devkitARM installed to compile it (works on all major OSes). You'll need an emulator or a DS to run it. How will you get it on a DS? I don't know... <_<>_>

Sunday, February 15, 2009

Japanese Part 2

(Fine Blogger, I will use the font that you want me to use. Stupid WYSIWYG editor.)

Another blog post on Japanese! This time I'm talking about politeness levels (and the pronouns associated with them) and time.

Politeness

Many languages (including many/most Indo-European languages) have some way of indicating how politely you are speaking to someone. English is actually kind of unique in the European languages in that it has none. Most European languages have the "T-V" distinction, so named for the French pronouns tu and vous, which both mean "you" but in informal and polite speech, respectively. Spanish does it (tu/usted) and so does German (du/Sie). English apparently had a similar distinction at one time, but it has been lost in virtually all modern dialects.

Japanese has a system of politeness that can be compared, at least to an extent, to these kinds of systems. It is, however, much more extensive, affecting conjugation of all types of predicates, and there are many verb forms which range on a more continuous spectrum of politeness, rather than a simple dichotomy between "polite" and "informal".

The first level of distinction between polite and informal speech is the distinction between distal and direct conjugations. In general, direct style is used between people who are intimately familiar and when a superior speaks to an inferior, while distal style is used pretty much everywhere else. When you look up a verb or adjective in a Japanese dictionary, it will be listed in the direct style.

For example, let's consider the verb neru, "to sleep". All verbs in direct style end in -u. Unline the corresponding English "to sleep", this is not an "infinitive" form, as Japanese has no such form. neru is, in fact, a complete sentence. It means "someone sleeps" or "someone will sleep." The subject, as mentioned in the last post, is completely dependent on context, so you could really replace "someone" with anything. (The distinction between "sleeps" and "will sleep" is covered in the second half of this blog post.)

Now, if I use neru, I am implying that whomever I am talking to is either very familiar to me (a close friend, a family member) or inferior to me (I'm their boss or their parent). However, if I want to talk to someone else (a colleague, acquaintance, superior, complete stranger), I would have to use the distal style. Placing verbs in the distal style amounts to attaching the pseudo-verb -masu to the end of something called the "stem". The stem of neru is ne-, and attaching -masu gives nemasu. (A note on pronunciation: while neru is actually said how it's written, the -masu ending is said so often that it is usually just said something like -mas. This, of course, depends on the dialect of the speaker, and sometimes saying the -u will have a different meaning.)

In terms of use, the direct and distal styles of verbs are identical when they are used as sentential or clausal predicates. However distal-style verbs are almost never used as modifiers. So neru kodomo means "the sleeping child", but nemasu kodomo sounds very strange indeed.

Adjectival and nominal predicates also have a direct-distal distinction. The dictionary form of an adjective is its direct form - like akai for "red". When you put it into distal style, you add the distal form of the copula, desu, to get akai desu. Just like verbs, distal-style adjectives are (practically) never used to modify things, only as sentential or clausal predicates. Similarly, nominal predicates use the copula: hon da in direct style, and hon desu in distal. da is kind of funny because it likes to change forms when the nominal predicate is used to modify things - becoming no or na or disappearing altogether. (Another pronunciation note: desu, like -masu, is so common that it's usually pronounced more like des, and again, pronouncing it with the -u is dialectical, and sometimes has a different meaning.)

Okay, so now you know a bit about direct versus distal style. When you use it seems to correspond pretty nicely to the T-V distinction in European languages, actually. But this is only the beginning in Japanese. (German has tons of pointless inflectional endings; Spanish has tons of verb tenses and moods; Japanese had to have something to make it hard for foreigners to learn!)

Japanese has some other verb forms: humble-polite and honorific-polite. Most/all verbs can be put into these forms, though there are some irregularities. The irregularities, of course, come up with the most common verbs, as in any language.

An important concept when talking about humble and honorific forms is the group dynamic. For example, the humble-polite form is used when you want to talk about people in your "in-group". Who is in that group depends on who you are talking to and what you are talking about. You are always in your own in-group, and the smallest possible in-group is just you and nobody else. If you're in a business meeting, talking to your boss about the status of a project, your in-group might be you and your department, while your "out-group" will be your boss and possibly other management heads. But if you're talking to your boss about your plans for the holidays, your in-group might be you and your family, while your out-group might be your boss and his/her family. If you're talking to a friend, they can come and go in your in-group depending on the subject. Japanese people are constantly aware of this changing group dynamic, and it's something that foreigners just have to learn.

As was already mentioned, the humble form is used to talk about people in your in-group. Conversely, the honorific form is used to talk about people in your out-group. These forms are more polite than straight distal style, and when you use them is a matter of social requirements which, again, foreigners must just learn from experience. These forms are often used by people who are in public relations of many kinds - secretaries answering phones, customer support, and the like. In fact companies will actually have new employees attend a sort of "etiquette course' to learn how to speak using these forms, as they are not commonly used by most Japanese. They are also used in many kinds of ritualized greetings, expressions, and introductions, which are extremely important in Japanese culture. As these forms aren't commonly used in most speech, I won't bore you with the nitty-gritty grammatical details, but it suffices to say that most verbs will conjugate regularly in these forms, with a few common ones (like "to have", "to do", "to be", "to know", "to go", "to come") being replaced by different verbs which have the appropriate polite connotations.

Politeness also manifests itself in other ways. As was hinted to in the last post, Japanese has a complex pronoun system. If a pronoun is necessary - and it often isn't - which pronoun is used is dependent upon the relative social ranks and intimacy levels of the two parties involved (the speaker and the referent). For eample, anata means "you (singular)", but it's only used to talk to people of equal or lesser rank than you, and is not used by intimate friends. Use of family names, sometimes with polite or endearing suffixes, is actually far more common than pronouns in normal Japanese speech, to the surprise of many foreigners. -san is a gender-neutral generic name suffix that translates as "Mr." or "Mrs./Ms.", but there are others. -sama is (much) more polite; -kun is often used to speak of male friends; -tyan (-chan) has a childish or diminutive feel and can be used to speak of children or "cutesy" young girls. I doubt this is by any means an exhaustive list.

Whereas English has only a few verbs usually used for giving and receiving ("to give" and "to receive" or "to get", for the most part), Japanese has many more. There are five basic verbs that mean "to give" and two that mean "to get". Which verb to use is again based on the relative ranks of the two parties (giver and receiver), as well as which group (in or out) the giver and receiver are in. This comes up much more often than you might think, because in Japanese, you can give not only objects, but also actions. In English, we say "someone washed the car for me", while it would be expressed as something like "someone gave me the washing of the car". To complicate matters, you can of course bring in other parties, by adding levels of indirection (having someone make someone else wash the car, for you), which gets really fun when multiple parties are in different groups at different ranks. This is something we learned in second year Japanese and I still don't get it right.

My last example of politeness in Japanese, which follows from the previous section, is the frankly absurd number of possible ways you can use to tell or ask someone to do something. They're all based on verbs of receiving, so you've got that complication to deal with. But ignoring that, you've still got an incredible number of options for making commands, ranging on a politeness scale from downright rude to more polite than would be necessary for addressing the Emperor (if you were actually able to make a command to the Emperor). Consider the following far-from-exhaustive list of command forms of the verb taberu, "to eat":
  • tabero - direct, rude, masculine, impatient, extremely intimate
  • tabe-nasai - what a parent would tell their children
  • tabete - nicer
  • tabete kure - nicer still
  • tabete kurenai - "won't you eat?" intimate, friendly
  • tabete kurenai ka - same as above, but with a question particle - a little stiffer, more masculine
  • tabete kudasai - standard form, often used in public address and instruction manuals - generic "please eat"
  • tabete kudasaimasen - "won't you eat?" more polite
  • tabete kudasaimasen ka - same as above, stiffer from the ka particle
  • tabete kudasaranai desyoo ka - omfg polite
  • otabe ni narimasite kudasaranai desyoo ka - OK, now I'm just making things up
There are all sorts of forms I'm forgetting now. Some are distinctly feminine-sounding, others distinctly masculine; some would never be used on superiors while others never on inferiors; some have a condescending tone, and others have a friendly, unimposing feel.

So as I'm sure this has convinced you, politeness is far more complex in the Japanese language than in the European languages. This is undoubtedly due to the complex social hierarchy that has developed in Japanese culture which never really did in Europe.

Time

Now for the second major topic of this post: time. When I say time, I mean things like tense and aspect.

The first thing I should talk about is the distinction between progressive actions and instantive actions. I have no idea if these are the proper terms. I doubt they are. When I say a "progressive" action, I mean an action which has a beginning, a middle, and an end in time; and where the beginning and end are not the same point. In English and Spanish, progressive actions are indicated using the progressive aspect - the "to be x-ing" or "estar x-ndo" forms. So if I walk somewhere, that has a beginning, middle, and end. I begin walking, then I am walking, then I finish walking. By contrast, an instantive action is one which happens in an instant, one which has no beginning and end, just a single point in time before which it hasn't yet happened, and after which it already has happened. In English, instantive actions are markedly less common than progressive actions. Something like a cup falling to the floor and shattering is one that I can think of.

In Japanese, most verbs are instantive. Many verbs indicate not necessarily an "action" as we would define it but instead a sort of "change of state". For example, the use of the verb kuru, "to come", is a bit bewildering. In English, if a friend is coming over to my house, that action has a start point (when they leave their house), an interval when it's happening (as they're walking down the street), and an endpoint (when they come in my door). But in Japanese, my friend never starts or stops. kuru is an instantive action. Only when they actually arrive at my door have they come.

This preponderance of instantive verbs - verbs which either have not yet happened or which did - corresponds very neatly to the tense system in Japanese. There are really only two tenses: "perfect" and "imperfect". The perfect tense is used to talk about things that happened. The imperfect tense is used to talk about things that do happen on a regular basis (similar to the English simple present), or about things which have not yet happened. That is, there is no distinction between present and future tense in most Japanese, although you can certainly use adverbs to locate an action in time ("tomorrow" or "in five minutes").

There are ways to express progressive actions in Japanese, but it's not quite as common as in English. How you express it depends on the verb and the situation. Some verbs, like our friend taberu, let you express the progressive aspect in a very similar way as in English: gerund + form of to be. That is, tabete iru means "I am eating." Actually, it's not quite that cut-and-dry. tabete iru can mean "I am eating", but it could just as well mean "I have finished eating and am now in the state of having eaten". In fact, for most verbs, the latter interpretation is more likely: kite iru does not mean "he is coming (over)", but rather "he has arrived and is now here". For verbs like kuru, there's another way of expressing progressive action: tokoro da. This translates literally as something like "in the place (temporally) of ing", and figuratively as something more like "ing at the moment". So kuru tokoro da means that someone is on their way over. (You can, of course, put the tokoro da in another tense, to get things like kuru tokoro datta - "someone was on their way over".)

Okay

I think that's all I can write ;)

Saturday, January 17, 2009

Determinism

I wonder if the universe is deterministic.

Science shows tell me that even though virtually everything we see and experience is deterministic, on the atomic and subatomic levels, the universe instead operates probabilistically. I don't know nearly enough about QM to know if this is in any way true or if it's a result of an immense body of complex theory being distilled into a form suitable for the slightly-above-average TV viewer.

If the universe is deterministic, it has some interesting consequences.


"Fate" actually becomes correct, in a certain interpretation. Not in the "invisible people who decide what will happen in our lives" sense, but in the sense that because all interactions of matter and energy have only one possible outcome, if you know the state of the universe and all the laws that govern it, you can figure out what the state will be at an arbitary point in the future. The state of the universe is simply a function of time. Everything that happens was always "meant" to happen, although without the connotations of intent.


But even if the state of the universe is only a function of time, it is at the same time impossible to predict the future. Even if you had perfect knowledge of all the rules governing the universe, there is not enough matter and energy in the universe to simulate it (regardless of whether the universe is infinite or not). This is because simulation of a system is an inherently inefficient process. You will always need at least as much matter and energy to simulate a system as there is matter and energy in the system that you are simulating. (The most efficient simulator is the system itself, at which point you are no longer simulating!) Thus unless we are able to step outside the universe and somehow gain access to a separate quantity of matter and energy meeting or exceeding the sum of that which is in the universe, we cannot simulate the universe as a whole, and therefore cannot predict the future.

Another consequence is that there is no such thing as randomness. True randomness requires that at some point there has to be an event whose outcome cannot be known in advance, but since we are positing that all events have only one possible outcome, we cannot have a truly random event. Our concept of "randomness" really only refers to the fact that some sequence of events has no discernible pattern. The key word there is "discernible." The closest we can get to randomness in a deterministic universe is a process whose results depend on such a phenomenally large number of variables that we could not possibly comprehend the entire process involved in generating those results. We can't tell the difference between a truly random process and a process so complex that we can't find any patterns in it.

Blah, blah, blah.

Wednesday, January 14, 2009

Japanese Grammar

I liek Japanese grammar, so I'ma teach you some. (I am not a linguist or expert in the area in any way, and most of my experience in the language has been with a set of about ten native speakers in a fairly controlled, formal setting. Please let me know if I've made any mistakes, or if you have any other interesting things to add.)

There are three major word classes and some other minor classes. The minor ones are, more or less:

  • Particles: little grammatical words that serve to define the structure of clauses and sentences. Roughly, but definitely not always, correspond to prepositions and conjunctions in English.
  • Prenominals: a small class of words that have the odd distinction of being able to modify nouns while behaving a lot like nouns themselves. I think they derive from some older grammatical patterns which are no longer productive.
  • Copula: really derives from a contraction, it's the copula. The "linking verb," which often corresponds to some of the uses of the English "to be," but again, it's by no means a 1:1 correspondence.
And the three major ones:
  • Nouns: kind of a catch-all class for words that don't inflect and which don't fall into one of the minor categories. As such, it includes not only words that correspond to English nouns, but also adverbs, adjectives, pronouns etc.
  • Verbs: duh. They inflect and represent an action or change of state.
  • Adjectives: again, duh. They also inflect with forms similar to verbs, but there're differences, and there's not always an adjective inflection for a given verb inflection.
Predicates: Japanese has three kinds of predicates, one for each kind of major word class.

Verb predicates are pretty obvious. Japanese is a pro-drop language which means it really likes to leave out things that could be inferred from context. So, the subject of sentences is often left out and inferred. Thus, you can have one-word sentences - a single verb - that mean something.

Noun predicates consist of Noun + Copula. The copula inflects for pretty much all the same forms as verb predicates, although more irregularly (since it's derived from a contraction of "de" + "aru" - the "aru" verb part was inflected). Something like "hon da" is like saying "it's a book" in English - notice the correspondence between the copula and the use of the English "to be".

Adjective predicates are a little more interesting, since in English, adjectives can't function as predicates, only verbs. In Japanese, there's no need for a verb to make an adjective a predicate - the adjective alone is enough. So "akai" is a full sentence and means "it's red", or something like that. (Note that in distal (more polite) style, "akai desu" occurs. "desu" is the copula, but it's not really functioning the same way as "is" does in English. Its purpose is only to mark the adjective as being in the distal style, and it disappears everywhere else.)

Modifiers: here's one of the things I think is really cool. First off, you can modify nouns using adjectives just like in English - "red book" becomes "akai hon".

The interesting part is subordinate clauses. Japanese doesn't have a concept of a subordinating conjunction like in English. For example, we might say "that's the book that I bought last year." "that" is a subordinating conjunction and indicates that the following clause ("I bought last year") modifies the previous noun phrase ("the book").

So how does Japanese make a subordinate clause? Simple - the same way you use an adjective. Verbs can modify nouns. In fact, any time you modify a noun with an adjective or verb, it's more or less a subordinate clause. So "akai hon" can have two possible translations: "the red book" or "the book that is red". The translation of the verb phrase given above is "kyonen katta hon", literally "last-year bought book" - "the book that I bought last year".

Wait - adjectives are predicates, and so are verbs. We can modify nouns with either of them. What about nouns modifying nouns? Sure, we can do that too. In that case, the modifying noun's copula changes to an odd form - "no" or "na". "na" is used with many "adjective nouns", that is, nouns that function mostly or exclusively as adjectives/adverbs, but the "no"/"na" distinction is far from regular and in fact some nouns sound right with either one to a native speaker. In any case, an example would be "the pretty book": "kiree na hon". "kiree" is a noun, and works like a noun (like the sentence "kiree da" for "it's pretty"). An example of a "no" noun would be "boku", an informal male pronoun for "I", so "my book" becomes "boku no hon".

Pro-drop: As I mentioned earlier, Japanese is a pro-drop language - many times things are left to context and interpretation. Well, there's nothing explicit in the Japanese grammar that makes it like this - you could be very explicit about everything - but virtually everyone speaks it this way.

As an example, consider that you are telling a story about your day. In English, you might describe it like "first I did X, then I did Y. Then I found out something and I decided to come home, but not before I did Z." Notice how often the pronoun "I" appears. Japanese finds this redundant. Instead, a more Japanesey wording of this story would be something like "first did X, then did Y. Then found out something and decided to come home, but not before doing Z." "I" never appears. We sometimes speak like this in English, but it sounds kind of.. journaly.

Japanese does have a system of pronouns somewhat more complex than in English, but the fact is you don't really use it all that much simply because most of the time, either names are used, or nothing is used. For all those weeaboos out there who love to put poorly-worded Japanese in their forum signatures - please, for the love of all that is holy, take out the "watasi wa" at the beginning of every sentence. You are abusing the language horribly when you do that.

Related to this dropping phenomenon are the particles wa and ga. These are untranslatable words (particles) that follow noun phrases.

Now when we first learned about these particles, we learned that "wa" is sort of a contrastive particle, sometimes translatable as "at least". For example, "boku wa ikanai" means something like "I, at least, will not go." That is to say, someone else is probably going, but in contrast, I will not. Note that I'm using a pronoun here - this is actually one of the few places I've heard pronouns used: when contrasting with someone else.

On the other hand, we learned "ga" to be a sort of.. "indicational" particle. It indicates that someone/thing did something, but without the contrastive connotation that "wa" has. "ga" is also used with a certain class of verbs known as "affective" verbs, which are verbs in which there is no real actor, but only objects which are affected.

The reason I bring up "wa" and "ga" in relation to pro-drop is because of a more subtle phenomenon that we really didn't learn explicitly, but more implicitly as the years went on. Being a very context-sensitive language, each sentence then has to be interpreted within the scope of a context. This context is built up as you say things. "ga" is also used to bring new items into this context. If you are talking about a person or thing for the first time in this conversation (or in a while), you would use "ga" to indicate that. On the other hand, when referring to objects within the current context, "wa" can be used, and it doesn't seem to always have that contrastive connotation when used in this way.

I'm probably just making shit up, but I've noticed an odd correlation between these uses of "wa" and "ga" and the use of the English "a/an" and "the". "A/an" is used sometimes to bring up a new object in the conversation, and "the" is used with that object in subsequent utterances.

Phew: okay, enough writing for now.

Random Thoughts on the Perfect Language

There's no such thing.

Also, Lisp is already perfect and beat us to it by decades.


(Yes, those two sentences derive a logical contradiction.)


I'm not a Lisp weenie. I haven't drunk the Kool-aid. But the Lispers are right in a lot of ways. When your language consists of a single uniform data structure which represents both code and data, you can do a lot of really interesting things.


My exposure to the
D programming language has really opened my eyes as to the power of compile-time code generation and manipulation. Granted, string mixins and templates are just a hollow imitation of the power of true AST macros like Lisp provides. But it's made an impact on me nonetheless.

I can't shake the feeling that, no matter what the Lisp weenies say, the syntax of Lisp really has had an impact on its adoption as a mainstream language - that is to say, it hasn't been. It's probably more a product of the stigmas that have been associated with Lisp-style and C-style syntax since the early days of high-level programming. Lisp was way ahead of its time in a lot of ways, making it unusable for most programming tasks outside academia. C was made to be a low-level systems language. Thirty-forty years later, Lisp is still mostly in the realm of academia, and C-style languages still dominate the low-level end of the pool. For some reason, people don't seem to be able to take certain syntaxes "seriously" if they're used in a different realm than the realm in which their parent language was developed. You don't see many system-level BASIC languages in widespread use.

If we're to sell the benefits of Lisp to those who stick to C, then, we'd have come up with a syntax that is both palatable and familiar to them, as well as offering a lot of the benefits of Lisp-style syntax. A C syntax, but with a single unifying form with which all language constructs can be represented.

There's also the principle of "if it's different, it should look different" underlying the C syntax, something I wouldn't want to get rid of. The "omg parens" of Lisp aren't so much a problem with a sane (read: not Lisp-style) indentation and bracketing scheme, but even then it's still very difficult to pick out different kinds of operations when they're all represented with the same visual form and words. Mathematicians have a ridiculous amount of syntax to be able to compress ideas into tiny, elegant-looking formats. When you see a big sigma, you know that some sequence of numbers is being summed. It's much quicker to recognize than, say, (summation i 0 n (f i)).

No, I'm not really going anywhere with this. I'm just getting stuff down on.. paper. Screen? ..Internets?

Tuesday, January 13, 2009

Blogoblag

Derp, it's a blog. I have no idea what to put here.