bwerf's Blog

It's plukalicious
posts - 14, comments - 12, trackbacks - 0, articles - 0

Wednesday, January 16, 2008

After reading about collections in ruby and c#, i'm thinking about how to add collections to pluk.

Collection libraries seem to have become part of what people expect from a language, and seem to basicly consider it a part of it.

Not unreasonably seeing how things like foreach directly talk to its api.

So i'm designing the baseclass that will back most collections, and probably some other 'containers'.

abstract class Iteratable<T>
{
        Iterator<T> createIterator;
        Iteratable<T> copy();
        Iteratable<T> filter(Bool(T) predicate);
        Iteratable<U> map<U>(U(T) converter);
        Iteratable<T> take(Int count);
        Iteratable<T> drop(Int count);
        void foreach(void(T) action);
        U fold<U>(U(U, T) folder, U base);
        Bool exists(Bool(T) predicate);
        Bool all(Bool(T) predicate);
        Bool none(Bool(T) predicate);
}

Things like Sum / Min / Max / Average / Aggregate can be easily be used through the fold method, and so can exists/all/none. Inclusion of directer methods should depend on how commonly something is used, and if it actually saves work/thinking in the long run.

Methods like filter do not return an iteratable with the filtered data but an iteratable that when queried filters based on the filter function from the original iteratable on demand.

This way of lazy processing is more memory efficient generally.

This interface should allow additional syntax sugar like C# LINQ to work with pluk collections.

 

 

 

posted @ 10:07 PM | Feedback (0)

http://blog.micropledge.com/2008/01/ten-python-quirkies/

http://blogs.msdn.com/wesdyer/archive/2007/01/03/how-linq-to-objects-queries-work.aspx

posted @ 1:53 PM | Feedback (0)

It has some issues with shutting down that i'm too lazy to figure out, but it loads and adds a !dumpimage command to windbg that i used to feed a tool i use to find the number of objects in memory used to find memory leaks

library DrBart

// WinDbg plugin that dumps a 4G file named d:\dump\a containing the full memory space of the current open dump/process

// in windbg
// .load DrBart
// .dumpimage
 
uses
  SysUtils,
  Classes;
 
{$R *.res}
 
type
  TExtensionApis = record
    nSize: Cardinal;
    lpOutputRoutine: Pointer;
    lpGetExpressionRoutine: Pointer;
    lpGetSymbolRoutine: Pointer;
    lpDisasmRoutine: Pointer;
    lpCheckControlCRoutine: Pointer;
    lpReadProcessMemoryRoutine: Pointer;
    lpWriteProcessMemoryRoutine: Pointer;
    lpGetThreadContextRoutine: Pointer;
    lpSetThreadContextRoutine: Pointer;
    lpIoctlRoutine: Pointer;
    lpStackTraceRoutine: Pointer;
  end;
  PExtensionApis = ^ TExtensionApis;
  TPrint = procedure(c: PChar); stdcall;
  TEXT_API_VERSION = record
    Major, Minor, Rev, Res: Word;
    end;
  TReadMem = function (Ptr: Cardinal; Buffer: Pointer; BufLen: Cardinal; Read: Pointer): Cardinal; stdcall;
 
var
  ExtensionApis: TExtensionApis;
  ApiVersion: TEXT_API_VERSION;
 
function dumpimage: integer; Stdcall;
var
  I: Integer;
  Ptr: Cardinal;
  Buf: array[0..511] of Byte;
  Read: Cardinal;
  fOut: TFileStream;
begin
  fout := TFileStream.Create('d:\dump\a', fmCreate);
  for I := 0 to $7FFFFF do  // 4G / 512
  begin
    Ptr := I shl 9;
    TReadMem(ExtensionApis.lpReadProcessMemoryRoutine)(Ptr, @Buf[0], 512, @Read);
    fout.WriteBuffer(Buf[0], 512);
  end;
  fout.Free;
  Result := 0;
end;
 
procedure WinDbgExtensionDllInit(
    lpExtensionApis: PExtensionApis;
    MajorVersion: Word;
    MinorVersion: Word
    ); stdcall;
begin
    ExtensionApis := lpExtensionApis^;
end;
 

function
ExtensionApiVersion(): Pointer;
begin
  Result := @ApiVersion;
      //
    // ExtensionApiVersion should return EXT_API_VERSION_NUMBER64 in order for APIs
    // to recognize 64 bit addresses.  KDEXT_64BIT also has to be defined before including
    // wdbgexts.h to get 64 bit headers for WINDBG_EXTENSION_APIS
    //
    ApiVersion.Rev := 5;
    Result := @ApiVersion;
end;
 
//
// Routine called by debugger after load
//
procedure
CheckVersion; stdcall;begin end;
 
exports
  WinDbgExtensionDllInit,
  ExtensionApiVersion,
  CheckVersion,
 dumpimage;
 
begin
end.

posted @ 10:38 AM | Feedback (3)