[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[plt-scheme] syntax rules



  i am attempting to learn how to define syntax's in scheme. i decided
to try to make a toy type system as my first try. the problem i'm having
is that each identifier in my lambda needs to be put in two different
places (the assertion and the parameter) and i can't seem to do that
with a recursive syntax. also my attempt seems to be currying the functions
so it takes one paramter at a time. i can see how it does that but i'm
not sure how to do it correctly. also there is a shortage of syntax-rules
docs on the web, in help-desk, the r5r and in the ansi scheme book. does
anyone know of a place to read up on this?

my problem:
expand this
(type-lambda ((nunber? foo) (number? bar) (string? baz) un-typed-param)
  (if (= foo bar)
      baz
      un-typed-param))
to this
(lambda (foo bar baz un-typed-param)
  (type-assert number? foo)
  (type-assert number? bar)
  (type-assert string? baz)
  (if (= foo bar)
      baz
      un-typed-param))
i also very simply define
(define type-assert
  (lambda (typep value)
    (if (typep value)
      (void)
      (raise-type-exeption "bad type") ;or whatever it says in help-desk
    )))
this is my attempt
(define-syntax type-lambda
  (syntax-rules ()
    ((_ ((type var) var2 ...) exp1 ...)
     (lambda (var)
       (type-assert type var)
       (type-lambda (var2 ... ) exp1 ...)))
    ((_ (var var2 ...) exp1 ...)
     (lambda (var)
       (type-lambda (var2 ...) exp1 ...)))
    ((_ () exp1 ...)
     (lambda ()
       exp1 ...))

just a note i mentioned this to robby findler of the plt who's making a
sophisticated contract system and i know there are ways to do this but
what i'm really trying to do here is learn define syntax.
thanks for the help
-mike