emacs,lisp,elisp , Exceed evaluation depth when forward function in Emacs Lisp


Exceed evaluation depth when forward function in Emacs Lisp

Question:

Tag: emacs,lisp,elisp

Here is just a simplified code snipped I have not managed to work. I do not understand what is wrong.

(defun enumerate-indicies (func)
    (let ((index 0))
        (while (< index 5)
            (funcall func index)
            (setq index (1+ index)))))

(defun enumerate-multiplied-indicies (func)
    (enumerate-indicies #'(lambda (index)
                            (funcall func (* 10 index)))))

The following testing code returns 10 as expected:

(defun test/enumerate-indicies ()
    (let ((sum 0))
          (enumerate-indicies #'(lambda (index)
                                    (setq sum (+ sum index))))
    sum))

(test/enumerate-indicies)

But the below causes error Lisp nesting exceeds max-lisp-eval-depth in my Emacs:

(defun test/enumerate-multiplied-indicies ()
    (let ((sum 0))
          (enumerate-multiplied-indicies #'(lambda (index)
                                             (setq sum (+ sum index))))
    sum))
(test/enumerate-multiplied-indicies)

Could you please give my a clue? That is not supposed be a recursive call here but seems that it is. Thanks.


Answer:

How about using lexical-let to penetrate the lambda? Is the correct answer 100?

(defun enumerate-indicies (func)
  (let ((index 0))
    (while (< index 5)
      (funcall func index)
        (setq index (1+ index)))))

(defun enumerate-multiplied-indicies (func)
  (lexical-let ((func func))
    (enumerate-indicies #'(lambda (index)
      (funcall func (* 10 index))))))

(defun test/enumerate-multiplied-indicies ()
  (lexical-let ((sum 0))
    (enumerate-multiplied-indicies #'(lambda (index)
      (setq sum (+ sum index))))
    sum))

(test/enumerate-multiplied-indicies)

Related:


Error in Dired sorting on Windows (with Cygwin Emacs)


windows,emacs,cygwin,dired
In a Cygwin Emacs on Windows, in Dired, if I try to sort by time (for example), I get the error: insert-directory: Listing directory failed but `access-file' worked In a Windows Emacs binary on Windows, I do not have any problem, but Emacs uses its own implementation of ls IIUC....

Is there any mode for Rails' *.js.erb in emacs or I must use TextMate?


javascript,ruby-on-rails,emacs
I googled for "emacs js.erb" and got nothing valuable, Now I use web-mode for it, but obviously web-mode is not for *.js.erb: it can not auto complete the html tag, such as </div>. For <% ... %>, <%= .. %> and so on, it can not indent them. For javascript...

How do EMACS Lisp programmers read text files for non-editing purposes?


file-io,emacs,elisp
What do EMACS Lisp programmers do, when they want to write something roughly the equivalent of... for line in open("foo.txt", "r", encoding="utf-8").readlines(): ...(split on ws and call a fn, or whatever)... ..? When I look in the EMACS lisp help, I see functions about opening files into text editing buffers...

How to define a function with a variable number of arguments?


emacs,elisp
Instead of this: ((lambda (a b) (apply '+ (list a b))) 1 2) it is possible to write this in Scheme: ((lambda args (apply '+ args)) 1 2) Now it is possible to pass more than two arguments to the function. When I try it in Emacs Lisp I get...

looking for help in configuring .emacs file for python (python.el),


emacs,python.el
My emacs version is 24.5, using in built python. I have written these lines in my .emacs for it: (require 'python) (setq python-shell-interpreter "C:/Python34") The problem is none of the commands (when I am trying to run test.py) are working. I have tried several commands named like M-x python-shell-* and...

How to use FFI:def-call-in in clisp


lisp,common-lisp,ffi,clisp
I have figured out how to make use of shared objects created from C code into Clisp using FFI:def-call-out but I am not able to figure out how to use FFI:Def-call-in. I don't know the process and actually I am confused if clisp will also create some .so file that...

Exceed evaluation depth when forward function in Emacs Lisp


emacs,lisp,elisp
Here is just a simplified code snipped I have not managed to work. I do not understand what is wrong. (defun enumerate-indicies (func) (let ((index 0)) (while (< index 5) (funcall func index) (setq index (1+ index))))) (defun enumerate-multiplied-indicies (func) (enumerate-indicies #'(lambda (index) (funcall func (* 10 index))))) The following...

How to use a parameter in a macro call?


macros,lisp,common-lisp,sbcl
I have defined the following simple macro: (defmacro define-class (class-name) `(defclass ,class-name ()())) And now I want to use it in the following function: (defun create-data (mode) (define-class mode)) After compiling the last function I get the following message, the variable MODE is defined but never used. And when I...

Common Lisp Object System method execution order


lisp,common-lisp,clos
I have the following two classes: (defclass person () ()) (defmethod speak ((s person) string) (format t "-A" string)) (defmethod speak :before ((s person) string) (print "Hello! ")) (defmethod speak :after ((s person) string) (print "Have a nice day!")) (defclass speaker (person) ()) (defmethod speak ((i speaker) string) (print "Bonjour!"))...

Emacs bindings documentation


emacs,elisp
I am writing some bindings to lambdas in my ~/.emacs and would like to have a description of what the function does appear when I do (for example) C-c ?. I tried to put a string immediately after lambda () but that still does nothing. How do I get something...

How to pipe output from one external process into another?


emacs,elisp
I’ve written a function which takes the contents of the selected region and then runs it through two external processes. Effectively the behaviour I want to replicate is M-| smartypants -2 | ascii2uni -a D -q. The following function works, but requires two calls to call-process-region and temporarily storing the...

Confused when setting an Emacs face


emacs,elisp
(set-face-attribute 'diredp-dir-heading nil '(t (:foreground blue :background dark1))) What should be the right statements to set this face? Bow//...

Emacs hotkey for diffing buffer from file without reading (confirming) buffer name


emacs,elisp
I have made a hotkey that calls the diff-buffer-with-file command but then you have to hit enter to confirm that the file you are on is the one to correctly diff: (global-set-key (kbd "C-c e") 'diff-buffer-with-file). I looked up the documentation and saw that you also give &optional BUFFER, so...

Emacs code hints in minibuffer. How do I get them?


emacs,code-hinting
I've looked all over the internet for this, and since I'm new to Emacs, I don't know what to search for. I'm not looking for mini-buffer completion for commands and such. I'm looking for code hints in the mini-buffer, as shown in this gif. I couldn't care less about the...

Using vim to develop instead of Emacs on Windows


vim,emacs
I have used Emacs for a long time, say, 6 or 7 years. And it seems that I got Emacs Pinky somehow. Now I am trying to switch to vim, and it's a very good editor, just like Emacs, except that I wonder how you guys develop with it. Using...

ESS produces “Variable binding depth exceeds max-specpdl-size”


r,emacs,ess
I am trying ESS (Emacs Speaks Statistics). The problem is: Ctrl-P and the up-arrow are disabled on any buffer because of the following error: Variable binding depth exceeds max-specpdl-size The trigger is the following line in .emacs.el (require 'ess-site) This line is needed to load ESS. If I delete this...

EVAL/APPLY: too many arguments given to F


lisp,common-lisp,clisp
Hello why do i get *** - EVAL/APPLY: too many arguments given to F on function call with nested lists parameter. I cannot figure it out, since I passed a simple nested list. (defun f (L) (cond ((NULL l) nil) ((listp (car L)) (append (F(car L))) (F(cdr L) (car (F...

Printing ith row jth column value in lisp


arrays,multidimensional-array,lisp,clisp
I am taking input N as number of rows of a 2D matrix in lisp, where each row can have maximum of 5 elements in it. So i make it like this. Now for eachrow as it can have any number of elements between 0 to 5. So I made...

Emacs - selection not showing in windowed mode


emacs
I have Emacs on a Kubuntu 15.04 OS and I have a problem in showing the selected region; if I run emacs in the terminal windows with -nw option, I can set marks and I see the selected region highlighted; but if emacs starts in a window, the selected region...

How to move a file in Lisp using rename-file


lisp,common-lisp,pathname
What's the best way to move a file in Lisp in an implementation-independent way? For example I have an image file: (setq oldpath #P"SERVER:PICTURES;TEMP;PHOTO.PNG") and I want to move it out of the TEMP directory into the PICTURES directory. This seems to work: (setq newpath (make-pathname :host (pathname-host oldpath) :directory...

Emacs dired, what controls the color of the title line of a directory


emacs,dired
As the picture shown in attachment, what is the variable, if any, that controls the color of the title line of the directory? I'm trying to change the darkgreen to grey.

EMACS-Live + Slime error at startup


emacs,common-lisp,slime,kubuntu
Ok, I must be missing something obvious. I'm getting stuck since yesterday to launch Emacs-live + slime. I'm using EMACS 24.3.1, installed Emacs-live and it worked well (if I start emacs-live without Slime it works), downloaded Slime-Pack from git and added this line to .emacs-live.el (live-append-packs '(~/.live-packs/slime-pack/)) I'm on a...

Insertion into a list doesn't reflect outside function whereas deletion does?


list,lisp,common-lisp
I am new to Lisp. Deletion of an item in a list by a function gets reflected outside the function but insertion doesn't. How can I do the same for insertion? For example (defun test (a b) (delete 1 a) (delete 5 b) (append '(5) b) (member '5 b)) (setq...

Return items of a list in Lisp


lisp
I have to write a program in Lisp that returns the first item of a list if it contains an even number of elements, and the last if it contains an odd number of elements. I need a little advice on where to start? I don't need whole program.

Invalid specialized parameter in method lambda list


lisp,common-lisp
I am trying to write a simple coin flip program in Common Lisp. This is the code I have (defun yn (let ht (random 1) (if (eq ht 1) (princ heads) (princ tails)) ) ) It seems simple enough, but I keep getting the error: "Invalid specialized parameter in method...

How to start Emacs For Mac OS X from the command line without blocking?


osx,emacs
A tip from the website of Emacs For Mac OS X suggests executing the following script to start it from the command line: #!/bin/sh /Applications/Emacs.app/Contents/MacOS/Emacs "$@" However, this will block the command line until Emacs.app exists. Is there a way to start it from the command line without blocking?...

custom-set-variables add blank space on subsequent uses


emacs,elisp
I followed the emacs haskell tutorial, and couldn't understand some of its language regarding the use of custom-set-variables in the text quoted below. It seems that custom-set-variables should be used in one way on first usage, and another way (with added blank space) on subsequent uses. My questions are: What...

Shell (zsh) through Emacs?


emacs,zsh
I usually run emacs in a terminal to work. I would like to run a shell inside a emacs window. I've found the shell command, but I would like to run the zsh I usually use inside (with my own configuration). Is it possible? EDIT : I succeeded to run...

Elisp: how to make this function short


emacs,macros,elisp
I am implementing an plugin, which a lot of project types are remembered. For example: angular, meteor, ember, rails ... And keyed arguments are used. The function creates an hash table with provided keys and values, and assign the hash table to another hash table. Code below: (defun jst-remember-project-type (type...

How to get Emacs to sort lines by length?


sorting,emacs,elisp
I'd like to be able to highlight a region in Emacs and then sort the region by line length. The closest I've found is the following code which I think will sort by length: (sort-subr t #'forward-line #'end-of-line nil nil (lambda (l1 l2) (apply #'< (mapcar (lambda (range) (- (cdr...

If strings are vectors, why are they immutable?


lisp,common-lisp
if strings are vectors of characters, and a vector's elements can be accessed using elt, and elt is setf-able - then why are strings immutable?

Configuring Flycheck to work with C++11


c++,c++11,emacs,flycheck
I am having significant trouble configuring flycheck for C++11. Right now, flycheck is flagging things like std::to_string(). The checker I am using is just g++. What can I add in the .emacs file such that flycheck will assume C++11 by default?

Result value of elisp code stored in a file?


emacs,elisp,emacs24,dot-emacs
Looking for a way how evaluate elisp code stored in an external file and pass its result as a function argument. Example demonstrating what I'd like to achieve follows: ;; content of my_template.el '(this is a list) ;; content of .emacs where result of my_template.el has to be used (define-auto-insert...

How to omit certain folders on ido-switch-buffers and ido-dired?


emacs,dired,ido
I would like to ignore certain folders turning up via ido-dired when changing buffers in Emacs. These folders are system folders on a Mac and should not be removed otherwise, so at least I would like to hide them (especially annoying is, for example, ~/Documents which is suggested when one...

Getting `which-func-mode` output as a string in Emacs lisp


emacs
I am trying to retrieve the output which-function-mode as a string in Emacs. I am going to create a keyboard binding shortcut that copies it to my clipboard. It seems like this (which-func-mode ("" which-func-format " ")) is used to insert which-function into Emacs header line. However, I can't seem...

word-wrap — using `'cursor t` when overlay 'after-string at end of visual line


emacs,elisp,overlay
PROBLEM:  When point is at the end of a visually wrapped line (but not at the very end of the line), the cursor does not respect the cursor t setting of the overlay after-string -- i.e., the cursor appears at the beginning of the next visually wrapped line, instead of...

emacs: Symbol's function definition is void: loop


emacs,elisp,emacs-prelude
I am testing on loading packages in emacs init.el (Emacs 24.3). I followed a blog by the author of emacs prelude to automatically load packages, and copied the code there into my init.el as in the bottom. However, I got an error message about the loop function/symbol, which says: Symbol's...

org-mode agenda view matching tag and todo state


emacs,org-mode
I would like to create an agenda view with org-agenda-custom-commands, which will connect capabilities todo-tree and tags-tree. That's what I want to achieve, this sparse tree suited to such a search C-c / m JOB+TODO="NEXT"...

org-mode built-in table editor on windows


windows,emacs,org-mode
I am using org-mode version 8.2.2 and Emacs 24.2.1 on Windows 7 and have been struggling with the alignment of org-mode tables. Creating a simple table in org-mode using the build in editor gives me an unaligned table unaligned table columns | first col | second col | third col...

how to change the value of sp-navigate-reindent-after-up in smartparens


emacs,lisp,elisp,parentheses
I want to change the default behavior of smartparens to remove the whitespace before the close delimiter. I mean, when I type ) after (a b c |, I hope the final result is (a b c)|. Here, the | is cursor. I searched the documentation of smartparens, and find...

in clojure, function argument type mismatch


clojure,functional-programming,lisp
clojure, function argument is vector, but it takes a map without problem. (defn flower-colors [colors] (str "The flowers are " (:flower1 colors) " and " (:flower2 colors))) (flower-colors {:flower1 "red" :flower2 "blue"}) ;; -> "The flowers are red and blue" Function flower-colors suppose to take vector type argument, but with...

Escape symbols shown in “git log view” (C-x v l) in Emacs


git,logging,emacs,escaping
When doing C-x v l on a Git versioned file in Emacs, I get its recent history but with escape symbols ^[[... See http://screencast.com/t/x1YWh4GKZR. What's wrong in my config?...

No-argument (and) returns t


clojure,scheme,lisp,common-lisp
Both CL and Scheme define (and) to return t (or #t) with no arguments. I'm trying to understand the rationale for this. My naive assumption is that an empty set is false, and passing in zero arguments feels like passing in nothing that can be true. Edit: clojure follows the...

Backquote String Interpolation


macros,lisp,common-lisp
Is it possible to use lisp's macro to do string interpolation? For instance, can I make a macro like this: (defmacro test (a) `",a") So that (test abc) returns "abc" as a string? I could probably cheat by quoting it and turning that quote into a string, but that doesn't...

Task Dependency in org-mode


emacs,org-mode
I am trying to setup org-capture or org file for following issue: Task A is the major task. It depend upon minor tasks B and Task C. Now in org-agenda view, I should be able to see Task B and Task C. When they are done, I should be able...

Structuring large Lisp applications


lisp,common-lisp,quicklisp,asdf
I am currently trying to wrap my head around packages, systems & co. I now have read Packages, systems, modules, libraries - WTF? a few times, and I think I'm still having difficulties to get it right. If I simply want to split a Lisp source file into two files,...

Value from binding in LFE interpreter using Erlang


erlang,lisp,lfe
I'd like to use Lisp Flavored Erlang as a scripting extension language for an Erlang application. If you want, in a similar way GNU Emacs is configured and extended via Emacs Lisp. I know that the argument is wide and structured; but in the specific case of this question I'd...

MELPA pointing to non-existent version of multi-term?


emacs,package,melpa,multi-term
I am trying to use MELPA to install the emacs package "multi-term". When I do package-install multi-term, I get "http://melpa.org/packages/multi-term-20141203.1658.el: Not found". However, a more recent version http://melpa.org/packages/multi-term-20150220.1320.el is on MELPA. Why is emacs not installing this version?