[Home]AphroditeDescription

TheSourcery | RecentChanges | Preferences | Index | RSS

No diff available--this is the first major revision. (minor diff)
This is from a post describing some of the features of my mudlib language, Aphrodite.

Aphrodite Description

Below is a decompiled object dump with many attributes and methods expunged and a few added for illustration that wouldn't be there. Note that the programmer normally doesn't type all this in all at once, as defining objects, attributes and methods is done interactively online. The begin and end keywords common to pascal are rarely inserted manually by the programmer unless they are specifically coding a sub block within a method. I used to have pascal like blocks in all my if/else statements and loops but now they are instead marked with their own special terminators, e.g. endif/wend/endfor/until.

There's a lot of implicit stuff here that might not be obvious.

Here's some sample code:

object $bag
begin;
inherits $container, $thing;
attrib weight 50.00; 
attrib maxweight 1000.00;
attrib contents {};
attrib location $user_tyche;

method weight reserved
begin;  
  if _@ 
    // test for arguments
    weight := weight + _@[1];
  endif
  return weight;
end;

method get exported
begin;
  var item;
  
  item := _#.getenv(_@[1]); 
  // getenv inherited from container
  if item = _!
    _&.tell("There is no %n inside %n, item, name) 
    return "There is no " + _@[1] + " inside.";
  else  
    _#.weight(item.weight() * -1);
    item.moveto(_&);
    _&.location().tell("%n removes %n from %n.", _&, item, name); 
  endif  
end;    

method fastroutine native

method sample_loops exported
begin;
  // prints hello world to user.
  var msg, i;
  msg = {"Hello", "world"};
  
  i := 1;
  repeat
    _&.tell(msg[i]);
    ++i;  
    // no postfix operator
  until i = 3
  
  foreach x in msg
    _&.tell(x);
  endfor
  
  i := 1;
  while i < 4
    _&.tell(msg[i]);
    i := i + 1; 
  wend
end;  

method sample_lookup exported
begin;
  var table, item;
  
  table := [[1,"orc"],
            [2,"elf"],
            [3,"dwarf"]
           ];
  if args
    item := table.lookup(args[1]);
    if item
      user.tell("%v found", item)
    else
      user.tell("Couldn't find a match for %v", args[1]);  
    endif  
  else
    user.tell("No arguments provided");
  endif
end;


TheSourcery | RecentChanges | Preferences | Index | RSS
Edit text of this page | View other revisions
Last edited May 28, 2005 7:31 am by JonLambert (diff)
Search:
All material on this Wiki is the property of the contributing authors.
©2004-2006 by the contributing authors.
Ideas, requests, problems regarding this site? Send feedback.