css.scm 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. (def (mycss)
  2. (css
  3. (class 'foo
  4. margin: (* (px 21) 2))))
  5. (both-times
  6. (def (fact n)
  7. (warn "fact" n)
  8. (if (zero? n) 1
  9. (* n (fact (dec n))))))
  10. (defmacro (FACT n)
  11. (assert* natural0? n
  12. (lambda (n)
  13. (fact n))))
  14. (def f
  15. (lambda (m) (+ (FACT 10) m)))
  16. ;; (let ..binds.. ..expr..)
  17. (defmacro (the expr _where binds)
  18. (if (eq? (source-code _where) where:)
  19. `(let ,binds ,expr)
  20. (raise-source-error _where "invalid keyword")))
  21. '(def f*
  22. (the (lambda (m) (+ f10 m))
  23. where:
  24. (f10 (fact 10))))
  25. '(define-syntax kwote
  26. (syntax-rules ()
  27. ((kwote exp)
  28. (quote exp))))
  29. '(kwote (foo . bar))
  30. (defmacro (kwote exp)
  31. (warn "kwote" exp)
  32. `(quote ,exp))
  33. ;; (equal? (foo (+ 10 20))
  34. ;; '((+ 10 20) 30))
  35. (defmacro (foo expr)
  36. (def v `(quote ,expr))
  37. (warn "v=" (cj-desourcify v))
  38. `(list ,v `(list "The result is " ,,expr)))
  39. (def (t)
  40. (foo (+ (error "nope" 10) 20)))
  41. '(defmacro (m+ [number? a] [number? b])
  42. `(+ ,a ,b))
  43. ;; *** ERROR IN #<procedure #20>, "/home/chris/gac/css.scm"@53.1 -- a does not match number?: (source* 1 "css.scm" 57 10)
  44. (defmacro (m+ a b)
  45. (assert* number? a)
  46. (assert* number? b)
  47. `(+ ,a ,b))
  48. '(def (t2)
  49. (m+ 1 "hello"))
  50. '() ;; what did we want ?
  51. ;;(derivative (* x x) x) (* 2 x)