lisp

Idiomatic clojure for progress reporting?

馋奶兔 提交于 2019-11-28 16:51:28
How should I monitor the progress of a mapped function in clojure? When processing records in an imperative language I often print a message every so often to indicate how far things have gone, e.g. reporting every 1000 records. Essentially this is counting loop repetitions. I was wondering what approaches I could take to this in clojure where I am mapping a function over my sequence of records. In this case printing the message (and even keeping count of the progress) seem to be essentially side-effects. What I have come up with so far looks like: (defn report [report-every val cnt] (if (= 0

What does # mean in LISP

你。 提交于 2019-11-28 16:47:02
问题 For example, #'functionname , is it necessary? 回答1: #'functionname in Common Lisp Common Lisp and some other Lisp dialects have more than one namespace. Here the ones for functions and values are different. To get the function value of a name, we need to write: (function functionname) Since that is a bit long to write, there is a shorter notation: #'functionname To show the effect see this: (let ((foo 42)) (flet ((foo () 'bar)) (list foo (function foo) #'foo (foo)))) Above defines a local

How to force Emacs not to display buffer in a specific window?

佐手、 提交于 2019-11-28 16:44:55
My windows configuration looks like this: +----------+-----------+ | | | | | | | | | | | | | | | | +-----------+ | | | +----------+-----------+ And I use the lower right window for special displays (like help, completion etc.), but emacs insists on using that window when I call commands ( find-file-other-window , etc.) that use display-buffer , and resize that window as well. It's annoying... Is there a way that I can force emacs NOT to use that windows? I was thinking of advising display-buffer , but it's a function in c. Any thoughts on this? EDIT: Based heavily on Trey's answer, this is

What can you do with Lisp macros that you can't do with first-class functions?

[亡魂溺海] 提交于 2019-11-28 16:42:57
I think I understand Lisp macros and their role in the compilation phase. But in Python, you can pass a function into another function def f(filename, g): try: fh = open(filename, "rb") g(fh) finally: close(fh) So, we get lazy evaluation here. What can I do with macros and not with functions as first class objects? First of all Lisp has first-class functions too, so you could as well ask: "Why do I need macros in Lisp if I already have first-class functions". The answer to that is that first-class functions don't allow you to play with syntax. On a cosmetic level, first-class functions allow

Definition of “lisp form”?

梦想的初衷 提交于 2019-11-28 16:29:08
问题 What exactly the definition of a "Lisp form"? As far as I know, it's "either an atom or a list that has a symbol as its first element". But then, this (in Scheme) would not be a form: ((lambda () 42)) ;; The answer to Life, the Universe and Everything. Because the first element of the list is itself another list. And after it's evaluated it will be a procedure (not a symbol). I can find several different websites and tutorials talking about Lisp forms, but none which gives a complete and

Lisp and Erlang Atoms, Ruby and Scheme Symbols. How useful are they?

与世无争的帅哥 提交于 2019-11-28 16:10:13
How useful is the feature of having an atom data type in a programming language? A few programming languages have the concept of atom or symbol to represent a constant of sorts. There are a few differences among the languages I have come across (Lisp, Ruby and Erlang), but it seems to me that the general concept is the same. I am interested in programming language design, and I was wondering what value does having an atom type provide in real life. Other languages such as Python, Java, C# seem to be doing quite well without it. I have no real experience of Lisp or Ruby (I know the syntaxes,

Best practices in building and deploying Clojure applications: good tutorials?

五迷三道 提交于 2019-11-28 15:53:17
I am new to Clojure, and am beginning to experiment with building an application. So far, everything I've seen about tutorials on compiling Clojure programs involves interactivity. For example, "load up the REPL and type (load-file "this-or-that") to run. This is fine, but it's not enough. I am so used to the edit-compile-run idioms of languages like C or Delphi, that I am instinctively driven to make edits, then hit "M-x compile". The problem is that "lein uberjar", which I understand is the equivalent to "make", is painfully slow to execute even for a hello world. So I'm going to have to

Why is the Lisp community so fragmented? [closed]

一个人想着一个人 提交于 2019-11-28 15:51:57
To begin, not only are there two main dialects of the language (Common Lisp and Scheme), but each of the dialects has many individual implementations. For example, Chicken Scheme, Bigloo, etc... each with slight differences. From a modern point of view this is strange, as languages these days tend to have definitive implementations/specs. Think Java, C#, Python, Ruby, etc, where each has a single definitive site you can go to for API docs, downloads, and such. Of course Lisp predates all of these languages. But then again, even C/C++ are standardized (more or less). Is the fragmentation of

How to write an interpreter?

♀尐吖头ヾ 提交于 2019-11-28 15:40:58
问题 I have decided to write a small interpreter as my next project, in Ruby. What knowledge/skills will I need to have to be successful? I haven't decided on the language to interpret yet, but I am looking for something that is not a toy language, but would be relatively easy to write an interpreter for. Thanks in advance. 回答1: You will have to learn at least: lexical analysis (grouping characters into tokens) parsing (grouping tokens together into structure) abstract syntax trees (representing

Given the following LISP eval function - what is required to add defmacro?

谁说我不能喝 提交于 2019-11-28 15:40:22
Given the following definition of the LISP eval function - what is required to add the defmacro function? (Or even just evaluate a macro) (defun null. (x) (eq x '())) (defun and. (x y) (cond (x (cond (y 't) ('t '()))) ('t '()))) (defun not. (x) (cond (x '()) ('t 't))) (defun append. (x y) (cond ((null. x) y) ('t (cons (car x) (append. (cdr x) y))))) (defun list. (x y) (cons x (cons y '()))) (defun pair. (x y) (cond ((and. (null. x) (null. y)) '()) ((and. (not. (atom x)) (not. (atom y))) (cons (list. (car x) (car y)) (pair. (cdr x) (cdr y)))))) (defun assoc. (x y) (cond ((eq (caar y) x) (cadar