How to determine if a variable's value is a symbol associated with a procedure in a Schema?

I am familiar with Common Lisp and trying to learn some schemas, so I was trying to figure out how to use the Scheme for the things that I usually code in Common Lisp.

There is one in Common Lisp fboundpthat tells me whether a character (variable value) is associated with a function. So, I would do the following:

(let ((s (read)))
  (if (fboundp s)
      (apply (symbol-function s) args)
      (error ...)))

Is this possible in the diagram? I tried to find this in the R6RS specification, but did not find anything like it.

+3
source share
2 answers

This way?

  • check if this is a symbol
  • rate character using EVALto get its value
  • , PROCEDURE?
+5

, Common Lisp. , , procedure?:

(if (procedure? s) (do-something-with s) (do-something-else))

, , - , Lisp //plist.

- :

(define function-table (list `(car ,car) `(cdr ,cdr) `(cons ,cons) `(display ,display)))

(let* ((s (read))
       (f (cond ((assq s function-table) => cadr)
                (else (error "undefined function")))))
    (apply f args))

i.e., "" . , "" .

+4

Source: https://habr.com/ru/post/1718165/


All Articles