這個作業與 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)))]))
uj5u.com熱心網友回復:
它是一個識別符號,而不是由箭頭分隔的兩個識別符號——方案識別符號不像許多其他語言一樣限于字母數字字符和下劃線。
從型別 A 到型別 B 的轉換函式的常規名稱是A->B,因此racketlist->mupllist是一個合理的名稱,因為它將 Racket 串列轉換為 mupl 串列。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/329391.html
上一篇:如何為執行行程分配處理器
