How to apply a symbol as a function in a schema?

Is there a way to apply + to (1 2 3)?

edit: I'm trying to say that the function that I get will be a symbol. Is there any way to apply this?

Thanks.

+5
source share
6 answers
(apply (eval '+) '(1 2 3))

Must do it.

+6
source

In R5RS you need

(apply (eval '+ (scheme-report-environment 5)) '(1 2 3))

The "fairly large" language in Dr. Scheme allows you to:

(apply (eval '+) '(1 2 3))
+4
source

How about apply? Use the + variable instead of the + symbol.

(apply + '(1 2 3))

R5rs

+1
source

;; This works the same as funcall in Common Lisp:
(define (funcall fun . args)
  (apply fun args))

(funcall + 1 2 3 4) => 10
(funcall (lambda (a b) (+ a b) 2 3) => 5
(funcall newline) => *prints newline*
(apply newline) => *ERROR*
(apply newline '()) => *prints newline*

Btw, what is the deal with this "syntax highlighting" ??

+1
source

In a Racket scheme, this will be

#lang scheme

(define ns (make-base-namespace))
(apply (eval '+ ns) '(1 2 3))
+1
source

What about the apply scheme

(apply + `(1 2 3)) => 6

Hope this was what you asked :)

-1
source

All Articles