Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Lingua::Romana::Perligata - Basica Basicum Basicus

by benn (Priest)
on Apr 28, 2003 at 19:12 UTC ( #253797=perltutorial: print w/ replies, xml ) Need Help??

Intro
I love this module - you maybe able to tell from the fulsome praise below. I've been admiring the principle from afar for a long time now, and finally decided to get my feet wet a little while ago. I'm still paddling, so this is as much a way of me reviewing what I've learnt as it is a tutorial for others, but as there is nothing already out there other than TheDamian's original paper and the POD (basically derived from it), I thought I'd throw this in the water as a possible lifebelt, especially for those (like myself) who have little formal grammar under their belt.

Lingua::What?
A module (henceforth referred to as L::R::P to save typing) by TheDamian that allows perl programming using Latin prose.

How?
Filter::Util and a big YAPP (Sorry Damian - and I quote "YAPP couldn't handle the stress, nor P::RD") home-brewed parser. If you use L::R::P 'converte';, you can see what the translated-back-to-perl looks like - use L::R::P 'discribe'(classify) and use L::R::P 'investiga' (trace) for even more info on the magic - handy when you're debugging.

Why?
The answer given in the definitive paper (and duplicated in the POD) is "If you have to ask why, you probably won't understand the answer". Feeling that a little harsh maybe, I'd prepend "Because you can". If you still have to ask why, then we start getting into complicated issues of aesthetics and linguistics...

Nope - still why?
OK - here's where the linguistics bit starts - sorry, but you did ask :) In English, word order matters greatly - "man bites dog" is very different in meaning to "dog bites man". In some (generally older) languages though, this is not the case. They can say "The man bit the dog", "The dog was bitten by the man", "The dog by the man was bitten", "Biting was done to the dog by the man" etc. etc. using all the same words (rather than "bit, "was bitten","biting was" etc.) in any order.

Word order is important in most programming languages too - $x = $y being rather different to $y = $x (I know - we've all been there...). Wouldn't it be nice if that particular 'bug' never cropped up again? If you could say "$x is to be acted upon by $y" or "$y is to act upon $x" - the way you already can in perl with if $x {foo} and foo if $x?

As for the aesthetics...well, IMHO, this exemplifies the aesthetics of perl itself. And if that's not enough for all you youngsters out there, then how about "*Man!* You can write a CGI script in *Latin* and show it to all your friends? Just How Cool Is That?". Groovy.

Sold - so How, again?
The way to do this easily is by using different word-endings, or inflection - the thing that distinguishes "thing" from "things", or determines whether you thinged, are thinging, or will thing. That's about it for English - we distinguish singular from plural, and the timeframe (tense). Many other languages use inflection (or 'inflexion', as all you non-Brits have it :) ) to determine things like the gender of the subject - an Italian male may be "bello" , or 'handsome', while a female is "bella", or 'pretty'.

Now...Latin also uses inflection to determine the role of the word - for instance, whether it is "doing" (the 'subject') , or "having done to" (the 'object').
(Meat of this example nicked from the Introduction to the paper mentioned earlier, as (a) It's about as clear as you can get, and (b) I can't be bothered to drag out my Latin textbooks to contrive another one - maybe I'll expand on 'man bites dog' later.)
The phrase "Puer dedit cani escam" means "The boy gave the dog the food". Each word's ending determines its role in the sentence, so one could also say "Escam dedit puer cani" ("The food was given by the boy to the dog"), or (most commonly) 'reverse Polish', with the verb at the end: "Puer cani escam dedit. " ("The boy to the dog the food did give"). Same words, different order.

"Puer" (boy), is the subject of the sentence - the one that was doing the giving, so it takes no ending. "esca" (food), becomes "escam", as it's the direct object - the thing that is being given. The "canis" (dog) drops the 's' to become the indirect object - the thing that is being given to. If the dog gave some food back, it would be "Canis puero escam dedit"- the 'o' denoting that the boy is now the indirect object.

Before you start sweating - don't worry. Although Latin is the uber-grammar language, and has been known to make small boys wet themselves rather than attempt to decline "to beat soundly", you'll only need to learn a few of these endings to write L::R::P.

Enough with the theory already - show me some code.
Being rather canonical, here's something that should be recognisable.

scribe egresso dictum sic Hello World cis.
Literally translated, that comes out as.."Write to the Exit the result of saying (as follows) Hello world (to here).".
Or, more loosely, "print STDOUT q{Hello World};".
Note that it ends, as in English, with a period rather than a semi-colon. L::R::P doesn't like anything except alphanumerics and periods - all sigils are completely out of the egresso.

Taking that apart, we get "scribe" (print - that's an easy one we still use in English) , "egresso" (STDOUT, literally 'the exit') , "dictum" (like 'dictate' - a quote operator) and the 'brackets' "sic" and "cis" ('as follows' and 'to here' - almost too good to be true...). Even if you're not thinking about writing any code, check out the THESAURUS PERLIGATUS in the POD just for a laugh at the translations - my favourites are STDERR ('oraculo' - a place where doom is pronounced) and rmdir ('excide', or raze, as in '...to the ground').

(Actually, the more usual way of saying this would be... Hello tum World inquementum scribe egresso. ...or "print the result of saying Hello then World" but that particular example doesn't work. Hiya tum World ... is OK though, for reasons to be explained shortly.)

Without further ado, let's get straight to...

Variables
$var = 8; would be expressed as...

varo VIII da. # or 'da varo VIII' or 'da VIII varo' or...
(or "meo varo VIII da." if you're using strict - guess what 'meo' is :)

"da" is "=" ('to give'). "var", as the indirect object (the thing being given to - remember?) takes an 'o' to become "varo". And it's being given 'VIII' - yup - even the numbers are in Latin. For 1-10, you can use some names as well - 'unum', 'duo', 'tres' etc. , and zero is "nullum".

When it comes to printing it out, on the other hand, 'var' is now an rvalue (rather than the lvalue it was when it was being assigned to), and is the subject of the 'print' verb, so...

varum scribe egresso.
...and that's basically how the trick is done. That's why you can say either"scribe egresso varum" or "varum scribe egresso" - "um" denotes that it can only be used as an rvalue, so under the hood, "print" knows that the "whatever-um" next to it is to be printed ( as opposed to the "eggress-o", which it's doing the printing *to*, and which BTW is why 'Hello' as a 'bareword' gets translated to '$Hell'). "varum scribe egresso", "scribe egresso varum", "egresso scribe varum", "scribe varum egresso", "varum egresso scribe", "egresso varum scribe". All the combinations. They all work. Isn't that lovely?

That's scalars - arrays and hashes are similar, except they use a couple of different plural forms (as perl uses '@' or '%') to distinguish them from $ingulars.
(Two different types of plurals? Oh Yes - Latin can be a nightmare...

BRIAN: R-- Romanus? CENTURION: Goes like...? BRIAN: 'Annus'? CENTURION: Vocative plural of 'annus' is...? BRIAN: Eh. 'Anni'? CENTURION: 'Romani'!
Romani ite Damian's Domum. )

So, we get this...

da meo arrayis I tum II tum III. # my @array = (1,2,3); arraya scribe egresso. meo hashibus key1 tum I tum key2 tum II da. # my %hash=(key1=>1,key2= +>2) hashus scribe egresso.
'tum' ('and then') is a comma, so we have "give 1 then 2 then 3 to the array".

If you got this far, you don't need me any more - get straight to the manual and start coding. Remember about 'converte', 'discribe' and 'investiga' - you'll find them very useful. Any suggestions regarding further material to add to this tutorial (or places where I've got it plain wrong) as ever welcome.

Thanks to ybiC for the obligatory Monty Python link.
Minor formatting / syntax updates 29/04/03

Ben

Comment on Lingua::Romana::Perligata - Basica Basicum Basicus
Select or Download Code
Re: Lingua::Romana::Perligata - Basica Basicum Basicus
by parv (Priest) on Apr 28, 2003 at 19:39 UTC
    Great prose.
Re: Lingua::Romana::Perligata - Basica Basicum Basicus
by Anonymous Monk on Jul 14, 2005 at 22:12 UTC
    Extraordinaire ! That's really useless, but so funny !!! ben
Re: Lingua::Romana::Perligata - Basica Basicum Basicus
by lishevita (Novice) on Jun 14, 2006 at 18:11 UTC
    This is *precisely* what I love about Perl and the Perl community. Perl is the language for people who love language, no question.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perltutorial [id://253797]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2014-09-21 12:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (168 votes), past polls