方案功能定义

时间:2019-01-19 16:26:54

标签: scheme lisp mit-scheme

我在业余时间一直在阅读“ The Little Schemer”,并尝试尝试语法,但遇到了一个语法问题,无法解决。我有一个看起来像这样的脚本:

;;;; Chapter 2 examples
;;; Note: run this file with 'mit-scheme --quiet < c2.scm'

;; You can define variables using the "define" function
(define my-favorite-number 13)

;; You can define strings using double-quotes
(define my-favorite-color "green")

;; you define functions with lambdas.  Functions auto return their last line
(define my-favorites
  (lambda (color number)
    (string-append "My favorite color is " color " and my favorite number is " number)))

; display will print
(display
 (my-favorites my-favorite-color (number->string my-favorite-number)))

; and newline prints a newline
(newline)

这在运行时效果很好。

在此之下,我还有更多:

(define greet
  (lambda (name)
    (string-append "Hello, " name)))

(display (greet "World"))

运行此文件时,我似乎无法打印“ Hello,World”。第一个显示效果不错,但是第二个显示却什么也没做,我无法解释原因。起初,我认为这可能与scheme在交互式环境中的正常运行方式有关,因此我删除了第一段代码,但仍然没有任何反应。

如果我在交互式会话中加载文件,则“ greet”功能可以完美运行,因此我认为显示功能一定有点奇怪。

谁能解释为什么我的第一个显示器可以工作,而我的第二个显示器却不能工作?

Here is a github link to the exact file

0 个答案:

没有答案
相关问题