最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

what is the proper way to evaluate LispScheme in emacs - Stack Overflow

programmeradmin0浏览0评论

I try this LISP snippet from the Structure and Interpretation book

(define (a-plus-abs-b a b)
  ((if (> b 0) + -) a b))

in emacs by C-x C-e, or by evaluating the whole buffer. either way and get the backtrace:

Debugger entered--Lisp error: (void-function define)
  (define (a-plus-abs-b a b) ((if (> b 0) + -) a b))
  (progn (define (a-plus-abs-b a b) ((if (> b 0) + -) a b)))
  eval((progn (define (a-plus-abs-b a b) ((if (> b 0) + -) a b))) t)
  elisp--eval-last-sexp(nil)
  eval-last-sexp(nil)
  funcall-interactively(eval-last-sexp nil)
  call-interactively(eval-last-sexp nil nil)
  command-execute(eval-last-sexp)

If I try {evaluate-defun} I get a different error: symbol's definition is void: define

what is the proper way to evaluate the snippet? should I be using sth outside emacs?

I try this LISP snippet from the Structure and Interpretation book

(define (a-plus-abs-b a b)
  ((if (> b 0) + -) a b))

in emacs by C-x C-e, or by evaluating the whole buffer. either way and get the backtrace:

Debugger entered--Lisp error: (void-function define)
  (define (a-plus-abs-b a b) ((if (> b 0) + -) a b))
  (progn (define (a-plus-abs-b a b) ((if (> b 0) + -) a b)))
  eval((progn (define (a-plus-abs-b a b) ((if (> b 0) + -) a b))) t)
  elisp--eval-last-sexp(nil)
  eval-last-sexp(nil)
  funcall-interactively(eval-last-sexp nil)
  call-interactively(eval-last-sexp nil nil)
  command-execute(eval-last-sexp)

If I try {evaluate-defun} I get a different error: symbol's definition is void: define

what is the proper way to evaluate the snippet? should I be using sth outside emacs?

Share Improve this question edited Feb 3 at 18:39 Stephen asked Feb 2 at 18:25 StephenStephen 6081 gold badge5 silver badges16 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

Either way of executing Emacs Lisp works.

What the issue here is that SICP uses a Lisp called Scheme. This is a language that differs from Emacs Lisp. The main difference is that Scheme is a Lisp-1 and so a variable and a function can't have the same name and so define is used to create both. Whilst Emacs Lisp is a Lisp-2 and you can have a function and a variable with the same name, so defun to define a function and defvar for a variable - or usually setq to set a variables value and also define it if required.

If you want to try SICP you need to get a Scheme interpreter or possibly Racket and use its Scheme language mode.

发布评论

评论列表(0)

  1. 暂无评论