lisp

How to use double-float?

試著忘記壹切 提交于 2019-12-05 04:51:25
I am struggling a little trying to figure out how to tell Lisp that I want to use double-float values. Suppose I have: (let ((x 1)) (format t "~A~%" (/ x 3.0))) Which gives: 0.33333334 If I want to use double-float, I tried this: (let ((x 1)) (declare (type double-float x)) (format t "~A~%" (/ x 3.0))) 0.33333334 So the result is not a double-float. I can, however, force double-float like this: (let ((x 1)) (format t "~A~%" (/ x 3.0d0))) 0.3333333333333333d0 And now I get a double-float result. So my question is: if I'm defining a form or function in which I want arithmetic to be in double

Lisp macro (or function) for nested loops

二次信任 提交于 2019-12-05 04:28:27
Is it possible to write a Common Lisp macro that takes a list of dimensions and variables, a body (of iteration), and creates the code consisting of as many nested loops as specified by the list? That is, something like: (nested-loops '(2 5 3) '(i j k) whatever_loop_body) should be expanded to (loop for i from 0 below 2 do (loop for j from 0 below 5 do (loop for k from 0 below 3 do whatever_loop_body))) Follow up As huaiyuan correctly pointed out, I have to know the parameters to pass to macro at compile time. If you actually need a function as I do, look below. If you are ok with a macro, go

c(a|d)+r macro in Racket

半腔热情 提交于 2019-12-05 04:21:43
问题 I wonder if it's possible to write a macro in Racket that would translate every form of shape (c(a|d)+r xs), where c(a|d)+r is a regular expression matching car, cdr, caar, cadr, ... etc, into the corresponding composition of first and rest. For example, this macro should take (caadr '(1 2 3 4 5)) and transform that to (first (first (rest '(1 2 3 4 5)))). Something like this in Shen (Mark Tarver's new programming language): https://groups.google.com/group/qilang/browse_thread/thread

Why is the @ sign needed in this macro definition?

不问归期 提交于 2019-12-05 04:20:20
In the following when macro: (defmacro when (condition &rest body) `(if ,condition (progn ,@body))) Why is the there an at sign? It's very easy to see the difference by making a little experiment > (let ((x '(1 2 3 4))) `(this is an example ,x of expansion)) (THIS IS AN EXAMPLE (1 2 3 4) OF EXPANSION) > (let ((x '(1 2 3 4))) `(this is an example ,@x of expansion)) (THIS IS AN EXAMPLE 1 2 3 4 OF EXPANSION) As you can see the use of ,@ will place the elements of the list directly inside in the expansion. Without you get instead the list placed in the expansion. The @ can also be thought of

Retrieving (load)ed source code from CCL?

南楼画角 提交于 2019-12-05 03:08:37
问题 I called (load "code.lisp") with CCL, then accidentally deleted code.lisp. Is there any way for me to retrieve the source code? Does CCL have it in memory anywhere? 回答1: That's a very special functionality. Here only for Clozure CL . The code won't work anywhere else. This works for me in the CCL IDE. It retrieves the source code of symbols who are :internal or :external in a certain package. It doesn't do that for symbols which are inherited from other packages (you would then often have the

SBCL initialization file

对着背影说爱祢 提交于 2019-12-05 02:52:50
I would like to know where I should save my .sbclrc file. I tried saving it in my .sbcl folder, but it doesn't seem to be working. I'm using Windows XP with Emacs version 23. I'm trying to set up asdf-install, that is why I'm mucking around with the initialization file. Thanks for your time. What is the result of evaluating this in the repl: (SB-IMPL::USERINIT-PATHNAME) 来源: https://stackoverflow.com/questions/2245854/sbcl-initialization-file

LISP: How to read content from a file and write it in another file?

狂风中的少年 提交于 2019-12-05 02:20:24
问题 I want to write a function that has as arguments the names of the two files and copies the content from the first file to the second one. So far I wrote a function that reads from a file: (defun readFile (name) (let ((in (open name))) (format t "~a~%" (read-line in)) (close in))) And a function that writes a string to a file: (defun writeFile (name content) (with-open-file (stream name :direction :output :if-exists :overwrite :if-does-not-exist :create) (format stream content))) Following

Build Lisp code in SublimeText2

我的未来我决定 提交于 2019-12-05 02:19:14
问题 Any way to build&run common lisp in ST2 on mac os? I know about SLIME and Emacs, but i'm interested in ST 回答1: First you have to install interpreter, in my case I used sbcl. After installing that it's prety simple. On ST2 go to Preferences/Browse Packages , go to Lisp, add a new file Lisp.sublime-settings with: { "cmd": ["sbcl", "--script", "$file"], "working_dir": "${project_path:${folder}}", "selector": "source.lisp", "osx": { "cmd": ["/opt/local/bin/sbcl", "--script", "$file"] }, //

Does learning one Lisp help in learning the other?

五迷三道 提交于 2019-12-05 02:07:50
Is there any synergy between learning different Lisp languages? I'm currently learning Emacs Lisp, as it is immediately useful in my daily Emacs usage, however i'm fascinated with all Lisps, so maybe someday i will learn and use others. Will learning Emacs Lisp help me, when i start digging in Common Lisp, Scheme or Clojure? In other words, will it be for me like learning a completely new language, or some notions and paradigms are common? I'm also interested in comparison of unique differences between the Lisps, which will be a problem, when i come from one Lisp to another. In How to go about

Emacs lisp evaluate variable in alist

倾然丶 夕夏残阳落幕 提交于 2019-12-05 01:55:57
问题 This is a follow-up question to Emacs Lisp: evaluate variable in alist.. I am trying to set default-frame-alist in my .emacs file. Consider, e.g. (setq default-frame-alist '((auto-lower . nil) (auto-raise . nil) (height . 41) (width . 80) (top . 1) (left . 1))) (I have omitted some values) This works fine.. Suppose now I want set the height according to another variable..Say, I stored the integer value 50 in the variable my-height .. How can I set height to the value of my-height ? I have