美文网首页
2021-07-26 Chez-Scheme building

2021-07-26 Chez-Scheme building

作者: yango3 | 来源:发表于2021-07-26 19:20 被阅读0次

source codes:

./main.ss
./lib/fibonacci.ss
./lib/fibonacciex.ss

main.ss

(import (chezscheme)                                                           
        (lib fibonacci)                                                        
        (lib fibonacciex))                                                     
                                                                               
(display "What's up?\n")                                                       
                                                                               
(printf "~a~%" (fib 5))                                                        
                                                                                                                                                 
(define main                                                                   
  (lambda ()                                                                   
    (printf "This is the main procedure~%")                                    
    (printf "First, print fib(10) = ~a~%" (fib 10))                            
    (printf "First 11 Fibonacci numbers: ~a~%" (fib-list 11))))                
                                                                               
;;; Initialize the program                                                     
(define initialize                                                             
  (lambda fns                                                                  
    (printf "This procedures initializes the program.~%")))                    
                                                                               
;;; This will be called by the boot-file                                       
(scheme-start                                                                  
  (lambda fns                                                                  
    (initialize fns)                                                           
    (main)))                                                                   
                                                                               
(main) 

fibonacci.ss

;;; fibonacci.ss                                                               
(library (lib fibonacci)                                                       
  (export fib)                                                                 
  (import (rnrs))                                                              
                                                                               
  (define fib                                                                  
    (lambda (n)                                                                
      (if (<= n 2)                                                             
          1                                                                    
          (+ (fib (- n 2)) (fib (- n 1))))))                                   
                                                                               
  )  

fibonacciex.ss

(library (lib fibonacciex)                                                     
  (export fib-list)                                                            
  (import (rnrs)                                                               
          (lib fibonacci))                                                     
                                                                               
  (define fib-list                                                             
    (lambda (n)                                                                
      (if (zero? n)                                                            
          '()                                                                  
          (cons (fib n)                                                        
                (fib-list (- n 1))))))                                         
  )  

Compile

(compile-imported-libraries #t)
(generate-wpo-files #t)
(compile-program "./main.ss")
(compile-whole-program "./main.wpo" "./main")

Run

chez --program main

相关文章

网友评论

      本文标题:2021-07-26 Chez-Scheme building

      本文链接:https://www.haomeiwen.com/subject/kdmgmltx.html