jon rafkind
play

Jon Rafkind 1 Honu is 2 Honu is Macros are 3 Infix syntax - PowerPoint PPT Presentation

Jon Rafkind 1 Honu is 2 Honu is Macros are 3 Infix syntax #lang honu function loadImages(path, files){ binary_operator + 1 'left string_append [make_bitmap(path + file): file = files] } loadImages(root, ["a.png",


  1. Jon Rafkind 1

  2. Honu is 2

  3. Honu is Macros are 3

  4. Infix syntax #lang honu function loadImages(path, files){ binary_operator + 1 'left string_append [make_bitmap(path + file): file = files] } loadImages(root, ["a.png", "b.png", "c.png"]) 4

  5. XML as a macro #lang honu macro xml ... var data = xml <record> <name> { get_name(person) } </name> <age> { get_age(person) } </age> <address> { get_address(person) } </address> </record> 5

  6. Racket parsing characters s-expression program Read Expand () (let ([x 5]) (+ x 5)) let () () [] + x 5 x 5 6

  7. Racket parsing characters s-expression program Read Expand () (let ([x 5]) (+ x 5)) let () () [] + x 5 x 5 Honu parsing characters s-expression terms program Read Enforest Expand unparsed terms () + f(x) * 2 + 1 f () * 2 + 1 * 1 x f (x) 2 7

  8. Honu expansion Enforest function c_to_f(temp){ temp * 9/5 + 32 } printf("temperature ~a", c_to_f(40)) 8

  9. Honu expansion Enforest function c_to_f(temp){ temp * 9/5 + 32 } printf("temperature ~a", c_to_f(40)) Expand <function>, printf("temperature ~a", c_to_f(40)) 9

  10. Honu expansion Enforest function c_to_f(temp){ temp * 9/5 + 32 } printf("temperature ~a", c_to_f(40)) Expand <function>, printf("temperature ~a", c_to_f(40)) Enforest printf("temperature ~a", c_to_f(40)) 10

  11. Honu expansion Enforest function c_to_f(temp){ temp * 9/5 + 32 } printf("temperature ~a", c_to_f(40)) Expand <function>, printf("temperature ~a", c_to_f(40)) Enforest printf("temperature ~a", c_to_f(40)) Done <function>, <call> 11

  12. Honu grammar Expression := <literal> | <identifier> | <unary> <expression> | <expression> <unary> | <expression> <binary> <expression> | <expression> ( <expression, ... ) | ( <expression> ) | <expression> [ <expression> ] | [ <expression> , ... ] | [ <expression> : <expresion> = <expression> ] | { <sequence> ... } | <identifier> <term> ... 12

  13. Honu grammar Expression := <literal> | <identifier> | <unary> <expression> Function call | <expression> <unary> | <expression> <binary> <expression> | <expression> ( <expression, ... ) | ( <expression> ) List comprehension | <expression> [ <expression> ] | [ <expression> , ... ] | [ <expression> : <expresion> = <expression> ] | { <sequence> ... } | <identifier> <term> ... 13

  14. Honu grammar Expression := <literal> | <identifier> Operators | <unary> <expression> | <expression> <unary> | <expression> <binary> <expression> | <expression> ( <expression, ... ) | ( <expression> ) | <expression> [ <expression> ] | [ <expression> , ... ] Macro | [ <expression> : <expresion> = <expression> ] | { <sequence> ... } | <identifier> <term> ... 14

  15. Macros Definition macro name(literal ...){ pattern ... }{ body ... } Use macro withCloser(=){name:id = e:expression { body ... }}{ syntax({ var name = e body ... name.close() }) } In action withCloser d = getDatabase() { ... } printf("Done") 15

  16. Patterns macro withCloser(){ name:id = e:expression { body ... } }{ syntax({ var name = e body ... name.close() }) } 16

  17. Patterns Identifier pattern Expression pattern macro withCloser(){ name:id = e:expression { body ... id expression } }{ syntax({ var name = e body ... name.close() }) } 17

  18. Patterns Identifier pattern Expression pattern macro withCloser(){ name:id = e:expression { body ... id expression } }{ syntax({ var name = e body ... name.close() }) } expression = enforest(terms) 18

  19. Patterns pattern letvar(=){name:id = expr:expression} 19

  20. Patterns pattern letvar(=){name:id = expr:expression} Definition macro let(){ v:letvar ... { body ... } }{ /* ..implementation.. */ } 20

  21. Patterns pattern letvar(=){name:id = expr:expression} Definition macro let(){ v:letvar ... { body ... } }{ syntax({ $ var v_name = v_expr $ ... body ... }) } Use let day = getDay() month = getMonth() { printf("~a\n", is_christmas(day, month)) } 21

  22. Racket Honu Bridge (require honu/core/api honu) (define-honu-macro xml (lambda (stx) )) 22

  23. Racket Honu Bridge (require honu/core/api honu) (define-honu-macro xml (lambda (stx) (syntax-parse stx [(..stuff.. . rest) (values (racket-syntax ..new-stx..) #'rest #t)]))) 23

  24. Operators Definition binary_operator logbase 4 'left function(left right){ log(left) / log(right) } Use 2 * 12 logbase 4 + 8 24

  25. Infix enforest macro call(){ object:id . method:id(arg:expression ...)}{} 1 + call plane.passengers() * 5 25

  26. Infix enforest macro call(){ object:id . method:id(arg:expression ...)}{} 1 + call plane.passengers() * 5 1 Parse State 26

  27. Infix enforest macro call(){ object:id . method:id(arg:expression ...)}{} 1 + call plane.passengers() * 5 1 + Parse State a = function (right){ mkOp(+, 1, right) } 27

  28. Infix enforest macro call(){ object:id . method:id(arg:expression ...)}{} 1 + call plane.passengers() * 5 1 + call plane.passengers() Parse State a = function (right){ mkOp(+, 1, right) } 28

  29. Infix enforest macro call(){ object:id . method:id(arg:expression ...)}{} 1 + call plane.passengers() * 5 1 + call plane.passengers() * Parse State a = function (right){ mkOp(+, 1, right) } b = function (right){ mkOp(*, <call>, right) } 29

  30. Infix enforest macro call(){ object:id . method:id(arg:expression ...)}{} 1 + call plane.passengers() * 5 1 + call plane.passengers() * 5 Parse State a = function (right){ mkOp(+, 1, right) } b = function (right){ mkOp(*, <call>, right) } a(b(5)) 30

  31. #lang honu Thank you 31

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend