Latest |Kites |Pictures |Programming |Life
[filed under Programming]Why LISP is better than me

I wish I could do this in any of the languages I use: porting-perls-qq-to-common-lisp. A few simple lines of code and you have a new language operator qq. Ugh. This would be soooo cool.

I had a problem the other day where I had an object with various members, some of which I wanted to have the extra attribute 'merge-able' some how. This is how it looked:

class moo{
  private var colour:String;
  protected var depth:Number;
  public var height:Number;
  .....

Then in a method inside moo:

foreach( prop in this )
{
  // this iterates over 'colour','depth','height'

and what I wanted was to somehow 'hide' height from the iterator...

I guess there are two ways of doing this, first override the 'iterator' or 'foreach' operator. This is impossible in ActionScript. Or second add an attribute to each property, kinda like:

class moo{
  private var colour:String;
  protected var depth:Number;
  public non-iterable var height:Number;
  .....

But there's no way to do this and no way to extend the language to make it work. It is most irritating.

I have 40 or 50 objects and I iterate over all of them. And I have this problem in one or two of them.... argh! How annoying.

The only thing I can think of is to have an iterable properties list, then:

foreach( prop in this.iterable_properties_list() )
{
  // only returns 'colour' and 'depth'
  this[prop] = ....

But this means keeping my object definition and iterable_properties_list method in sync (for over 40 different objects.) Filth.

I guess I could hack it using PHPs naming scheme, anything that starts with an underscore is 'special'. Then I could do:

foreach( prop in this )
{
  // this iterates over 'colour','depth','_height'
  if( !prop.starts_with('_') )
    // _height is magically hidden...
    ....

But then I need to rename all my properties in all my objects. Bah. I want language macros! And I want them now!! :-)

8th of July, 2008@3:03:03 PM
2 comments, permanent link to article

Comments

[15th of Aug, 2008 @ 08:49 PM]
Chris McFadyen said:
You mentioned ActionScript, though your code looks like a mix of AS and PHP...

For AS2, you can use ASSetPropFlags() to make properties non-enumerable, and in AS3 you can use Object.setPropertyIsEnumerable().
[19th of Aug, 2008 @ 10:35 AM]
Thanks chris :-) I'm always learning new stuff ;-)
name
website
Check this if you are a human being. Thanks.

Comment


Parse error: syntax error, unexpected $end in /home/teethgrinduk/public_html/bbclone/var/access.php on line 368