Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

The Science of Programming/SwayPresentations/Objects/Examples3

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

Examples Being able to extend a class such that the subclass has the same name is a great way to implement aspects. extends(stack()); //if subclass has new name extends((shadowed(:stack))()); //if subclass has same name As an alternative, here's an instrumented stack using filters: include("stack.s"); function emptyPopChecker($expr) { if ($expr . context . empty?()) { throw(:stackError,"pop on empty stack"); } force($expr); } Then we make and instrument a particular stack: var s = stack(); s . pop . filter = emptyPopChecker; Not quite right. Anybody? function emptyPopChecker2($expr) { var result = catch(force($expr)); if (type(result) == :ERROR) { throw(:stackError,"pop on empty stack"); } result; } Next Previous Top