Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

That's in many cases what a LET with a dynamic binding does in Lisp.

Set origin draw Reset Origin

is

    (let ((origin (move 50 50)))
      (draw something))
Similar in the Common Lisp object system we use :before, :after and :around methods.

    (defmethod draw :before () (move 50 50))

    (defmethod draw () (draw-something))

    (defmethod draw :after () (move -50 -50))


> Similar in the Common Lisp object system we use :before, :after and :around methods

Ditto for Moose (in Perl)...

  before draw => sub { shift->move( 50, 50 )};

  sub draw { shift->draw_something }

  after draw => sub { shift->move( -50, -50 )};
Also you can package up these method modifiers into a role which not only can be composed into a class but can also be applied just to an object...

  {
    package DrawRole;
    use Moose::Role;
    
    before draw => sub { shift->move( 50, 50   )};
    after  draw => sub { shift->move( -50, -50 )};
  }

  my $d = Draw->new;
  DrawRole->meta->apply( $d );


I think you mean Special Operator UNWIND-PROTECT.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: