Yoix

From Wikipedia, the free encyclopedia

Yoix
Image:Yoixlogo.png
Paradigm: Multi-paradigm, Object-based, procedural
Appeared in: 2000
Designed by: Rich Drechsler and John Mocenigo
Latest release: 2.1.4 / January 25, 2007
Typing discipline: Dynamic, Weak
Influenced by: C, Java, PostScript
OS: Cross-platform
License: Open Source Initiative Common Public License
Website: http://www.yoix.org/


Yoix is a pure Java programming language implementation of a general purpose scripting language developed by researchers at AT&T Labs. Its syntax and grammar should be easy to learn for those familiar with the C programming language and Java. To an end-user, a Yoix application is indistinguishable from a Java application, but to the application developer Yoix should provide a simpler coding experience than working in Java directly, much like writing Perl code can be simpler than writing C code.

Yoix is not an object oriented language, but makes use of over 150 object types that provide access to most of the standard Java classes. Because the Yoix interpreter is built entirely using Java technology, it means that Yoix applications are cross-platform, GUI-capable and both network and thread friendly, yet Yoix developers find themselves insulated from the more cumbersome and tricky parts of coding the same functionality directly in Java. It does not use reflection to access Java functionality and thus adds value by not only simplifying access to that functionality, but also improving application reliability by coding through both Java glitches and complicated Java features one-time, behind-the-scenes. The Yoix language includes pointers, addressing, declarations, and global and local variables. In addition to supporting native user functions, users can add their own builtin functions written in Java.

A data visualization module called YDAT (Yoix Data Analysis Tool) has been included in the public Yoix distribution since release 2.1.2. YDAT uses a data manager component to coordinate data display and filtering among its several visualization components that include an event plot, a graph drawing pane, histogram filters and tabular detail. YDAT is able to display graphs generated by the GraphViz graph drawing and layout tool, which is another open source tool freely available from AT&T Labs. YDAT is highly configurable at the Yoix language level. The image below is a screenshot of a Yoix YDAT instantiation, which in this example is being used to analyze vehicle auction transactions.

Image:Vhcl.jpg

Yoix is free software licensed under the Open Source Initiative Common Public License. Yoix is a registered trademark of AT&T, Inc.

[edit] Examples

1. Extract all HTML directives from the AT&T home page and write them to standard output.

import yoix.*.*;

URL att = open("http://www.att.com", "r");
String text;
int cnt = 0;
while (cnt >= 0) {
  if ((cnt = fscanf(att, " <%[^>]>", &text)) > 0)
    printf("<%s>\n", text);
  else cnt = fscanf(att, " %*[^<]");  // discard
}

2. Build and display a GUI with two buttons in a titled frame (i.e., window) that also has a titled border. One button pops up a message when pressed, the other quits the example. The window is sized automatically to just fit its components, and some additional code calculates its location to put it in the center of the screen before making it visible.

import yoix.*.*;

JFrame  jf = {
  Dimension  size = NULL; // auto-size window

  FlowLayout  layoutmanager = {
    int hgap = 18; // 0.25 inch gap
  };

  String  title = "Wikipedia Yoix Example"; // window title
  String  border = "Simple Button Example"; // border title

  Array  layout = {
    new JButton {
      String  text = "Press for Message";

      actionPerformed(ActionEvent ev) {
        showMessageDialog(root, "Hello, world.", "Message Example");
      }
    },
    new JButton {
      String  text = "Press to Exit";

      actionPerformed(ev) { // ActionEvent declaration can be omitted
        exit(0);
      }
    },
  };
};

// set frame location to center of screen now that frame size is known
jf.location = new Point {
  int x = (VM.screen.width - jf.size.width) / 2;
  int y = (VM.screen.height - jf.size.height) / 2;
};

// make it visible
jf.visible = TRUE;

3. The code shown here was used to generate the Yoix logo image in PNG format that can be seen in the language description box near the top of this page. Command-line arguments allow the size of the image to be specified as well as select between PNG image output or display in an on-screen window.

import yoix.*.*;

BuildYoixLogoImage(double height, Color color, int addshadow) {
  // create the basic image, without shadow
  GenImage(double height, Color color, Font imagefont, double scale) {
    Image yoixlogo = {
      int type = TYPE_RGB_ALPHA;
      Color imgcolor = color;
      double scale = scale;
      Font imagefont = imagefont;
      Font regfont = imagefont.scalefont(0.5, 0.5);
      Graphics graphics = {
        Font font = imagefont;
        int textantialiasing = TRUE;
      };
      double ywd = stringWidth(graphics.font, "Y");
      Dimension size = {
        double height = height;
        double width = ywd * 5.25;
      };
      double owd = stringWidth(graphics.font, "o");
      double iwd = stringWidth(graphics.font, "i");
      double xwd = stringWidth(graphics.font, "x");
      ywd += iwd;
      ywd /= 2.0;
      paint(Rectangle r) {
        double alpha = 1.0;
        double alpha2 = 0.3333;
        int    limit = 12;
    
        graphics {
          gsave();
          erasedrawable(0.0); // for transparent PNG
          rectclip(r);
          setrgbcolor(imgcolor.red, imgcolor.green, imgcolor.blue);
          translate(48 * this.scale, 44 * this.scale);
          for(n=0; n<limit; n++) {
            moveto(0.0, 0.0);
            setfont(this.imagefont);
            // "handmade" kerning
            show("Y", alpha);
            if (n == 0) {
              moveto(ywd, 0.0);
              show("o", alpha);
              moveto(ywd + owd - 0.3 * iwd, 0.0);
              show("i", alpha);
              moveto(ywd + owd + 0.8 * iwd, 0.0);
              show("x", alpha);
              moveto(ywd + owd + 0.8 * iwd + xwd, -this.imagefont.height * 0.33);
              setfont(this.regfont);
              show("\xAE", alpha);
              alpha = alpha2;
            }
            alpha *= 0.75;
            rotate(30);
          } 
          grestore();
        }
      }
    };

    return(yoixlogo);
  }

  Font basefont = {
    String name = "ClearviewATT-plain-48";
  };
  double scale = height / 90.0;
  Font imagefont = basefont.scalefont(scale, scale);

  if (addshadow) {
    Image logo = GenImage(height, color, imagefont, scale);
    image = new Image {
      int type = TYPE_RGB_ALPHA;
      Image source = logo;
      Image img = logo;
      // convolve image to make a (lightened) shadow
      Image shadow = new Image {
        int type = TYPE_RGB_ALPHA;
        Image source = img;
        Array kernel = new Array[100];
        Pointer ptr;
        for(ptr in kernel) *ptr = 0.0055;
        paint() {
          convolve(kernel);
        }
      };
      // combine the image and shadow into one image
      paint(Rectangle r) {
        graphics {
          gsave();
          moveto(0, 0);
          showimage(this.img);
          moveto(this.img.size.height * 0.005, this.img.size.height * 0.02);
          showimage(this.shadow);
          grestore();
        }
      }
    };
  } else {
    image = GenImage(height, color, imagefont, scale);
  }

  return(image);
}

// rudimentary argument processing (getopt is also available)
// first argument is height of image
double sz = (argc > 1) ? atof(argv[1]) : 270;
int shdw = 1;
int print = 0;
// second argument: if 0/1 turn shadow off/on, otherwise
// assume it is a filename for printing.
if (argc > 2) {
  if (argv[2] =~ "^[01]$") {
    shdw = atoi(argv[2]);
  } else {
    print = 1;
  }
}

Image yoixlogo = BuildYoixLogoImage(sz, Color.black, (sz >= 72) && shdw);

if (print) {
  Stream output;

  if ((output = open(argv[2], "w")) != NULL) {
    encodeImage(yoixlogo, "png", output);
    close(output);
  }
} else {
  JFrame jf = {
    int visible = TRUE;
    Dimension size = NULL;
    Array layout = {
      new JPanel {
        Dimension preferredsize = {
          double width = yoixlogo.size.width;
          double height = yoixlogo.size.height;
        };
        Color background = Color.white;
        Image backgroundimage = yoixlogo;
        int backgroundhints = SCALE_NONE;
      },
    };
  };
}

[edit] External links