[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Object orientation in es, and a bug?



Yes, it's a documented bug that closures aren't preserved across es
invocations.  That's because when a new shell starts up, it just has a
bunch of environment strings with no indication that any of the closures
they represent were shared originally.  I suggested to Paul giving each
closure a unique, numeric tag so that subshells could identify which were
shared, but I suppose neither of us has had the time to implement that.

As far as OOP in es goes, I've done a small amount myself.  The most
substantial example is my implementation of conses and a bunch of list
operations.  I don't really have any idea how much space the internal
representation takes, but the external (print) representation takes an
exponential amount of space with respect to the length of the list, which
shows up as a bunch of nested (and quoted) closures:

; require list
; list a
# result = %closure(car=a;cdr=){result @ * {result $($1)} @ s v{$s=$v}}
; list a b
# result = %closure(car=a;cdr='%closure(car=b;cdr=){result @ * {result $($1)} @ s v{$s=$v}}'){result @ * {result $($1)} @ s v{$s=$v}}
; list a b c d e f
# result = %closure(car=a;cdr='%closure(car=b;cdr=''%closure(car=c;cdr=''''%closure(car=d;cdr=''''''''%closure(car=e;cdr=''''''''''''''''%closure(car=f;cdr=){result @ * {result $($1)} @ s v{$s=$v}}''''''''''''''''){result @ * {result $($1)} @ s v{$s=$v}}''''''''){result @ * {result $($1)} @ s v{$s=$v}}''''){result @ * {result $($1)} @ s v{$s=$v}}''){result @ * {result $($1)} @ s v{$s=$v}}'){result @ * {result $($1)} @ s v{$s=$v}}
; 

I think this gives new meaning to the expression "cons me harder".