Created
May 2, 2018 23:42
-
-
Save justinmeiners/390e1f96f9c3a215e0ef93b44935cf94 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (eval-html templ env) | |
(define (lookup-var key env) | |
(let ((pair (assoc key env))) | |
(if (pair? pair) | |
(cdr pair) | |
'()))) | |
(define (tag? templ) | |
(and (pair? templ) (symbol? (car templ)))) | |
(define (attr-list? templ) | |
(and (pair? templ) (pair? (car templ)))) | |
(define (eval-attr-list templ) | |
(cond ((null? templ) 'done) | |
((pair? (car templ)) | |
(let ((key (car (car templ))) | |
(val (cdr (car templ)))) | |
(display " ") | |
(display key) | |
(display "=\"") | |
(display val) | |
(display "\""))))) | |
(define (eval-tag templ) | |
(let ((tag (car templ)) | |
(tag-string (symbol->string (car templ)))) | |
(display "<") | |
(display tag-string) | |
(let ((next (cdr templ))) | |
(if (or (null? next) (not (attr-list? (car next)))) | |
(begin (display ">") (eval-list next)) | |
(begin (eval-attr-list (car next)) (display ">") (eval-list (cdr next))))) | |
(display "</") | |
(display tag-string) | |
(display ">"))) | |
(define (eval-list templ) | |
(cond ((null? templ) 'done) | |
((tag? templ) | |
(eval-tag templ)) | |
(else | |
(begin (eval (car templ)) (eval-list (cdr templ)))))) | |
(define (eval templ) | |
(cond | |
((list? templ) (eval-list templ)) | |
((string? templ) (display templ)) | |
(else (error templ)))) | |
(eval templ)) | |
(define template2 | |
'(ul | |
(for-each person (get list)) | |
(li (ref item name) (ref item age)))) | |
(define template | |
'(html | |
(head | |
(title "Plant o matic Web Page")) | |
(body ((bgcolor . "yellow")) | |
(h1 "Plant O matic") | |
(h3 ((align . "right")) "New automatic plant feeding and watering") | |
(p (font ((color . "green") | |
(face . "comic sans") | |
(size . 2)) | |
"Be the first in your neighborhood to own the plant-o-matic")) | |
(p ((align . "center")) | |
(font ((color . "#00FFFF") (face . "arial") (size 5))) "Don't Wait" | |
(hr ((color . "purple")))) | |
"this new " (b "product") " will save you " (u "time") ", " | |
(p (em "money") (br) "and will keep your plants" (i "alive"))))) | |
(eval-html template '(title . "Plant o matic Web Page")) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment