lisp

The Clojure (or Lisp) Equivalent of a Compound Boolean Test

梦想的初衷 提交于 2020-01-12 03:09:48
问题 In C++ I'd write something like this: if (a == something && b == anotherthing) { foo(); } Am I correct in thinking the Clojure equivalent is something like this: (if (= a something) (if (= b anotherthing) (foo))) Or is there another way to perform a logical "and" that I've missed? As I said the latter form seems to work correctly--I was just wondering if there's some simpler way to perform the logical and. And searching for "boolean" "logical" and "and" on the Clojure Google Group turned up

Mapping multiple functions, in order, over a single list [closed]

与世无争的帅哥 提交于 2020-01-11 12:00:15
问题 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 5 years ago . I would like to map three different functions, in order, over a single list. To demonstrate what I mean, say we want to do the following three mappings: (map foo mylist) (map bar mylist) (map foobar mylist) If we define mylist as '(1 2 3) , and we run the above functions one at a time, we get: (map foo mylist) =

Why does this mapcan cause my REPL to freeze?

五迷三道 提交于 2020-01-11 10:11:09
问题 In this very useful answer, it was suggested I could replace this code: (defun describe-paths (location edges) (apply (function append) (mapcar #'describe-path (cdr (assoc location edges))))) With this: (defun describe-paths-mapcan (location edges) (mapcan #'describe-path (cdr (assoc location edges)))) I certainly understand conceptually why this should work, but it doesn't; the second variation freezes my REPL and the CL prompt never returns. I have to restart SLIME. So I looked it up, and

Why does this mapcan cause my REPL to freeze?

僤鯓⒐⒋嵵緔 提交于 2020-01-11 10:10:16
问题 In this very useful answer, it was suggested I could replace this code: (defun describe-paths (location edges) (apply (function append) (mapcar #'describe-path (cdr (assoc location edges))))) With this: (defun describe-paths-mapcan (location edges) (mapcan #'describe-path (cdr (assoc location edges)))) I certainly understand conceptually why this should work, but it doesn't; the second variation freezes my REPL and the CL prompt never returns. I have to restart SLIME. So I looked it up, and

Why does this mapcan cause my REPL to freeze?

十年热恋 提交于 2020-01-11 10:10:07
问题 In this very useful answer, it was suggested I could replace this code: (defun describe-paths (location edges) (apply (function append) (mapcar #'describe-path (cdr (assoc location edges))))) With this: (defun describe-paths-mapcan (location edges) (mapcan #'describe-path (cdr (assoc location edges)))) I certainly understand conceptually why this should work, but it doesn't; the second variation freezes my REPL and the CL prompt never returns. I have to restart SLIME. So I looked it up, and

Get numbers for the lottery

十年热恋 提交于 2020-01-11 07:06:05
问题 As part of learning Lisp I'm currently trying to write a function that helps me fill out my lottery ticket. I want that function to return a list of six numbers, where each number is between 1 and 49, without duplicate numbers, and being the list ordered in an ascending way. So far, I'm done with four of the five requirements. This is my current code: (defun lottery () (sort (loop repeat 6 collect (1+ (random 49))) #'<)) When I run this function I get something such as: (lottery) ;; => (3 10

193_common lisp文件句柄的使用

ε祈祈猫儿з 提交于 2020-01-10 16:22:54
分析使用的例子来自于《实用common lisp编程》中的CD录入程序。或许是因为之前学习过其他的编程语言,我现在的编程语言的学习基本上都是在寻找之前已经掌握的编程语言的已知元素。当然,这只是第一步。当这一步过了之后,后面的提升则是针对这个编程语言的一些特性。 这一次找到的已知元素是C语言中的文件句柄,当然,在我之前学习过的一系列的脚本语言中也有这个元素。或许,拿语法清晰的Python做一个类比更简单吧! 如果是在Python中,这里涉及到的接口是open,open打开的文件句柄可以拥有不同的属性。比如说,最简单的读或者写。在common lisp中,相应的功能是一个宏,with-open-file。与python的open相似,这个宏打开文件的同时会将文件操作绑定到一个变量上。而打开文件的方式具有不同的属性。而其他语言中提到的句柄这个东西,就是common lisp中with-open-file需要绑定的变量。 以下是common lisp的代码: 上面的操作,打开一个文件,设置输出属性。如果文件已经存在,那么进行覆盖。第二个类似句柄的宏with-standard-io-syntax作用于print,将其行为设置为默认。因此,上面的函数功能就是把全局量*db*的信息存储到filename指定的文件中。 理解了上面的功能,读取基本是一个相反的操作。 以下是common lisp代码

The object ___ is not applicable [duplicate]

醉酒当歌 提交于 2020-01-10 05:56:09
问题 This question already has answers here : “application: not a procedure” in binary arithmetic procedures (1 answer) Getting every nth atom using scheme does not pick up the last atom (3 answers) Closed 5 years ago . Hi I'm writing something that grabs every third element after the first element. However I can't test the logic due to ";The object (a b c d e f g) is not applicable." The code is below, atom? checks if it's a list, listful is defined as an empty list. (DEFINE (threes var) (if(atom

Mathematica: Unevaluated vs Defer vs Hold vs HoldForm vs HoldAllComplete vs etc etc

雨燕双飞 提交于 2020-01-09 04:38:10
问题 I'm bewildered by all the built-in Mathematica functions that purport to prevent evaluation in some way: Unevaluated , Defer , Hold , and over half a dozen of the form Hold* . The Mathematica documentation just explains each function in isolation without explaining why you would choose one or the other. Can anyone offer a coherent explanation of all these functions? The whole thing seems like a convoluted mess to me. Relating it all to Lisp macros might be a good place to start. Most of the

How do I call another function in lisp;

北战南征 提交于 2020-01-07 09:45:15
问题 My program is supposed to convert a given temperature from Fahrenheit to Centigrade or the other way around. It takes in a list containing a number and a letter. The letter is the temperature and the letter is the unit we are in. Then I call the appropriate function either F-to-C or C-to-F. How do I call the functions with the given list that was first checked in my temperature-conversion function. Here is my code. (defun temperature-conversion (lst) (cond ((member 'F lst) (F-to-C)) ((member