A #lang for data structures students 2 Welcome to DSSL2 #lang - - PowerPoint PPT Presentation

a lang for data structures students
SMART_READER_LITE
LIVE PREVIEW

A #lang for data structures students 2 Welcome to DSSL2 #lang - - PowerPoint PPT Presentation

Jesse Tov, RacketCon.eighth() A #lang for data structures students 2 Welcome to DSSL2 #lang dssl2 struct nil: pass struct cons: let car let cdr 3 class ListBuilder: let head let tail def __init__(self): self.head = nil() self.tail =


slide-1
SLIDE 1

A #lang for data structures students

Jesse Tov, RacketCon.eighth()

slide-2
SLIDE 2

Welcome to DSSL2

#lang dssl2 struct nil: pass struct cons: let car let cdr

2

slide-3
SLIDE 3

class ListBuilder: let head let tail def __init__(self): self.head = nil() self.tail = nil() def snoc(self, x): let old_tail = self.tail self.tail = cons(x, nil()) if nil?(old_tail): self.head = self.tail else:

  • ld_tail.cdr = self.tail

def build(self): let result = self.head self.__init__() result

3

slide-4
SLIDE 4

Road map

  • What’s DSSL2 for?
  • What’s it like?
  • How does it work?
  • Was it worth it?

4

slide-5
SLIDE 5

What’s it for?

slide-6
SLIDE 6

Why would I want to program in it?

You wouldn’t!

6

slide-7
SLIDE 7

Why would I want to program in it?

You wouldn’t!

6

slide-8
SLIDE 8

A story

C Java Python Ruby C++

7

slide-9
SLIDE 9

A story

  • C

Java Python Ruby C++

7

slide-10
SLIDE 10

A story

  • C
  • Java

Python Ruby C++

7

slide-11
SLIDE 11

A story

  • C
  • Java
  • Python

Ruby C++

7

slide-12
SLIDE 12

A story

  • C
  • Java
  • Python
  • Ruby

C++

7

slide-13
SLIDE 13

A story

  • C
  • Java
  • Python
  • Ruby
  • C++

7

slide-14
SLIDE 14

Disaster!

Node* node; node->data = data; Node* current = new Node; current = this->root;

8

slide-15
SLIDE 15

Disaster!

Node* node; node->data = data; Node* current = new Node; current = this->root;

8

slide-16
SLIDE 16

Prerequisites for data structures at Northwestern

  • 10 weeks of BSL/ISL
  • 10 weeks of C++

9

slide-17
SLIDE 17

What now?

Teach C++ with a side of data structures? Teach Java with a side of data structures? Teach data structures in a language the students already know? Teach data structures in a language the students can easily learn? What about a teaching language?

10

slide-18
SLIDE 18

What now?

  • Teach C++ with a side of data structures?

Teach Java with a side of data structures? Teach data structures in a language the students already know? Teach data structures in a language the students can easily learn? What about a teaching language?

10

slide-19
SLIDE 19

What now?

  • Teach C++ with a side of data structures?
  • Teach Java with a side of data structures?

Teach data structures in a language the students already know? Teach data structures in a language the students can easily learn? What about a teaching language?

10

slide-20
SLIDE 20

What now?

  • Teach C++ with a side of data structures?
  • Teach Java with a side of data structures?
  • Teach data structures in a language the students already

know? Teach data structures in a language the students can easily learn? What about a teaching language?

10

slide-21
SLIDE 21

What now?

  • Teach C++ with a side of data structures?
  • Teach Java with a side of data structures?
  • Teach data structures in a language the students already

know?

  • Teach data structures in a language the students can

easily learn? What about a teaching language?

10

slide-22
SLIDE 22

What now?

  • Teach C++ with a side of data structures?
  • Teach Java with a side of data structures?
  • Teach data structures in a language the students already

know?

  • Teach data structures in a language the students can

easily learn? What about a teaching language?

10

slide-23
SLIDE 23

What now?

  • Teach C++ with a side of data structures?
  • Teach Java with a side of data structures?
  • Teach data structures in a language the students already

know?

  • Teach data structures in a language the students can

easily learn? What about a teaching language?

10

slide-24
SLIDE 24

From Advanced Student Language…

(define (insert! t k) (cond [(tree-empty? t) (new-node k)] [(zero? (random (+ 1 (size t)))) (root-insert! t k)] [(< k (node-key t)) (begin (set-node-left! t (insert! (node-left t) k)) (fix-size! t) t)] [(> k (node-key t)) (begin (set-node-right! t (insert! (node-right t) k)) (fix-size! t) t)] [else t]))

11

slide-25
SLIDE 25

…to DSSL…

(define (insert! t k) (cond [(empty? t) (new-node k)] [(zero? (random (+ 1 (size t)))) (root-insert! t k)] [(< k (node-key t)) (set-node-left! t (insert! (node-left t) k)) (fix-size! t) t] [(> k (node-key t)) (set-node-right! t (insert! (node-right t) k)) (fix-size! t) t] [else t]))

12

slide-26
SLIDE 26

…to DSSL2

def insert!(t, k): if empty?(t): new_node(k) elif random(size(t) + 1) == 0: root_insert!(t, k) elif k < t.key: t.left = insert!(t.left, k) fix_size!(t) t elif k > t.key: t.right = insert!(t.right, k) fix_size!(t) t else: t

13

slide-27
SLIDE 27

What’s it like?

slide-28
SLIDE 28

DSSL2 in a nutshell

  • strict/eager, untyped, dynamically checked

structs (not dictionaries) fjxed-sized arrays classes and interfaces built-in support for unit tests contracts

15

slide-29
SLIDE 29

DSSL2 in a nutshell

  • strict/eager, untyped, dynamically checked
  • structs (not dictionaries)

fjxed-sized arrays classes and interfaces built-in support for unit tests contracts

15

slide-30
SLIDE 30

DSSL2 in a nutshell

  • strict/eager, untyped, dynamically checked
  • structs (not dictionaries)
  • fjxed-sized arrays

classes and interfaces built-in support for unit tests contracts

15

slide-31
SLIDE 31

DSSL2 in a nutshell

  • strict/eager, untyped, dynamically checked
  • structs (not dictionaries)
  • fjxed-sized arrays
  • classes and interfaces

built-in support for unit tests contracts

15

slide-32
SLIDE 32

DSSL2 in a nutshell

  • strict/eager, untyped, dynamically checked
  • structs (not dictionaries)
  • fjxed-sized arrays
  • classes and interfaces
  • built-in support for unit tests

contracts

15

slide-33
SLIDE 33

DSSL2 in a nutshell

  • strict/eager, untyped, dynamically checked
  • structs (not dictionaries)
  • fjxed-sized arrays
  • classes and interfaces
  • built-in support for unit tests
  • contracts

15

slide-34
SLIDE 34

A DSSL2 example (1/3)

interface STACK: def push(self, element) def pop(self) def empty?(self) def full?(self)

16

slide-35
SLIDE 35

A DSSL2 example (2/3)

class VecStack (STACK): let _data let _len def __init__(self, capacity): self._data = [False; capacity] self._len = 0 def empty?(self): self._len == 0 def full?(self): self._len == self._data.len()

17

slide-36
SLIDE 36

A DSSL2 example (3/3)

def push(self, element): if self.full?(): error('VecStack.push: full') self._data[self._len] = element self._len = self._len + 1 def pop(self): if self.empty?(): error('VecStack.pop: empty') self._len = self._len - 1 let result = self._data[self._len] self._data[self._len] = False result test 'VecStack': let s = VecStack(8) s.push('hello') assert_eq s.pop(), 'hello'

18

slide-37
SLIDE 37

How does it work?

slide-38
SLIDE 38

Implementation of DSSL2

It’s a Racket #lang:

  • Run-time system for free
  • IDE with syntax coloring and renaming for “free”
  • A nice documentation system

20

slide-39
SLIDE 39

Custom reader

It has a custom reader, written using parser-tools/lex:

[#\λ (token-LAMBDA)] ["True" (token-LITERAL #t)] ["False" (token-LITERAL #f)] ["def" (token-DEF)]

And parser-tools/yacc:

(<expr6> [(<expr6> OP6 <expr7>) (loc/2 (list $2 $1 $3))] [(<expr7>) $1])

21

slide-40
SLIDE 40

Custom reader

It has a custom reader, written using parser-tools/lex:

[#\λ (token-LAMBDA)] ["True" (token-LITERAL #t)] ["False" (token-LITERAL #f)] ["def" (token-DEF)]

And parser-tools/yacc:

(<expr6> [(<expr6> OP6 <expr7>) (loc/2 (list $2 $1 $3))] [(<expr7>) $1])

21

slide-41
SLIDE 41

A bunch of macros

(define-syntax-rule (dssl-while test expr ...) (let/ec break-f (let loop () (define (continue-f) (loop) (break-f (void))) (syntax-parameterize ([dssl-break (syntax-rules () [(_) (break-f (void))])] [dssl-continue (syntax-rules () [(_) (continue-f)])]) (when test (dssl-begin expr ...) (loop))))))

22

slide-42
SLIDE 42

Implementation diffjculties: symbols

(define (locate/symbol sym pos) (let ([port (open-input-string (format "~s" sym))]) (port-count-lines! port) (set-port-next-location! port (position-line pos) (position-col pos) (position-offset pos)) (read-syntax src port)))

23

slide-43
SLIDE 43

Implementation diffjculties: documentation

24

slide-44
SLIDE 44

Implementation diffjculties: documentation

24

slide-45
SLIDE 45

Implementation diffjculties: documentation

24

slide-46
SLIDE 46

Was it worth it?

slide-47
SLIDE 47

Pros

Students seem to pick it up easily—no complaints I don’t get badly indented code They can’t copy code ofg the internet

26

slide-48
SLIDE 48

Pros

  • Students seem to pick it up easily—no complaints

I don’t get badly indented code They can’t copy code ofg the internet

26

slide-49
SLIDE 49

Pros

  • Students seem to pick it up easily—no complaints
  • I don’t get badly indented code

They can’t copy code ofg the internet

26

slide-50
SLIDE 50

Pros

  • Students seem to pick it up easily—no complaints
  • I don’t get badly indented code
  • They can’t copy code ofg the internet

26

slide-51
SLIDE 51

Cons

I have a language to maintain It might be better for them to get better at C++ or learn Java

27

slide-52
SLIDE 52

Cons

  • I have a language to maintain

It might be better for them to get better at C++ or learn Java

27

slide-53
SLIDE 53

Cons

  • I have a language to maintain
  • It might be better for them to get better at C++ or learn Java

27

slide-54
SLIDE 54

Thank you