---
title: "scheme或者guile尾递归算阶乘"
author: "polyahu"
date: "2013-02-08T22:03:01Z"
tags: []
categories: ["编程语言"]
slug: "scheme-guile"
draft: false
lastmod: "2013-02-08T22:03:01Z"
id: 1797534
url: "https://polyahu.iteye.com/blog/1797534"
---

一段guile脚本程序，基本就是打印一个hello world，然后算个阶乘。


```bash

#!/usr/bin/guile \
-s 
!#
(begin 
  (newline)
  (display "hello world")
  (newline))

(define (factorial n)
  (fact-iter 1 1 n))

(define (fact-iter product counter max-count)
  (if (> counter max-count)
      product
      (fact-iter (* counter product)
                 (+ counter 1)
                 max-count)))

(display (factorial 100))
(newline)
(newline)


```