lisp

Clojure: determine if a function exists

天涯浪子 提交于 2019-12-04 03:03:06
how can i know if a function name provided as string is callable or not in the current context? something like: (callable? "asdasd") ;; false (callable? "filter") ;; true thanks Hamza Yerlikaya You are looking for resolve, (resolve (symbol "asd")) returns nil (resolve (symbol "filter")) return #'clojure.core/filter To check if a var is a function (credit goes to @amalloy): (-> s symbol resolve deref ifn?) Chances are if you need this, you're doing something wrong, but... (defn callable? [s] (let [obj (try (eval (symbol s)) (catch Exception e))] (and obj (fn? obj)))) (defn callable? [name]

How to create an empty file by elisp?

ぐ巨炮叔叔 提交于 2019-12-04 02:53:06
I set an explicit file to customization created via the UI. It's named custom.el . Currently, I use the followed snippets to create this file if not exist. (defconst custom-file (expand-file-name "custom.el" user-emacs-directory)) (unless (file-exists-p custom-file) (shell-command (concat "touch " custom-file))) There is an ugly shell-command touch in, any other elisp functions can do this? You can use (write-region "" nil custom-file) not sure that is the ideal solution. 来源: https://stackoverflow.com/questions/14071991/how-to-create-an-empty-file-by-elisp

Can you implement any pure LISP function using the ten primitives? (ie no type predicates)

我的梦境 提交于 2019-12-04 02:06:14
This site makes the following claim: http://hyperpolyglot.wikidot.com/lisp#ten-primitives McCarthy introduced the ten primitives of lisp in 1960. All other pure lisp functions (i.e. all functions which don't do I/O or interact with the environment) can be implemented with these primitives. Thus, when implementing or porting lisp, these are the only functions which need to be implemented in a lower language. The way the non-primitives of lisp can be constructed from primitives is analogous to the way theorems can be proven from axioms in mathematics. The primitives are: atom, quote, eq, car,

What is the Definition of a Lisp Cons Cell?

喜你入骨 提交于 2019-12-04 00:43:14
What exactly is the definition of a Common Lisp Cons Cell? How is a Cons Cell different than a standard linked list item? After all, both the cons cell and the linked list item have a value and a pointer to the next cell or item... or is this understanding wrong? Cons cells in general hold two pointers that can point to anything. General usage of course is to point to a "value" with the left one, and to another Cons cell (or nil) with the "right" one. A cons cell is closer to a binary tree node than a linked list node. car and cdr return the two children, which can be nil, atoms, or other cons

Is there a command to halt the interpreter in Common Lisp?

僤鯓⒐⒋嵵緔 提交于 2019-12-04 00:12:15
I'm looking for an expression that will cause the interpreter to exit when it is evaluated. I've found lots of implementation-specific ones but none in the HyperSpec, and I was wondering if there were any that I wasn't seeing defined in the specification. I've found that (quit) is recognized by both CLISP and SLIME, and (exit) is recognized only by CLISP, but I can't find any documentation that references either of these. Since most Lisps import a quit function into CL-USER, CL-USER::QUIT is a good guess without knowing the implementation specific package where it is. (cl-user::quit) Note the

How to start REPL for slimv with MIT-Scheme

半城伤御伤魂 提交于 2019-12-04 00:03:31
My operating system is Debian Squeeze. Here's the vim version: VIM - Vi IMproved 7.2 (2008 Aug 9, compiled Jul 12 2010 02:29:33) I read a tutorial on http://kovisoft.bitbucket.org/tutorial.html and tried to start REPL for MIT-Scheme. Unfortunately, I failed to start. When I pressed ",c", it started a terminal window loading mit-scheme. Nothing showed in the REPL buffer of vim. Some errors showed in the terminal: Listening on port: 4005 ;netcat: "4005: inverse host lookup failed: Unknown host" ;To continue, call RESTART with an option number: ; (RESTART 1) => Return to read-eval-print level 1.

Common LISP on iPhone/iOS

你。 提交于 2019-12-04 00:01:23
Is it possible to call a Common Lisp function in iOS? If so, is it possible create it in a dynamic library? It depends on what you mean by calling a CL function, but most likely ECL will be your shortest path. Start here, as there is a patch for ECL to better accommodate iOS: http://funcall.posterous.com/tag/iphone ECL generates C code, so you should be in safe territory with Apple's shifting policies. Have you tried MOCL ? According to the website "mocl is a highly optimizing CL implementation, delivering tight native code via LLVM/Clang". Maybe you can create a dynamic library, though it is

find free variables in lambda expression

主宰稳场 提交于 2019-12-03 23:59:27
Does anyone know how I can figure out the free variables in a lambda expression? Free variables are the variables that aren't part of the lambda parameters. My current method (which is getting me nowhere) is to simply use car and cdr to go through the expression. My main problem is figuring out if a value is a variable or if it's one of the scheme primitives. Is there a way to test if something evaluates to one of scheme's built-in functions? For example: (is-scheme-primitive? 'and) ;Value: #t I'm using MIT scheme. [EDIT 4] Disclaimer; or, looking back a year later: This is actually a really

F# Type Providers vs. Lisp macros

淺唱寂寞╮ 提交于 2019-12-03 23:30:59
I've been reading about F# 3.0 type providers (e.g. here ) and it seems that they are based on a kind of compile-time code generation. In that respect I was wondering how they compare against Lisp macros. It would seem that both F# 3.0 type providers and Lisp macros allow user code to execute at compile time and introduce new types available to the compiler. Can anyone shed some light on the issue and nuances involved? There is some overlap between F# type providers and meta-programming techniques from other languages, but I agree with Daniel that they do not have much in common. F# has some

Why use #' before function arguments in emacs-lisp?

寵の児 提交于 2019-12-03 23:17:02
I'm familiar with Emacs Lisp, but not Common (or any other) Lisp. Some Lisp programmers suggest (e.g. A basic function for emacs ) that it's good to use #' in front of function arguments in Lisp code. For example: (mapc #'my-fun '(1 2 3)) In Emacs Lisp, I believe that this is equivalent to (mapc 'my-fun '(1 2 3)) From the elisp manual, section 12.7. The read syntax #' is a short-hand for using function . The following forms are all equivalent: (lambda (x) (* x x)) (function (lambda (x) (* x x))) #'(lambda (x) (* x x)) and the help for function function is a special form in eval.c . (function