Saturday, December 27, 2014

A bit of fun with Jabberwocky, classes, mixins, python and method resolution order (MRO)

I was trying to figure out and demonstrate python's Member Resolution Order... In particular, pay attention to the output from __str__...

#!/usr/bin/env python
# -*- coding: utf-8 -*-

class BeastBase(dict):
  def __init__(self, **characteristics):
    super(BeastBase, self).__init__(**characteristics)

  def __str__(self):
    return "; ".join(["%s=%r"%item for item in super(BeastBase, self).iteritems()])

class Mixin(object): pass

class BitingMixin(Mixin):
  def __init__(self, jaws=2, teeth_per_mouth=32, **characteristics):
    super(BitingMixin, self).__init__(**characteristics)

  def bite(self):
    print "Bite: jaws=%s, teeth=%s"%(self.jaws, self.teeth_per_mouth*self.jaws/2)

  def __str__(self):
    return "Jawed: %s; %s"%(self.jaws, super(BitingMixin, self).__str__())

class JawedBeast(BeastBase, BitingMixin): pass

class ClawingMixin(Mixin):
  def __init__(self, feet=4, toes_per_foot=3, **characteristics):
    super(ClawingMixin, self).__init__(**characteristics)

  def catch(self):
    print "Catch: feet=%s, toes=%s"%(self.feet, self.toes_per_foot*self.feet)

  def __str__(self):
    return "Claws: %s; %s"%(self.toes_per_foot*self.feet, super(ClawingMixin, self).__str__())

class ClawedBeast(BeastBase, ClawingMixin): pass

class FlamingMixin(Mixin):
  def __init__(self, eyes=6, flames_per_eye=1, **characteristics):
    super(FlamingMixin, self).__init__(**characteristics)

  def flame(self):
    print "Flames:", self.eyes*self.flames_per_eye

  def __str__(self):
    return "Eyes: %s, Flames: %s; %s"%(self.eyes, self.eyes*self.flames_per_eye, super(FlamingMixin, self).__str__())

class FlamedBeast(FlamingMixin, BeastBase): pass

class WhifflingMixin(Mixin):
  def whiffle(self): print "Whiffle...."
  def __str__(self): return "Whiffling... "+super(WhifflingMixin, self).__str__()

class WhifflingBeast(WhifflingMixin, BeastBase): pass

class BurblingMixin(Mixin):
  def burble(self): print "Burble...."
  def __str__(self): return "Burbling... "+super(BurblingMixin, self).__str__()

class BurblingBeast(BurblingMixin, BeastBase): pass

class Jabberwocky(BitingMixin, ClawingMixin, FlamingMixin, WhifflingMixin, BurblingMixin, BeastBase):
  def __init__(self, **characteristics):
    super(Jabberwocky, self).__init__(**characteristics)

  def __str__(self):
    return "JabberWocky: "+super(Jabberwocky, self).__str__()+" ... Beware! "

if __name__ == "__main__":

# Beware the Jabberwock, my son!
  jabberwocky1=Jabberwocky(personality="Friendly", consideration="Temperamental", eyes=5, flames_per_eye=3)
  print jabberwocky1

# Beware the Jubjub bird, and shun
# The frumious Bandersnatch!

# The jaws that bite, the claws that catch!

# And as in uffish thought he stood,
# The Jabberwock, with eyes of flame,

# Came whiffling through the tulgey wood,
# And burbled as it came!

JabberWocky: Jawed: 2; Claws: 12; Eyes: 5, Flames: 15; Whiffling... Burbling... consideration='Temperamental'; personality='Friendly' ... Beware!
Bite: jaws=2, teeth=32
Catch: feet=4, toes=12
Flames: 15

Saturday, March 8, 2014

A brief history of Air Traffic Control and on-line Aircraft Tracking Systems...

Today's loss of flight MH370 got me wꜵndering the internet briefly investigating how Aircraft Tracking/Control systems have changed over the years.
  • 1958 - Semi-Automatic Ground Environment - The prototype was an IBM 4020 Military Computer
    "SAGE—Air Force project 416L—became the pattern for at least twenty-five other major military command-control systems… These were the so-called “Big L” systems [and] included 425L, the NORAD system; 438L, the Air Force Intelligence Data Handling System; and 474L, the Ballistic Missile Early Warning System (BMEWS). … Project 465L, the SAC Control System (SACCS) [with] over a million lines, reached four times the size of the SAGE code and consumed 1,400 man-years of programming; SDC invented a major computer language, JOVIAL, specifically for this project." 
  • 1958 - Algol58/JOVIAL created.
  • 1961- AN/FSQ-31V- SAGE Solid State Computer was a planned military computer central for deployment to Super Combat Centers in nuclear bunkers
  • 1968 - ALGOL 68 Final Reportr0 Presented at Munich Meeting
  • 1980 - re: 1968 ... The best we could do was to send with it a minority report, stating our considered view that, "... as a tool for the reliable creation of sophisticated programs, the language [ALGOL 68] was a failure." [...] - C. A. R. Hoare  Oct 1980

¢ My commentary: Algol68 should have been adopted and replaced Algol60, but [IMHO] instead Algol68 was shot down by a vocal minority.  Sure, I would love to own and drive a 1961 E-type Jaguar, but it would be better with airbags and a GPS.  So the 1968 Security, Efficiency, Type-safety, Standardization and Internationalization offered by Algol68 (which predates C11 well by over 40 years!) should have been leveraged in 1968! Algol68 is kind of like a 1961 E-type Jaguar, but with seat-belts, air-bags, a roll-bar, traction-control and modern tyres! ¢

BTW:  As a wonderful example of today's "crowd-sourcing": Do you regularly have aircraft pass (or cross paths) over your home/community? but you live in the "middle-of-every-where"... How about becoming part of "flight-aware" and to help track aircraft?  If your location is "desirable", then you may get a free [ADS-B] to put on your roof... Here is the current coverage map:

Click MH370 for an example of this flightaware's tracking of MH370.

Update: My best guess as to where MH370 is... On a "great circle" west of Kuda Huvadhoo (in the Maldives).

Friday, March 7, 2014

Was Algol ever used for “mainstream” programming?

¢ I rather liked this answer on Stackoverflow, so I am reproducing it here ¢
Algol58 seems to have been the most successful in terms of important applications.

From Wikipedia:
JOVIAL is an acronym for “Jules Own Version of the International Algorithmic Language.” The “International Algorithmic Language” was a name originally proposed for ALGOL 58. It was developed to compose software for the electronics of military aircraft by Jules Schwartz in 1959.
Notable systems using JOVIAL include the Milstar Communications Satellite, Advanced Cruise Missile, B-52, B-1B, B-2 bombers, C-130, C-141, and C-17 transport aircraft, F-111, F-15, F-16 (prior to Block 50), and F-117 fighter aircraft, LANTIRN, U-2 aircraft, E-3 Sentry AWACS aircraft, Navy Aegis cruisers, Army Multiple Launch Rocket System (MLRS), Army UH-60 Black Hawk helicopters, F100, F117, and F119 jet engines, the NORAD air defense & control system (Hughes HME-5118ME system) and RL-10 rocket engines. Airborne radar systems with embedded JOVIAL software include the APG-70, APG-71 and APG-73
ALGOL 68 was used in part of DRA for the same purpose. cf. Wikipedia:
The ”’Defence Research Agency”’ (normally known as ”’DRA”’), was an executive agency of the UK Ministry of Defence (MOD) from April 1991 until April 1995. At the time the DRA was Britain’s largest science and technology organisation.
DRA’s Algol68 compiler was finally open-sourced in April 1999 and is now available for linux for download from sourceforge. (However an interpreter for “Algol68g” is easier to use).

ICL’s Algol68 was/is S3 – It was developed by the UK company International Computers Limited (ICL) for its 2900 Series mainframes. It is a system programming language based on ALGOL 68 but with data types and operators aligned to those offered by the 2900 Series. It was the implementation language of the operating system VME.

There are (at least) two other British operating systems – Flex and Cambridge_CAP_computer – written in Algol68 variants. And also 1 Soviet OS: Эльбрус-1 (Elbrus-1), but I have yet to find any of their source code. (If anyone can find and distribute to this source code please let me know)

BTW: I believe that VME is still running – in production – as a Linux/Unixware guest VM. Mostly at Commonwealth of Nations Custom/Immigration services.
Also over the same period the USSR was using Algol68, c.f. history link. Algol68 is used in Russian telephone exchanges. And Algol58 was used in the Russian “Buran/Буран” Space Shuttle landing system.

ALGOL68 was internationalized in 1968. I suspect there are other Algol projects in other countries. esp in German, in Dutch Japanese and Chinese but I have no details.

If you want to actually tryout Algol68 and/or contribute your code, check out Rosettacode’s ALGOL 68 repository, then as a class project try one of the “Tasks not implemented“.


Wednesday, February 12, 2014

Déjà vu: SMIL-2.0 vs Algol-68

SMIL-2.0: The example assume video and audio media that are recorded to be in exact sync with one another:

<par dur="indefinite">
  <img id="foo" end="click" .../>
  <video id="bar" begin="foo.endEvent" .../>
  <audio id="copy" begin="foo.end" .../>

Algol-68: An example of a parallel-clause which synchronizes eating and speaking:

PROC VOID eat, speak; SEMA mouth = LEVEL 1;
           DOWN mouth;
           UP mouth
           DOWN mouth;
           UP mouth