⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mce-extension.scm

📁 用JAVA实现的小的学生管理系统.JAVA与数据库的结合使用.
💻 SCM
字号:
;##################################################
; GdI 1/ICS 1 WS 04/05
; Uebung/Exercise 13 - Aufgabe/Task 4
;##################################################

;##################################################
; Load scheme interpreter
(load "mce.scm")

;##################################################
; Redefine eval function for registering special 
; forms.
(define (eval exp env)
  (cond ((self-evaluating? exp) exp)
        ((variable? exp) (lookup-variable-value exp env))
        ((quoted? exp) (text-of-quotation exp))
        ((assignment? exp) (eval-assignment exp env))
        ((definition? exp) (eval-definition exp env))
        
        ; ###############
        ; add and, or, let special forms here:
        ;;;; solution
        ((and? exp) (eval-and exp env))
        ((or? exp) (eval-or exp env))
        ((let? exp) (eval (let->combination exp env) env)) ; eval could be maintained in let->combination
        ;;;; end-solution
        ; ##############
        
        ((if? exp) (eval-if exp env))
        ((lambda? exp)
         (make-procedure (lambda-parameters exp)
                         (lambda-body exp)
                         env))
        ((begin? exp) 
         (eval-sequence (begin-actions exp) env))
        ((cond? exp) (eval (cond->if exp) env))
        ((application? exp)
         (apply (eval (operator exp) env)
                (list-of-values (operands exp) env)))
        (else
         (error "Unknown expression type -- EVAL" exp))))


;##################################################
; Please add here Definitions for:
; and?, or?,let?

;########### and special form ###########
;;;; solution
;condition
(define (and? exp) (tagged-list? exp 'and))  
;selector 
(define (and-exp exp) 
   (if (null? (cdr exp))  ; gets next and-expression
       ()
       (cadr exp)))

;constructor
(define (make-and . exprs)
    (cons 'and exprs))

;evaluation
(define (eval-and exp env) (begin 	
 (if (null? (and-exp exp)) true
  (if (true? (eval (and-exp exp) env)) 
      (eval-and (cdr exp) env)
      false))))

;######### or special form #############
;condition
(define (or? exp) (tagged-list? exp 'or))

;selector
(define (or-exp exp) 
 (if (null? (cdr exp))  ; gets next and-expression
  ()
  (cadr exp)))

;constructor 
(define (make-or . exprs)
 (cons 'or exprs))

;evaluation  
(define (eval-or exp env) 
 (if (null? (or-exp exp)) false
  (if (true? (eval (or-exp exp) env)) 
   true           
   (eval-or (cdr exp) env))))			

;######## let derived expression ########

	
;selectors
(define (let? exp) (tagged-list? exp 'let))
(define (let-bindings exp) (cadr exp))
(define (let-body exp) (cddr exp))
    
(define (let-var binding) (car binding))
(define (let-val binding) (cadr binding))
		
;constructor
(define (make-combination operator operands) (cons operator operands))
		
;transformation
(define (let->combination exp env) 
  (let ((bindings (let-bindings exp)))
    (make-combination (make-lambda (map let-var bindings)
                                   (let-body exp))
                      (map let-val bindings))))		
;;;; end-solution  
   
;###############################################

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -