lisp

What is wrong with my emacs/slime setup (compile-and-load/eval not working)?

荒凉一梦 提交于 2019-12-06 00:26:37
问题 I can run emacs and start slime (with M-x slime ). At this point I get the REPL in the inferior-lisp buffer and can run lisp there. But when I open up lisp code in another buffer none of the slime-goodness works ( C-x C-e , C-c C-k etc.) and I keep seeing this in the Messages buffer (with an increasing count-number): slime-connection: Not connected. Polling "/var/folders/B9/B9B5J15dH+aNt5J5gkROEk+++TI/-Tmp-/slime.3202".. (Abort with `M-x slime-abort-connection'.) [69 times] Makes me think

LISP very simple list question

被刻印的时光 ゝ 提交于 2019-12-05 22:40:55
Im learning lisp and im pretty new at this so i was wondering... if i do this: (defparameter *list-1* (list 1 2)) (defparameter *list-2* (list 2 3)) (defparameter *list-3* (append *list-1* *list-2*)) And then (setf (first *list-2*) 1) *list-3* I will get (1 2 1 4) I know this is because the append is going to "save resources" and create a new list for the first chunk, but will actually just point to the second chunk, coz if i do: (setf (first *list-1*) 0) *list-3* I will get (1 2 1 4) instade of the more logical (0 2 1 4) So my question is, what other cases are like this in lisp, how do you

How to make a Lisp function call java while being aware of packages?

拥有回忆 提交于 2019-12-05 21:11:39
In Emacs use a Lisp function to run the Java program the current file correspond to. (defun java-run-current-file () "Runs the java program the current file correspond to" (interactive) (shell-command (concat "java " (file-name-sans-extension (file-name-nondirectory (buffer-file-name)))))) It works by stripping the current file name of its path and extension and using it as an argument to java which is run from the path where the file is at. The problem with this approach is that if the current file is part of a package then the argument to java has to be prefixed with the package name and a

Common Lisp 操作Mysql

末鹿安然 提交于 2019-12-05 21:06:02
Common Lisp 通过CFFI可以调用其它语言的接口,如此,Common Lisp可以快速开发各种应用程序,本文将讲述在ubuntu系统下的一个简单的Common Lisp与mysql交互的实例。 准备 安装CFFI sudo apt-get install cl-cffi 安装CL-MYSQL sudo apt-get install cl-sql-mysql 安装MYSQL sudo apt-get install mysql-server 安装quicklisp wget http://beta.quicklisp.org/quicklisp.lisp 开始 启动slime或sbcl(本例使用slime). 进入slime: M+x slime slime下加载quicklisp: CL-USER> (load "quicklisp.lisp") CL-USER> (quicklisp-quickstart:install) CL-USER> (ql:add-to-init-file) 加载cffi和cl-mysql: CL-USER> (ql:quickload "cffi") CL-USER> (ql:quickload "cl-mysl") 定义试验用的mysql操作包: (defpackage :com.casic.mysql-oper (:use

How does Lisp function remember state in this code?

六眼飞鱼酱① 提交于 2019-12-05 20:58:56
I saw a piece of code from the website http://www.ccs.neu.edu/home/shivers/newstyle.html : > (defun element-generator () (let ((state '(() . (list of elements to be generated)))) ;() sentinel. (let ((ans (cadr state))) ;pick off the first element (rplacd state (cddr state)) ;smash the cons ans))) ELEMENT-GENERATOR > (element-generator) LIST > (element-generator) OF > (element-generator) ELEMENTS > (element-generator) TO > (element-generator) BE > (element-generator) GENERATED I don't understand how the function remembers the state. Isn't state redefined to the whole list each time the function

Clojure: determine if a function exists

南笙酒味 提交于 2019-12-05 20:22:42
问题 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 回答1: 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?) 回答2: Chances are if you need this, you're doing something wrong, but... (defn callable? [s] (let

Levels of Homoiconicity [closed]

不打扰是莪最后的温柔 提交于 2019-12-05 18:34:01
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . This is a follow up to my previous question. I’m not convinced that Lisp code is as Homoiconic as machine code on a Von Neumann architecture. It seems obvious to me that in both cases code is represented as data, but it also seems apparent that you can exploit this property much more freely in machine code than

How to create an empty file by elisp?

本秂侑毒 提交于 2019-12-05 18:24:15
问题 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? 回答1: You can use (write-region "" nil custom-file) not sure that is the ideal solution. 来源: https:/

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

旧街凉风 提交于 2019-12-05 18:08:33
问题 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

Position of All Matching Elements in List

孤人 提交于 2019-12-05 17:11:31
I'm trying to write a function in Common Lisp similar to the built in position function, that returns a list of the positions of all elements in the haystack that match the needle, as opposed to just the first. I've come up with a few possible solutions (for example recursively searching for the next element using a cdr-from function on the position and adding the result to the previous position) but none of the approaches I've come up with so far seem particularly elegant. Can anyone suggest what would be the best way of approaching this, as I'm currently struggling. The obvious way to solve