Back
eval (clj)
(source)function
(eval form)
Evaluates the form data structure (not text!) and returns the result.
Examples
clojure
(deftest division
(is (= clojure.core// /))
(binding [*ns* *ns*]
(eval '(do (ns foo
(:require [clojure.core :as bar])
(:use [clojure.test]))
(is (= clojure.core// bar//))))))
(eval (-> "^{:line 42 :column 99} (defn explicit-line-numbering [])" str->lnpr read))
(is (= {:line 42 :column 99}
(-> 'explicit-line-numbering resolve meta (select-keys [:line :column])))))
dundalek/closh
(defmacro def-eval []
(if (System/getenv "__CLOSH_USE_SCI_EVAL__")
`(do (require 'closh.zero.utils.sci)
(def ~'eval closh.zero.utils.sci/sci-eval))
`(def ~'eval clojure.core/eval)))
(def-eval)
(defmacro eval-closh-requires []
(when-not (System/getenv "__CLOSH_USE_SCI_EVAL__")
`(eval closh.zero.env/*closh-environment-requires*)))
hraberg/deuce
(ns deuce.emacs.eval
(:use [deuce.emacs-lisp :only (defun defvar)])
(:require [clojure.core :as c]
[deuce.emacs.alloc :as alloc]
[deuce.emacs.data :as data]
[deuce.emacs-lisp.cons :as cons]
[deuce.emacs-lisp :as el])
(:import [clojure.lang Var])
(:refer-clojure :exclude [apply eval macroexpand]))
(defvar debugger nil
"Function to call to invoke debugger.
If due to frame exit, args are `exit' and the value being returned;
this function's value will be returned instead of that.
If due to error, args are `error' and a list of the args to `signal'.
If due to `apply' or `funcall' entry, one arg, `lambda'.
If due to `eval' entry, one arg, t.")
(defvar max-lisp-eval-depth nil
"*Limit on depth in `eval', `apply' and `funcall' before error.
(defvar quit-flag nil
"Non-nil causes `eval' to abort, unless `inhibit-quit' is non-nil.
If the value is t, that means do an ordinary quit.
If the value equals `throw-on-input', that means quit by throwing
to the tag specified in `throw-on-input'; it's for handling `while-no-input'.
Typing C-g sets `quit-flag' to t, regardless of `inhibit-quit',
but `inhibit-quit' non-nil prevents anything from taking notice of that.")
(defvar debug-on-next-call nil
"Non-nil means enter debugger before next `eval', `apply' or `funcall'.")
(defvar debug-on-error nil
"*Non-nil means enter debugger if an error is signaled.
Does not apply to errors handled by `condition-case' or those
matched by `debug-ignored-errors'.
If the value is a list, an error only means to enter the debugger
if one of its condition symbols appears in the list.
When you evaluate an expression interactively, this variable
is temporarily non-nil if `eval-expression-debug-on-error' is non-nil.
The command `toggle-debug-on-error' toggles this.
See also the variable `debug-on-quit'.
(declare apply eval funcall)
(defun apply (function &rest arguments)
"Call FUNCTION with our remaining args, using our last arg as list of args.
Then return the value FUNCTION returns.
Thus, (apply '+ 1 2 '(3 4)) returns 10."
(let [rest (last arguments)]
(el/check-type 'listp rest)
(c/apply (cond (symbol? function) (data/symbol-function function)
(data/listp function) (eval function)
:else function) (c/apply alloc/list (concat (butlast arguments) rest)))))
(defun eval (form &optional lexical)
"Evaluate FORM and return its value.
If LEXICAL is t, evaluate using lexical scoping."
(el/eval form lexical))
(defun backtrace-debug (level flag)
"Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG.
The debugger is entered when that frame exits, if the flag is non-nil."
)
(defun backtrace-frame (nframes)
"Return the function and arguments NFRAMES up from current execution point.
If that frame has not evaluated the arguments yet (or is a special form),
the value is (nil FUNCTION ARG-FORMS...).
If that frame has evaluated its arguments and called its function already,
the value is (t FUNCTION ARG-VALUES...).
A &rest arg is represented as the tail of the list ARG-VALUES.
FUNCTION is whatever was supplied as car of evaluated list,
or a lambda expression for macro calls.
If NFRAMES is more than the number of frames, the value is nil."
)
The second optional arg ENVIRONMENT specifies an environment of macro
definitions to shadow the loaded ones for use in file byte-compilation."
;; Not sure how this is supposed to work even after reading eval.c, attempts to mimic observed behavior.
;; It is used in conjunction with cl-macroexpand-all, and should not expand into "raw" Clojure.
(let [shadow (into {} (map #(vector (data/car %) (data/cdr %)) environment))
shadow #(shadow % (shadow (str %)))
unshadowed-form ((fn shadow-walker [form]
(if-let [expander (shadow form)]
(if (= '(true) (data/cdr-safe expander))
(cons (first (data/car expander))
(map #(list 'quote %) (rest (data/car expander))))
(expander form))
(if (and (seq? form)
(not= 'quote (first form)))
(cons/maybe-seq (map shadow-walker form))
form))) form)
expansion (if-let [m (and (seq? form) (-> (el/fun (first form)) meta))]
(if (and (:macro m) (= (the-ns 'deuce.emacs-lisp) (:ns m)))
unshadowed-form
(macroexpand-1 unshadowed-form))
unshadowed-form)]
;; Protect against eq check in cl-macroexpand-all
(if (= form expansion)
form
expansion)))
hraberg/deuce
(ns deuce.emacs.print
(:use [deuce.emacs-lisp :only (defun defvar)])
(:require [clojure.core :as c]
[clojure.string :as s]
[deuce.emacs.buffer :as buffer]
[deuce.emacs.data :as data]
[deuce.emacs.editfns :as editfns]
[deuce.emacs.fns :as fns])
(:refer-clojure :exclude [print]))
(defvar print-circle nil
"*Non-nil means print recursive structures using #N= and #N# syntax.
If nil, printing proceeds recursively and may lead to
`max-lisp-eval-depth' being exceeded or an error may occur:
\"Apparently circular structure being printed.\" Also see
`print-length' and `print-level'.
If non-nil, shared substructures anywhere in the structure are printed
with `#N=' before the first occurrence (in the order of the print
representation) and `#N#' in place of each subsequent occurrence,
where N is a positive decimal integer.")
(defvar print-level nil
"Maximum depth of list nesting to print before abbreviating.
A value of nil means no limit. See also `eval-expression-print-level'.")
(defvar print-length nil
"Maximum length of list to print before abbreviating.
A value of nil means no limit. See also `eval-expression-print-length'.")
typedclojure/typedclojure
(ns ^:no-doc typed.ann.clojure
"Type annotations for the base Clojure distribution."
#?(:cljs (:require-macros [typed.ann-macros.clojure :as macros]))
(:require [clojure.core :as cc]
[typed.clojure :as t]
#?(:clj [typed.ann-macros.clojure :as macros])
#?(:clj typed.ann.clojure.jvm) ;; jvm annotations
#?(:clj clojure.core.typed))
#?(:clj
(:import (clojure.lang PersistentHashSet PersistentList
APersistentMap #_IPersistentCollection
#_ITransientSet
IRef)
(java.util Comparator Collection))))
(macros/anns
#?@(:cljs [] :default [
;; Internal annotations
;clojure.core.typed.current-impl/*current-impl* t/Any
clojure.core.typed.current-impl/clojure t/Any
clojure.core.typed.current-impl/clojurescript t/Any
clojure.core.typed/ann* [t/Any t/Any t/Any :-> t/Any]
clojure.core.typed/untyped-var* [t/Any t/Any :-> t/Any]
clojure.core.typed/declare-names* [t/Any :-> t/Any]
clojure.core.typed/typed-deps* [t/Any :-> t/Any]
clojure.core.typed/warn-on-unannotated-vars* [:-> t/Any]
clojure.core.typed/ann-datatype* [t/Any t/Any t/Any t/Any :-> t/Any]
clojure.core.typed/ann-protocol* [t/Any t/Any t/Any :-> t/Any]
clojure.core.typed/ann-record* [t/Any t/Any t/Any t/Any :-> t/Any]
clojure.core.typed/ann-pdatatype* [t/Any t/Any t/Any t/Any :-> t/Any]
clojure.core.typed/declare-datatypes* [t/Any :-> t/Any]
clojure.core.typed/declare-protocols* [t/Any :-> t/Any]
clojure.core.typed/non-nil-return* [t/Any t/Any :-> t/Any]
clojure.core.typed/nilable-param* [t/Any t/Any :-> t/Any]
clojure.core.typed/override-constructor* [t/Any t/Any :-> t/Any]
clojure.core.typed/override-method* [t/Any t/Any :-> t/Any]
clojure.core.typed/typed-deps* [t/Any :-> t/Any]
clojure.core.typed/load-if-needed [:-> t/Any]
clojure.core.typed/*collect-on-eval* t/Any
])
#?@(:cljs [] :default [
clojure.main/demunge [t/Str :-> t/Str]
clojure.main/repl-prompt [:-> t/Any]
clojure.main/repl-read [t/Any t/Any :-> t/Any]
clojure.main/repl-caught [Throwable :-> t/Any]
clojure.main/repl-exception [Throwable :-> t/Any]
clojure.main/root-cause [Throwable :-> Exception]
clojure.main/repl [& :optional {:init [:-> t/Any]
:need-prompt [:-> t/Any]
:prompt [:-> t/Any]
:flush [:-> t/Any]
:read [t/Any t/Any :-> t/Any]
:eval [t/Any :-> t/Any]
:print [t/Any :-> t/Any]
:caught [Throwable :-> t/Any]}
:-> t/Any]
clojure.main/main [t/Any :* :-> t/Any]
clojure.main/load-script [t/Str :-> t/Any]
])
#?@(:cljs [] :default [
cc/*file* t/Str
])
cc/*command-line-args* (t/NilableNonEmptyASeq t/Str)
#?@(:cljs [
cc/*unchecked-if* t/Bool
cc/*unchecked-arrays* t/Bool
cc/*warn-on-infer* t/Bool
cc/enable-console-print! [:-> t/Any]
] :default [
cc/*warn-on-reflection* t/Bool
cc/*compile-path* t/Str
cc/*compile-files* t/Bool
cc/*unchecked-math* t/Bool
cc/*compiler-options* (t/Map t/Any t/Any)
cc/*in* java.io.Reader
cc/*out* java.io.Writer ;; FIXME cljs
cc/*err* java.io.Writer
cc/*repl* t/Any
])
cc/*flush-on-newline* t/Bool
cc/*print-meta* t/Bool
cc/*print-dup* t/Bool
cc/*print-readably* t/Bool
#?@(:cljs [] :default [
cc/*read-eval* (t/U ':unknown t/Bool)
])
cc/eval [t/Any :-> t/Any]
cc/rand-nth (t/All [x] [(t/U (t/Indexed x) (t/SequentialSeqable x)) :-> x])
typedclojure/typedclojure
(ns ^:typed/skip-from-repo-root clojure.core.typed.test.load-test
(:require [clojure.core.typed.load :as load]
[clojure.test :refer :all]))
;; ensures evaluation occurs
(deftest evaluation-test
(is (try (some-> (find-ns 'clojure.core.typed.test.typed-load.eval)
ns-name
remove-ns)
(load/typed-load1 "clojure/core/typed/test/typed_load/eval")
nil
(catch clojure.lang.ExceptionInfo e
(-> e ex-data :blame :file #{"clojure/core/typed/test/typed_load/eval.clj"})))))