Code: Select all
(setq var "b")
(apply append '("a" var)) ;; I believe the result will be "ab", but what I get is error message.
Code: Select all
(setq var "b")
(append "a" var);; -> "ab"
Code: Select all
(setq var "b")
(apply append '("a" var)) ;; I believe the result will be "ab", but what I get is error message.
Code: Select all
(setq var "b")
(append "a" var);; -> "ab"
Code: Select all
> (setq var "b")
"b"
> (apply append '("a" var)) ;; I believe the result will be "ab", but what I get is error message.
ERR: string expected in function append : 'var
Code: Select all
> '("a" var)
("a" var)
> (list '"a" 'var)
("a" var)
Code: Select all
> (apply append '("a" var))
ERR: string expected in function append : 'var
> (apply append (list '"a" 'var))
ERR: string expected in function append : 'var
Code: Select all
> (apply append (list "a" var))
"ab"
The short answer is: because the quote prevents it from getting evaluated, as in:The symbol 'var which is passed to "append" has been binded to "b", why is the evaluator not able to see it?
Code: Select all
> (setq var "b")
"b"
> 'var
var
> var
"b"
Code: Select all
> (quote var)
var
Code: Select all
> (eval (quote var))
"b"
All the lisps that I know of have this same behavior. For example, take a Scheme:And is this a mechanism from "lisp" or from "newlisp"?
Code: Select all
$ guile
guile> (define val "b")
guile> 'val
val
guile> (quote val)
val
guile> val
"b"
guile> (string-append "a" val)
"ab"
guile> (apply string-append '("a" val))
Backtrace:
In standard input:
6: 0* [apply #<primitive-procedure string-append> ("a" {val})]
In unknown file:
?: 1 [string-append]
?: 2* [string-append "a" {val}]
ERROR: In procedure string-append:
ERROR: Wrong type (expecting string): val
ABORT: (wrong-type-arg)
guile> (apply string-append (list "a" val))
"ab"
Code: Select all
*** Welcome to IELM *** Type (describe-mode) for help.
ELISP> (setq val "b")
"b"
ELISP> 'val
val
ELISP> (quote val)
val
ELISP> val
"b"
ELISP> (concat "a" val)
"ab"
ELISP> (apply #'concat '("a" val))
*** Eval error *** Wrong type argument: sequencep, val
ELISP> (apply #'concat (list "a" val))
"ab"