lisp

Lisp string formatting with named parameters

ⅰ亾dé卋堺 提交于 2019-12-01 02:59:19
Is there a way in Lisp to format a string using named parameters? Perhaps something with association lists like (format t "All for ~(who)a and ~(who)a for all!~%" ((who . "one"))) in order to print "All for one and one for all" . Similar to this python question , or this scala one , or even c++ , but in Lisp. If this functionality isn't in the language, does anyone have any cool functions or macros that could accomplish the same thing? Use CL-INTERPOL . (cl-interpol:enable-interpol-syntax) String interpolation For simple cases, you don't need FORMAT : (lambda (who) #?"All for $(who) and $(who)

How to create and write into text file in Lisp

ε祈祈猫儿з 提交于 2019-12-01 02:47:03
问题 I want to know, how to create and write text file in lisp. I just want to write simple line like: "break 1" "break 2" I am using LispWorks IDE on Window 7 回答1: (with-open-file (str "/.../filename.txt" :direction :output :if-exists :supersede :if-does-not-exist :create) (format str "write anything ~%")) You may also choose different settings for the with-open-file macro. If you use :append instead of :supersede then you can write into the text file while preserving its context instead of

Are there function prototypes in Common Lisp?

一笑奈何 提交于 2019-12-01 02:22:19
问题 I have been programming in common lisp for a little while now, and throughout my experience using lisp, I have yet to see any function/macro that acts anything similar to function prototypes in C or C++. Currently I have to very careful about the ordering of my functions, otherwise, when I try to call a function from another, Lisp says the function "does not exist" because it is defined later in the file. Is there a way to get around this? Can I declare all my function prototypes at the top

What does the double minus (--) convention in function names mean in Emacs Lisp

随声附和 提交于 2019-12-01 02:04:18
I've been reading through a number of Emacs Lisp packages and have come across the convention of some functions being declared with -- after the library prefix, e.g.: (defun eproject--combine-regexps (regexp-list) I'm wondering if this a convention for declaring "private" functions to the library but so far I haven't found anything in the Emacs Coding guidelines. Emacs doesn't have any support for namespaces, packages, libraries or modules. Emacs sources therefore use foo- as a prefix for a foo library, and in some cases foo-- is used for bindings that are supposed to be internal. There is

Do any lisps have a s-expression as their head, e.g. ((f 2) 3 4)? If not, why?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 01:47:07
问题 Do any lisps support nested s-expression on their head? For example ((f 2) 3 4) for which (f 2) presumably evaluates to a function/macro to apply on 3 4 . Is it possible to have a lisp supporting such a thing? Or are there technical limitations that prohibit this/make it impractical? 回答1: In those Lisps, which have single namespace for variables and functions, your expression is valid. These are called Lisp-1. Scheme and Clojure are examples of such Lisps. In those Lisps, which have separate

What does backtick mean in LISP?

最后都变了- 提交于 2019-12-01 01:04:52
问题 I have this macro, which rewrites define. If I remove the " ` " backtick it won't work. What is the explanation? (defmacro define ((name &rest r) body) `(defun ,name ,r ,body)) 回答1: A single quote followed by the written representation of a value will produce that value: Example: '(1 x "foo") will produce a value that prints as (1 x "foo") . Suppose now that I don't want a literal symbol x in the list. I have a variable x in my program, and I want to insert the value to which x . To mark that

LISP cons in python

时光毁灭记忆、已成空白 提交于 2019-12-01 01:02:05
问题 Is there an equivalent of cons in Python? (any version above 2.5) If so, is it built in? Or do I need easy_install do get a module? 回答1: In Python, it's more typical to use the array-based list class than Lisp-style linked lists. But it's not too hard to convert between them: def cons(seq): result = None for item in reversed(seq): result = (item, result) return result def iter_cons(seq): while seq is not None: car, cdr = seq yield car seq = cdr >>> cons([1, 2, 3, 4, 5, 6]) (1, (2, (3, (4, (5,

Does Common Lisp have a something like java's Set Interface/implementing classes?

孤街浪徒 提交于 2019-11-30 23:55:56
问题 I need something like this, a collection of elements which contains no duplicates of any element. Does Common Lisp, specifically SBCL, have any thing like this? 回答1: For a quick solution, just use hash tables, as has been mentioned before. However, if you prefer a more principled approach, you can take a look at FSet, which is “a functional set-theoretic collections library”. Among others, it contains classes and operations for sets and bags. (EDIT:) The cleanest way would probably be to

What does the double minus (--) convention in function names mean in Emacs Lisp

蓝咒 提交于 2019-11-30 22:20:03
问题 I've been reading through a number of Emacs Lisp packages and have come across the convention of some functions being declared with -- after the library prefix, e.g.: (defun eproject--combine-regexps (regexp-list) I'm wondering if this a convention for declaring "private" functions to the library but so far I haven't found anything in the Emacs Coding guidelines. 回答1: Emacs doesn't have any support for namespaces, packages, libraries or modules. Emacs sources therefore use foo- as a prefix

Common lisp :KEY parameter use

倾然丶 夕夏残阳落幕 提交于 2019-11-30 22:12:17
The :KEY parameter is included in some functions that ship with Common Lisp. All of the descriptions that I have found of them are unhelpful, and :KEY is difficult to search in a search engine because the ":" is usually ignored. How would it be used, for example, in the member function which allows both :TEST and :KEY ? Imagine that we have a list of cities: (defparameter *cities* ; City Population Area km^2 '((Paris 2265886 105.4) (Mislata 43756 2.06) (Macau 643100 30.3) (Kallithea 100050 4.75) (Nea-Smyrni 73090 3.52) (Howrah 1072161 51.74))) Now we can compute the population density in