我定义了一个名为msl
#lang plai-typed
(define-type msl
[msl-num (n : number)]
[msl-add (l : msl) (r : msl)]
[msl-mul (l : msl) (r : msl)]
[msl-sub (l : msl) (r : msl)]
[msl-pow (l : msl) (r : msl)]
[msl-error (s : string)]
)
(define(** u t)
(cond
((= u 1) t)
(else
(* t(**(sub1 u) t)))))
我有一个解析器函数可以转换s-expression
为msl
(define (parse [s : s-expression]) : msl
(cond
[(s-exp-number? s) (msl-num (s-exp->number s))]
[(s-exp-list? s)
(let ([sl (s-exp->list s)])
(case (s-exp->symbol (first sl))
[(+) (msl-add (parse (second sl)) (parse (third sl)))]
[(*) (msl-mul (parse (second sl)) (parse (third sl)))]
[ (-) (msl-sub (parse (second sl)) (parse (third sl)))]
[ (**) (msl-pow (parse (second sl)) (parse (third sl))) ]
[else (error 'parse "invalid list input")]))]
[else (error 'parse "invalid input")]))
我的问题是:如何将msl
表达式转换为s-expression
这样?我是这个主题的初学者