这个函数中的箭头是做什么的?
what is the arrow doing in this function?
这项作业与 mupl(一种编造的编程语言)有关。多个程序
通过使用此处结构定义的构造函数直接在 Racket 中编写:
(provide (all-defined-out)) ;; so we can put tests in a second file
;; definition of structures for MUPL programs - Do NOT change
(struct var (string) #:transparent) ;; a variable, e.g., (var "foo")
(struct int (num) #:transparent) ;; a constant number, e.g., (int 17)
(struct add (e1 e2) #:transparent) ;; add two expressions
(struct ifgreater (e1 e2 e3 e4) #:transparent) ;; if e1 > e2 then e3 else e4
(struct fun (nameopt formal body) #:transparent) ;; a recursive(?) 1-argument function
(struct call (funexp actual) #:transparent) ;; function call
(struct mlet (var e body) #:transparent) ;; a local binding (let var = e in body)
(struct apair (e1 e2) #:transparent) ;; make a new pair
(struct fst (e) #:transparent) ;; get first part of a pair
(struct snd (e) #:transparent) ;; get second part of a pair
(struct aunit () #:transparent) ;; unit value -- good for ending a list
(struct isaunit (e) #:transparent) ;; evaluate to 1 if e is unit else 0
;; a closure is not in "source" programs but /is/ a MUPL value; it is what functions evaluate to
(struct closure (env fun) #:transparent)
这是我要问的函数
(define (racketlist->mupllist e)
(cond [(null? e) (aunit)]
[#t (apair (car e) (racketlist->mupllist (cdr e)))]))
它是一个标识符,而不是用箭头分隔的两个标识符 – 方案标识符不像许多其他语言那样仅限于字母数字字符和下划线。
从类型A到类型B的转换函数的常规名称是A->B
,因此racketlist->mupllist
是一个合理的名称,因为它将Racket列表转换为mupl列表。
这项作业与 mupl(一种编造的编程语言)有关。多个程序 通过使用此处结构定义的构造函数直接在 Racket 中编写:
(provide (all-defined-out)) ;; so we can put tests in a second file
;; definition of structures for MUPL programs - Do NOT change
(struct var (string) #:transparent) ;; a variable, e.g., (var "foo")
(struct int (num) #:transparent) ;; a constant number, e.g., (int 17)
(struct add (e1 e2) #:transparent) ;; add two expressions
(struct ifgreater (e1 e2 e3 e4) #:transparent) ;; if e1 > e2 then e3 else e4
(struct fun (nameopt formal body) #:transparent) ;; a recursive(?) 1-argument function
(struct call (funexp actual) #:transparent) ;; function call
(struct mlet (var e body) #:transparent) ;; a local binding (let var = e in body)
(struct apair (e1 e2) #:transparent) ;; make a new pair
(struct fst (e) #:transparent) ;; get first part of a pair
(struct snd (e) #:transparent) ;; get second part of a pair
(struct aunit () #:transparent) ;; unit value -- good for ending a list
(struct isaunit (e) #:transparent) ;; evaluate to 1 if e is unit else 0
;; a closure is not in "source" programs but /is/ a MUPL value; it is what functions evaluate to
(struct closure (env fun) #:transparent)
这是我要问的函数
(define (racketlist->mupllist e)
(cond [(null? e) (aunit)]
[#t (apair (car e) (racketlist->mupllist (cdr e)))]))
它是一个标识符,而不是用箭头分隔的两个标识符 – 方案标识符不像许多其他语言那样仅限于字母数字字符和下划线。
从类型A到类型B的转换函数的常规名称是A->B
,因此racketlist->mupllist
是一个合理的名称,因为它将Racket列表转换为mupl列表。