KlingonPerlProgrammingNAMELingua::thInganHol::yIghun - "The Klingon Language: hey you, program in it!" SYNOPSIS
DESCRIPTIONThe Lingua::tlhInganHol::yIghun module allows you to write Perl in the original Klingon. IntroductionThe Klingon language was first explained to Terrans in 1984 by Earth-born linguist Dr Marc Okrand. Those who dare can learn more about it at the Klingon Language Institute (http://www.kli.org/). The word order in Klingon sentences is I-O-V-S: indirect object, (direct) object, verb, subject. For example: luSpetna'vaD vay' vIghItlh jIH to-STDERR something write I Naturally, commands given in the imperative form are far more common in Klingon. In imperative statements, such as those used for programming instructions, word order becomes I-O-V: indirect object, (direct) object, (imperative) verb: luSpetna'vaD vay' yIghItlh! to-STDERR something (I order you to) write! Thus, for programming, Klingon is inherently a Reverse Polish notation. VariablesKlingon uses inflection to denote number. So the command: luSpetna'vaD vay' yIghItlh! is: to-STDERR something write! whereas: to STDERR some things write! is: luSpetna'vaD vay'mey yIghItlh! So in Klingon scalars and arrays can have the same root name (just as in regular Perl): vay' ---> $something vay'mey ---> @something The -mey suffix only refers to things incapable of speech. If the somethings had been articulate, the inflection would be: luSpetna'vaD vay'pu' yIghItlh! From a certain point-of-view, this parallels the difference between an array and a hash: arrays are subscripted mutely, with dumb integers; whereas hashes are subscripted eloquently, with quoted strings. Since hashes are thus in some sense "articulate", they are inflected with the -pu' suffix: vay' ---> $something vay'mey ---> @something vay'pu' ---> %something Standard variablesSome variables have special names. Specifically:
Subscripting arrays and hashesNumerical subscripts are just ordinals. The command: "kill $starships[5][3];" means: from starships, from the 5th of them, the 3rd of them, kill it! which, in the Warrior's Tongue, is: 'ejDo'meyvo' vagh DIchvo' wej Dich yIHoH! The [DIch] tag marks an ordinal number, whilst the ablative -vo' suffix marks something being subscripted (i.e. something that an element is taken from). Note that the -mey suffix on the original 'ejDo'mey (@starships) array didn't change. This implies that the literal back-translation is: "kill @starships[5][3];" Thus Klingon shows its superiority, in that it already honours the new Perl 6 sigil conventions. Hash indices have a different tag (Suq). So:
which means: from enemies, from the "ancient" ones, the 'human' one, kill him! is coded as: jaghpu'vo' <<ancient>> Suqvo' <human> Suq yIHoH! Once again the -pu'"I'm-a-hash" suffix is retained when subscripting, so the literal back-translation is the Perl6ish:
Element access through referencesWith references, the [DIch] or Suq tag still indicates what kind of thing is being subscripted. So there is no need for an explicit dereferencer. So: jepaHDIlIwI'vo' <<stupid>> Suqvo' wa' DIch yIHoH! can be translated:
but also means:
Distinguishing lvaluesAll the variables shown above were written in the (uninflected) accusative case. This is because they were used as direct objects (i.e. as data). When variables are assigned to, they become indirect objects of the assignment (give the weapon to me). This means that targets of assignment (or any other form of modification) must be specified in the dative case, using the -vaD suffix:
Variable declarationsVariable declarations also use suffixes for lexicals: scalarwIj! ---> my $scalar; arraymeywIj! ---> my @array; hashpu'wI'! ---> my %hash; for package variables: scalarmaj! ---> our $scalar; arraymeymaj! ---> our @array; hashpu'ma'! ---> our %hash; and for temporaries: scalarvam! ---> local $scalar; arraymeyvam! ---> local @array; hashpu'vam! ---> local %hash; Operators and other punctuationIn general, programming Perl in the original Klingon requires far less punctuation than in the Terran corruption. The only punctuation components of the language are: < and >These are pach poS (left claw) and pach niH (right claw). They delimit an uninterpolated character string. For example: <petaQ> yiHegh! ---> "die 'scum';" << and >>These are pachmey poS (left claws) and pachmey niH (right claws). They delimit an interpolated character string. For example: <<petaQ\n>> yiHegh! ---> "die "scum\n";" ( and )These are 'etlh [HivtaH] and 'etlh [HubtaH] (attaching sword and defending sword). They are used as grouping expressions. For example: xvaD wa' (cha maH yIfunc) yIlogh yInob! ---> "$x = 1*func(2,10)" For standard operators and functions with fixed parameter lists, this kind of grouping is not needed due to the RPN ordering of Klingon: xvaD wa' cha maH yIchel yIlogh yInob! ---> "$x = 1*(2+10)" { and }These are betleH [HivtaH] and betleH [HubtaH] (attacking batleth and defending batleth). They are used to group complete statements. For example:
#This is the tajmey gho (circle of daggers), which is used to indicate the beginning of a comment (which then runs to the end of the line). Its use is widely reviled as a sign of weakness. OperatorsThe Klingon binding of Perl does not use sniveling Terran symbols for important operations. It uses proper words. For example: = yInob "give!" + tIchel "add!" - tIchelHa' "un-add!" ++... yIghur "increase!" ...++ yIghurQav "increase afterwards!" .. tIchen "form up!" eq rap'a' "the same?!" == mI'rap'a' "the same number?!" For a complete list, see Appendix 2. Note that they all appear at the end of their argument lists:
Most of the above examples begin with yI- or tI-. These prefixes indicate an imperative verb referring to one or many objects (respectively). Hence, assignment is yInob (give it to...), whilst addition is tIchel (add them). Of course, in the heat of coding there is often not time for these syntactic niceties, so Lingua::tlhIngan::yIghun allows you do just drop them (i.e. use "clipped Klingon") if you wish. Numeric literalsKlingon uses a decimal numbering system. The digits are: 0 pagh 1 wa' 2 cha' 3 wej 4 loS 5 vagh 6 jav 7 Soch 8 chorgh 9 Hut Powers of 10 are: 10 maH 100 vatlh 1000 SaD or SanID 10000 netlh 100000 bIp 1000000 'uy' Numbers are formed by concatenating the appropriate digit and power of ten in a descending sequence. For example: yearvaD wa'[SaD] Hutvatlh chorghmaH loS yInob! ---> "$year = 1984;" Decimals are created by specifying the decimal mark ([DoD]) then enumerating post-decimal digits individually. For example: pivaD wej DoD wa' loS wa' vagh yInob! ---> "$pi = 3.1415;" ReferencesReferences are created by prepending the query nuqDaq (where is...) to a referent. For example: refvaD nuqDaq var yInob! ---> "$ref = \$var;" To dereference, the appropriate -vetlh, -meyvetlh, or -pu'vetlh suffix (that..., those..., those ...) is used, depending on the type of the referent. For example:
Conjunctives and disjunctivesJust as Terran Perl's conjunctive and disjunctive operators come in two precedences, so too do those of The Warrior's Perl. When joining expressions, the high precedence operators (joq and je) are used: x yImI'Suq joq yIghItlh! ---> "print($x || get_num();)" zvaD x yIy je yInob! ---> "$z = ($x && y());" Unlike all other operators in Klingon, low-precedence conjunctives and disjunctives (i.e. those between complete commands) are infix, not postfix. The low precedence operators are qoj and 'ej: x yIghItlh qoj yImI'Suq! ---> "print($x) or get_num();" zvaD x yInob 'ej yIy! ---> "($z = $x) or y();" Note that (as the above exampe illustrate) changing precedence often necessitates a radical change in word order. Object-oriented featuresKlingon Perl does not pander to feeble Terran object-oriented sensibilities by treating objects and methods specially. A method is a subroutine, so in Klingon Perl it is called exactly like a subroutine. The first argument of a method is special, so in Klingon Perl it is explicitly marked it as being special. For example, the procedural command: Hich DoSmey yIbaH! translates as: "fire($weapon,@targets);" To call the same subroutine as a method, with $weapons as its invocant object, it is necessary to mark the referent using the topicalizer 'e': Hich'e' DoSmey yIbaH! This then translates as: "$weapon->fire(@targets);" Likewise class methods are invoked by topicalizing the class name: <<Jagh>>'e' yItogh yIghItlh> which is: "print "Enemy"->count();" To create an object, the [DoQ] (claim ownership of) command is used:
ComparisonsThe equality comparison operators ("==", "!=", "eq", "ne") are implemented as questions in Klingon:
Inequalities are expressed with a different grammatical structure in Klingon. There is only one inequality operator, whose syntax is: expr1 comparator law' expr2 comparator puS Literally this means: comparator(expr1) is many; comparator(expr2) is few or, in other words: comparator(expr1) > comparator(expr2) The comparators tlhInganHol::yIghun supports are: ">" : tIn "<" : mach ">=" : machbe' "<" : tInbe' "gt" : tlha' "lt" : nung "ge" : nungbe' "le" : tlha'be' For example:
Flow controlThe flow control directives are: teHchugh "if" if is true teHchughbe' "unless" if is not true teHtaHvIS "while" while being true teHtaHvISbe' "until" while not being true tIqel "for(each)" consider them yIjaH "goto" go! yInargh "last" escape! yItaH "next" go on yInIDqa' "redo" try again Builtin functionsPerl builtins are represented as imperative verbs in tlhInganHol::yIghun. Appendix 1 has the complete list. As with operators, they may take yI- or tI- prefixes and are themselves postfix (the verb after it's arguments). Note that there are a suitably large number of variations on the "kill" command. User-defined subroutinesA user-defined subroutine is specified in a betleH delimited block, and given a name using the nab (procedure) specifier. For example:
means:
Such subroutines are then called using the (non-optional) yI- or tI- prefix: yIdoit! Anonymous subroutines are created by omitting the name:
which is:
Subroutine references can also be created by suffixing a subroutine name with -la HwI' (one who can...): refwIj doitlaHwI' nob! Either way, the subroutine is called through a reference by appending the -vetlh suffix (that...") and prepending the imperative yI- or tI-: yIrefvetlh! Pattern matchingPatterns (or nejwI') are specified using the same line-noise syntax as in Terran Perl. To match against a pattern, the ghov verb (recognize) is used: 'oH <\d+> yIghov 'ej <<vItu'>> yIghItlh! which means: $_ =~ m/\d+/ and print "found it"; Note that the value being matched against must be explicitly specified, even if it is 'oH. To substitute against a pattern, use tam (substitute): De'vaD <\d+> <\n> yItam! which means: $data =~ s/\d+/\n/; The container whose value is being substituted must be explicitly specified (again, even if it is 'oH). It is also the target of the action and thus takes the -vaD suffix. Invective operatorKlingon is a language of great emotional depth. By comparison, programming in Terran languages is an insipid, bloodless experience. Of particular note is the special programming construct: jay'. In Klingon it may be appended to a sentence to enhance it's emotional intensity. Thus: qaSpu' nuq 'e' yIja'! Tell me what happened! becomes: qaSpu' nuq 'e' yIja' jay'! Tell me what the *#@& happened! This useful and satisfying internal documentation technique can be used anywhere in a tlhInganHol::yIghun program. For example:
Module control optionsIf the module is imported with the argument y[IQij]: use Lingua::tlhInganHol::yIghun "yIQij"; it runs in debugging mode. If the module is imported with the argument yImugh: use Lingua::tlhInganHol::yIghun "yImugh"; it demeans itself to merely translating your glorious Klingon Perl code into a pale Terran Perl imitation. If the module is imported with the argument tera'nganHol (or tera::nganHol: use Lingua::tlhInganHol::yIghun "tera'nganHol"; it debases itself to output numeric values in Terran, rather than in the original Klingon. DIAGNOSTICS
ACKNOWLEDGEMENTSAUTHORDamian Conway (damian@conway.org) BUGSIn this module??? I should kill you where you stand! Send your challenge to me. If you dare! SEE ALSOThe Klingon Language Institute <http://www.kli.org/> The Varaq programming language <http://www.geocities.com/connorbd/varaq/> COPYRIGHTCopyright (c) 2001, Damian Conway. All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same Terms as Perl itself. Appendix 1: thlIngan-Terran dictionary
Appendix 2: [Terran-thlIngan] dictionary
Release of version 0.01 of Lingua::tlhInganHol::yIghunDESCRIPTIONCHANGES IN VERSION 0.01(No changes have been documented for this version) AVAILABILITYLingua::tlhInganHol::yIghun has been uploaded to the CPAN and is also available from: Damien Conway CHANGES
MANIFESTChanges MANIFEST Makefile.PL test.pl yIghun.pm demo_conj.pl demo_eratosthenes.pl demo_misc.pl demo_sub.pl demo_unary.pl Makefile.PL use ExtUtils::MakeMaker; WriteMakefile( NAME => 'Lingua::tlhInganHol::yIghun', VERSION => '0.01', ); demo_conj.pl
demo_eratosthenes.pl
demo_misc.pl
demo_sub.pl
demo_unary.pl
test.pl
|
|||||||||||||||||||||
|
|||||||||||||||||||||