Context-Oriented Algorithmic Design Bruno Ferreira António Menezes Leitão Algorithmic Design 2 CAD Tools 3 BIM Tools 4 BIM Tools 5 Complex Buildings 6 Complex Buildings 7 Need For Analysis 8 Several Tools 9 Khepri 10 Khepri 11 Khepri 12 Khepri 13 Code can become messy 14 15 One script for all models 16 Context-Oriented Programming COP > Behavioral Variations > Layers > Activation mechanism > Context > Scoping 17 Objectives > Present and compare COP > Combine COP with AD 18 Related Work 19 Aspect-Oriented Programming > Cross-cutting concerns > Aspects > Pointcuts, Join Points, Advice 20 Subject-Oriented Programming > Subjects > Subject-activation > Subjective Dispatch 21 Context-Oriented Programming > Contexts > Contextual Dispatch 22 ContextL > Common Lisp > Dynamically Scoped Layer Activation > Layered Generic Functions > Layer-in-class and class-in-layer 23 ContextL (deflayer employment-layer) (with-active-layers (employment-layer) ... contained code ...) (define-layered-class employer :in-layer employment-layer () ((name :initarg :name :layered-accessor employer-name))) 24 ContextPy > Python > Dinamically Scoped Layer Activation > Decorators > Layer-in-class 25 ContextPy class Slab: @around(a3DLayer) def generate(self): return extrusion(surface_from(self.path), self.thickness) @around(a2DLayer) def generate(self): return self.path 26 ContextJ > Java (source-to-source compiler) > Dynamically Scoped Layer Activation > Reflection API > Layer-in-class 27 ContextJ class Employer{ String toString() { return “Name: ” + name; } layer Address { String toString() { return proceed() + “; Address: ” + ... } } 28 Lambic > Common Lisp > Predicate Dispatch > Activation with Predicates > Different modularization 29 Lambic (defgeneric factorial (n) (:predicates < = >)) (defmethod factorial (n) (:when (> n 0)) (* n (factorial (- n 1)))) (defmethod factorial (n) (:when (= n 0)) 1) 30 Comparison 31 32 Context-Oriented Algorithmic Design 33 COAD BIM CAD Energy Program Radiation Structural 34 Implementation Visualization Tool COP Library Rendering Tool Khepri Analysis Tool … Implementation > ContextScheme (adapted to Racket) > Khepri 35 Case Study 36 Case Study 37 Original Version (define (shop-2d ...) (... (line ...) (rectangle ...) ...)) (define (shop-3d ...) (... (right-cuboid ...) ...)) 38 Original Version (define (mall ... shop ...) (... (shop ... ) ...)) 39 COP Version (define (shop p v l w) (... ((wall) p0 p1 wall-thickness wall-height) ... ((door) ((wall) p2 p3 wall-thickness wall-height) p4 p5 wall-thickness door-height)))) 40 COP Version (with-layers (2D) (mall (xy 0 0) 100000 12000 25000 7000 7000 4)) 41 COP 2D 42 COP 3D 43 COP Analysis 44 Partial Modelling 45 Partial Modelling 46 Advantages > Reduces the code > Dynamic context change 47 Evaluation 48 Evaluation > Higher-order or not? > Implicit or Explicit Activation? > Performance? 49 Future Work 50 Thank you! Questions? bruno.b.ferreira@tecnico.ulisboa.pt antonio.menezes.leitao@tecnico.ulisboa.pt https://algorithmicdesign.github.io/