question_id int64 1.99k 74.6M | answer_id int64 4.76k 74.6M | title stringlengths 20 144 | question stringlengths 22 4.09k | answer stringlengths 24 4.1k |
|---|---|---|---|---|
6,144,435 | 6,144,959 | Check if item is in a list (Lisp) | What's a simple way to check if an item is in a list?
Something like
(in item list)
might return true if item=1 and list=(5 9 1 2) and false if item=7
| Common Lisp
FIND is not a good idea:
> (find nil '(nil nil))
NIL
Above would mean that NIL is not in the list (NIL NIL) - which is wrong.
The purpose of FIND is not to check for membership, but to find an element, which satisfies a test (in the above example the test function is the usual default EQL). FIND returns su... |
6,165,836 | 6,167,589 | In LISP how to inspect free variables in a closure? | In lisp I can bind free variables bound in a closure like this...
(let ((x 1) (y 2) (z 3))
(defun free-variables () (+ x y z)))
(free-variables)
results in ...
6
What I want to know is if it is possible to inspect bound closure variables dynamically?
E.g.
(inspect-closure free-variables)
resulting in something li... | Common Lisp
Access to the closure's internal variables is only possible from functions in the same scope (See Jeff's answer). Even those can't query somewhere for these variables. This functionality is not provided by the Common Lisp standard.
Obviously in many cases individual Common Lisp implementations know how to g... |
6,168,089 | 6,168,140 | Does Lisp have something like Haskell's takeWhile function? | I'm new to Common Lisp. In Haskell, you can do a little something like this:
Prelude> takeWhile (<= 10) [k | k <- [1..]]
[1,2,3,4,5,6,7,8,9,10]
Is this possible in Lisp? Not necessarily with an infinite list, but with any list.
| You could use LOOP:
(setq *l1* (loop for x from 1 to 100 collect x))
(loop for x in *l1* while (<= x 10) collect x)
If you really need it as a separate function:
(defun take-while (pred list)
(loop for x in list
while (funcall pred x)
collect x))
And here we are:
T1> (take-while (lambda (x) (<= x 10... |
6,169,706 | 6,169,936 | Lisp Interpreter in a C++ Program | I'm not sure I'm phrasing this right, but I'm pretty sure I'm looking for a LISP interpreter I can put in my C++ program.
The ideal situation I'm imagining is a function or something to which I can pass either a string, file, or filename containing the LISP code and then use the output from the LISP code in other parts... | There is also ECL ("Embeddable Common Lisp"). It has the advantage, that it provides the full Common Lisp standard. Unfortunately, the documentation with respect to embedding is... well... a little bit scarce.
I never used it myself, so I cannot really tell, whether this would actually be an easy thing to embed into yo... |
6,197,460 | 6,199,126 | Trouble with Lisp macros | I'm trying to write a macro in Lisp that re-implements let using itself. This is a trivial exercise which has no practical purpose; however after giving a response to a related question, I realized I should probably learn more about macros. They're touted as one of the great things about Lisp, but I rarely use them.
... | Your macro expands to:
(LET ((A 5) (B 2))
(DOLIST (X ((PRINT (+ A B)))) X))
which is invalid because ((PRINT (+ A B))) is not a valid expression. There is also an issue that using an interned symbol in macro expansion can lead to variable capture, but that is not directly relevant (read more in PCL).
Using DOLIST he... |
6,213,455 | 6,213,606 | In common-lisp how can i override/change evaluation behaviour for a specific type of object? | In common-lisp, I want to implement a kind of reference system like this:
Suppose that I have:
(defclass reference () ((host) (port) (file)))
and also I have:
(defun fetch-remote-value (reference) ...) which fetches and deserializes a lisp object.
How could I intervene in the evaluation process so as whenever a referen... | In short: you cannot do this, except by rewriting the function eval and modifying your Lisp's compiler. The rules of evaluation are fixed Lisp standard.
Edit After reading the augmented question, I don't think, that you can achieve full transperency for your references here. In a scenario like
(defclass foo () (referen... |
6,225,211 | 6,226,248 | Mysterious problem with floating point in LISP - time axis generation | Ok, I do know what and how works floating point. But, It doesn't stop to puzzle me whenever I deal with it.
I try to do some time axis generation function. The idea is simple. To make smt like this
(defun make-time-axis (start step stop)
...)
So, when you call it with e.g.
(make-time-axis 0 0.1 1.2)
result will be
... | If you know how floating point works (you have read What Every Computer Scientist Should Know About Floating Point Arithmetic, right?), you should realize that you got exactly what you asked for.
Mathematical numbers (be they integers, rationals, reals, complex, whatever) have many useful properties. For example, x/10 ... |
6,256,179 | 6,561,967 | How can I find the value of LC_XXX locale integr constants so that I can use them with cffi | I have this code:
(define-foreign-library libc
(:unix "libc.so.6"))
(use-foreign-library libc)
(defcfun "setlocale" :pointer (category :int) (locale :pointer))
and I want to do:
(with-foreign-string (locale "en_US.UTF-8")
(setlocale XXXX locale))
How can I find the integer values of the various LC_xxx constant... | I see this in my locale.h:
/* These are the possibilities for the first argument to setlocale.
The code assumes that the lowest LC_* symbol has the value zero. */
#define LC_CTYPE __LC_CTYPE
#define LC_NUMERIC __LC_NUMERIC
#define LC_TIME __LC_TIME
#define LC_COLLATE __LC_COLLATE
#d... |
6,260,754 | 6,268,264 | Just getting used to paredit in emacs on OS X - how come C-) doesn't work? | I've recently set up a Common Lisp programming environment in Mac OS X Leopard. One emacs module which I've found to be indispensable is paredit. Paredit is doing its part to help me wrangle my Lisp code more easily, but I've ran into a bit of a snare.
C-), bound to paredit-forward-slurp-sexp, is not forward slurpin... | IIRC, the modifier combination of Control and Shift cannot be sent to Emacs in a terminal. C-) requires the shift key, so it's out of bounds. I'm not convinced that any amount of terminal tweaking will change this.
I believe paredit-forward-slurp-sexp also gets bound to C-<right> by default, which should work fine in a... |
6,268,275 | 6,269,132 | Why apply is so important for lisp evaluator? | I have read chapter 4 of SICP, and just found that the first section lists the most important functions for implementing a evaluator, eval and apply, I understand that eval is very important, but why apply is so important? For some language, there is totally no apply such as in Javascript.
Edit: Sorry about that I am ... | The eval/apply thing in SICP (and elsewhere) is separating two major parts of an evaluator. The first part, the one that eval is doing, is dealing with the syntactic translation of code to its meaning -- but it's doing almost nothing except dispatching over the expression type. As you can see in the book, there are v... |
6,272,179 | 6,272,253 | defining a procedure using graphics-draw-line | Can you see what is wrong with this:
(define (box d x1 y1 x2 y2) (
(graphics-draw-line d x1 y1 x1 y2)
(graphics-draw-line d x1 y2 x2 y2)
(graphics-draw-line d x2 y2 x2 y1)
(graphics-draw-line d x... | Don't just group expressions with ()s -- that will try to use the result of the first as a function, but the value is #!unspecific -- definitely not a function.
Use this:
(define (box d x1 y1 x2 y2)
(graphics-draw-line d x1 y1 x1 y2)
(graphics-draw-line d x1 y2 x2 y2)
(graphics-draw-line d x2 y2 x2 y1)
(graphic... |
6,272,587 | 6,272,642 | Why isn't this Do Form valid? | I'm new to Common Lisp. I tried out the following do form:
(do ((n 0 (+ n 1)))
(< n 10)
(print n))
Clisp responds with:
*** - IF: variable < has no value
From my understanding, the do form is as follows:
(do (<lexically scoped variables> [per-iteration-expression])
(end-expression)
<statements>)
Wher... | Forgive me, my Lisp is rusty, but shouldn't that be a >?
And then shouldn't it be ((> n 10))? (Two parens, not one. You need something evaluated there).
This could be completely wrong, but that would be my next try.
|
6,286,922 | 6,286,969 | How well does your language support unicode in practice? | I'm looking into new languages, kind of craving for one where I no longer need to worry about charset problems amongst inordinate amounts of other niggles I have with PHP for a new project.
I tend to find Java too verbose and messy, and my not wanting to touch Windows with a 6-foot pole tends to rule out .Net. That lea... | Python's unicode support did not really change in 3.x. The unicode support in Python has been pretty much the same since Python 2.x, which introduced the separate unicode type and the encoding handling. What Python 3.x changes is that unicode becomes the only string type (and is renamed to str), whereas 2.x has bytestr... |
6,298,662 | 6,324,381 | write comparison string function | I fully understand the use of list in lisp but I 've got problem using string.
I try to write my own code of functions like string> or string< from common lisp to understand how lisp deals with string.
For example, abcde is bigger than abbb and returns 1.
I think that I will use the char function or do you think that I... | This is an implementation of a function that given two strings will return either -1, 0 or +1 depending on if the first is less than, equal or greater than the second.
In case one string is the initial part of the other then shorter string is considered to be "less than" the longer.
The algorithm is very simple... loop... |
6,310,330 | 6,311,374 | Is Prolog an untyped language? What's the difference between Prolog and dynamically typed languages? | If Prolog has clear distinction between strings, numbers, atoms, lists and compound structures how can it be called untyped.
And how does it differ from dynamically typed languages like Lisp for example.
Which part of the definition of "dynamically typed language" does Prolog conflict with? And which part of the defini... | Prolog is mostly untyped in the sense that you can pass any kind of term to any predicate and, usually, the worst case is that the predicate will not succeed. However, arithmetic predicates, such as is and =:= expect numeric arguments and may blow up - so there is a notion of types there.
Non-pure predicates might als... |
6,315,130 | 6,320,397 | breaking polylines on join spot in autocad - any lisp function? | i am trying to break a poly line where an other poly line has joined the first line. for example in three ways that there are two lines, (one main road and one by-way) i want to break the main road on the joint spot of two poly lines and make 3 individual lines.
so is there any lisp function or something like that , ... | i find a solution for this problem,
there is lisp programm, free to download, named QBRICK
you can download it from here : http://www.synapse-informatique.com/qbrick_en.htm
but it only supports 2000 - 2008
|
6,326,565 | 6,331,397 | disable individual buttons on a lispworks capi:push-button-panel | I'm working on a Connect Four game using common lisp and the LispWorks CAPI. I'm finished with the interface except for one thing: I use push-buttons (in a push-button-panel) to drop pieces into the columns, and I'd like to disable a button once its corresponding column is full. I'm relatively new to lisp, and I espe... | A bit of searching through the manual reveals this function, which allows you to enable/disable one or more elements in a push-button-panel. Also, the code you wanted explained calls the function (setf capi:button-enabled) with the arguments nil and my-button. However, this function is called in the "process" associate... |
6,335,886 | 6,336,056 | How to properly indent clojure/lisp? | I want to indent the following piece of code.
How would a lisper indent this?
I am especially confused about where to put newlines.
(defn primes [n]
(letfn [(sieve [table removal]
(assoc table removal false))
(primebools [i table]
(cond
(= i ... | (defn primes [n]
(letfn [(sieve [table removal]
(assoc table removal false))
(primebools [i table]
(cond
(= i n) table
(table i) (recur (inc i)
(reduce sieve table
(range (* i i) n i)))
... |
6,338,011 | 6,338,036 | lisp interpreter in python | I'm curious how a part of Peter Norvig's Lisp interpreter works. One can define functions in this Lisp interpreter...how does this work? I'm a beginner, and just would like a simple explanation.
There's one part that might be related where it says
elif x[0] == 'define': # (define var exp)
(_, var, exp) ... | In this case, x[0] is define, x[1] is the variable name, and x[2] is the expression. So, in Python, _, var, exp = x is a "destructuring assignment", which destructures the array x into its constituent elements, and assigns them to the variables on the left-hand side.
|
6,342,974 | 6,348,874 | Handling Images in Clozure Cl | 1) What is the proper method to make an image in ccl? Or what is the exact difference between:
(compile-file "foo.lisp") and (progn (load "foo.lisp") (save-application "foo"))?
2) Is there any possibility to load multiple images (command line prefered)?
| The file compiler in Common Lisp systems creates a representation of the original source in some kind of machine language (depending on the target processor) or for some virtual machine (for example in CLISP). This compiled file then can be loaded into a running Lisp system with the LOAD function and creates the defini... |
6,351,475 | 6,354,034 | variable trouble in lisp | I'm writing a program in Common Lisp in which I need a function with this basic outline:
(defun example (initial-state modify mod-list)
(loop for modification in mod-list
collecting (funcall modify initial-state modification)))
The problem is that I need initial-state to be the same every time it is passed t... | If the function can be destructive and you cannot do anything about it then it's clear you need to make copies of initial-state.
One possibility to avoid preconfiguring what kind of data does initial-state contains is to leave providing a copy operation explicitly a problem for the caller or to make it a generic operat... |
6,358,355 | 6,363,723 | Vertical align floats on decimal dot | Is there a simple way to align on the decimal dot a column of floats? In other words, I would like an output like the one of (vertical bars '|' are there only for clarity purpose)
(format t "~{|~16,5f|~%~}" '(798573.467 434.543543 2.435 34443.5))
which is
| 798573.44000|
| 434.54355|
| 2.43500|
| ... | I do not think that this can easily be done with format's inbuilt control characters, but you could pass your own function to it:
(defun my-f (stream arg colon at &rest args)
(declare (ignore colon at))
(destructuring-bind (width digits &optional (pad #\Space)) args
(let* ((string (format nil "~v,vf" width digi... |
6,358,556 | 6,361,525 | Parsing in Prolog without cut? | I found this nice snippet for parsing lisp in Prolog (from here):
ws --> [W], { code_type(W, space) }, ws.
ws --> [].
parse(String, Expr) :- phrase(expressions(Expr), String).
expressions([E|Es]) -->
ws, expression(E), ws,
!, % single solution: longest input match
expressions(Es).
expressions([]) --> [].
... | The cut is not used for efficiency, but to commit to the first solution (see the comment next to the !/0: "single solution: longest input match"). If you comment out the !/0, you get for example:
?- parse("abc", E).
E = [s(abc)] ;
E = [s(ab), s(c)] ;
E = [s(a), s(bc)] ;
E = [s(a), s(b), s(c)] ;
false.
It is clear that... |
6,360,737 | 6,361,018 | Generating LLVM code for 'lambda', 'define' | So I now have a fairly complete LISP (scheme) interpreter written in haskell. Just for fun I want to try to have it compile down to LLVM. Most of the code generation seems pretty straight forward, but I'm at a loss as to how to generate code for a lambda expression (kind of important in lisp ;) ) and how to manage th... | See Lennart's blog post: http://augustss.blogspot.com/2009/06/more-llvm-recently-someone-asked-me-on.html
Look at the compileFunction function. In particular, newFunction in the LLVM core: http://hackage.haskell.org/packages/archive/llvm/0.9.1.2/doc/html/LLVM-Core.html#g:23
|
6,365,334 | 6,365,579 | Lisp commenting convention | What is the Lisp convention about how many semicolons to use for different kinds of comments (and what the level of indentation for various numbers of semicolons should be)?
Also, is there any convention about when to use semicolon comments and when to use #|multiline comments|# (assuming they exist and exist on mult... | In Common Lisp:
;;;; At the top of source files
;;; Comments at the beginning of the line
(defun test (a &optional b)
;; Commends indented along with code
(do-something a) ; Comments indented at column 40, or the last
(do-something-else b)) ; column + 1 space if line exceeds ... |
6,376,638 | 6,376,935 | How do I REALLY do math with NSNumbers? (implementing a lisp in obj-c) | inspired by Clojure, and Peter Norvig
I have been trying my hand at implementing a simple Lisp in obj-c. I have many of the basics (including some cool cocoa integration similar to Clojure) working and would like to move on to arithmetic.
A little background on how I have implemented this so far: I am using a tiny clas... | Easy method: simply turn all numbers into doubles when doing arithmetic, and ignore casting and precision issues.
Another option is to use NSDecimalNumber instead of NSNumber everywhere. There's the +[NSDecimalNumber decimalNumberWithString] method that you could use for boxing, and there are also methods for perform... |
6,395,898 | 6,413,349 | Emacs: how do I replace-regexp with a lisp function in a defun? | For example I want to make all text in parenthesis, (), UPCASE. It's trivial to do the following interactively:
M-x query-replace-regexp
replace: "(\(.+?\))"
with : "(\,(upcase \1))"
Instead I want to write a defun which will do that:
(defun upcs ()
(interactive)
(goto-char 1)
(while (search-forward "(\\(.+?\\... | So this solves the problem.
(defun put-in-par (str)
(concat "(" str ")"))
(defun upcs-luke ()
(interactive)
(goto-char 1)
(while (search-forward-regexp "(\\([^\\)]+\\))" nil t)
(replace-match (put-in-par (upcase (match-string 1))) t nil)))
Thanks to BillC and Luke Girvin for help.
|
6,403,697 | 6,405,490 | What are "not so well defined problems" that LISP is supposed to solve? | Most people agree that LISP helps to solve problems that are not well defined, or that are not fully understood at the beginning of the project.
"Not fully understood"" might indicate that we don't know what problem we are trying to solve, so the developer refines the problem domain continuously. But isn't this process... | In AI (Artificial Intelligence) historically Lisp was seen as the AI assembly language. It was used to build higher-level languages which help to work with the problem domain in a more direct way. Many of these domains need a lot of 'knowledge' for finding usable answers.
A typical example is an expert system for, say,... |
6,435,595 | 6,436,323 | New SLIMV 0.8.4 install, paren matching works, indentation doesn't | I'm reinstalling everything after a hdd failure on my netbook (fresh install of Ubuntu Netbook Edition 10.04), and am trying to get the excellent SLIMV working again.
It was working fine on the previous installation, but with this one, parenthesis matching works, but auto-indenting Lisp code does not. Hitting return... |
Check that function SlimvIndent is defined by calling :echo SlimvIndent(lnum) where lnum is the line number to be indented. It should return the indentation value for the line.
Check that lisp mode is off with the :verbose set lisp? command, that also prints the location where this option was last set. It should be "n... |
6,439,972 | 6,440,525 | what is the 'cons' to add an item to the end of the list? | what's the typical way to add an item to the end of the list?
I have a list (1 2 3) and want to add 4 to it (where 4 is the result of an evaluation (+ 2 2))
(setf nlist '(1 2 3))
(append nlist (+ 2 2))
This says that append expects a list, not a number. How would I accomplish this?
| You could use append, but beware that it can lead to bad performance if used in a loop or on very long lists.
(append '(1 2 3) (list (+ 2 2)))
If performance is important, the usual idiom is building lists by prepending (using cons), then reverse (or nreverse).
|
6,474,777 | 6,475,110 | Common Lisp Backquote/Backtick: How to Use? | I am having trouble with Lisp's backquote read macro. Whenever I try to write a macro that seems to require the use of embedded backquotes (e.g., ``(w ,x ,,y) from Paul Graham's ANSI Common Lisp, page 399), I cannot figure out how to write my code in a way that compiles. Typically, my code receives a whole chain of e... | First of all, Lisp macros have "destructuring" argument lists. This is a nice feature that means instead of having an argument list (rule) and then taking it apart with (car rule) (cadr rule) (caddr rule), you can simply make the argument list ((function-name column-index value)). That way the macro expects a list of... |
6,480,053 | 6,480,923 | Modifying function; saving to new function in lisp | So I thought one of the advantages of lisp (among other languages) is its ability to implement function factories (accept functions as arguments; return new functions). I want to use this capability to make small changes to a function and save it as a new function so that if changes are made to the original function, t... | It does work in Emacs Lisp:
elisp> (defun foo (x y)
(+ x y))
foo
elisp> (fset 'newfoo
(append (lambda (x y)
(when (< x 2)
(setq x (* x 2))))
(cddr (symbol-function 'foo))))
(lambda
(x y)
(when
(< x 2)
(setq x
... |
6,480,905 | 6,541,528 | Non-blocking input in lisp | I have program that runs for long periods of time and I'd like to interrupt it but not with ctrl-c ctrl-c. I also don't want the system to wait for a keystroke every so often. Instead, if I do press a key, I want it to wrap things up and exit. I found listen and read-char-no-hang but I can't get it to work right. Here'... | CCL has multithreading, I believe. You could try spawning a worker thread in the background and have a control thread doing a blocking read, and then communicating via a special variable. The following works in Lispworks, I don't have CCL available. You'd have to translate the mp:process-run-function to whatever CCL ... |
6,486,597 | 6,489,041 | Are there any non-Lisp dialects that allow for syntactic abstraction? | As Rich Hickey says, the secret sauce of Lisp languages is the ability to directly manipulate the Abstract Syntax Tree through macros. Can this be achieved in any non-Lisp dialect languages?
| Being able to "directly manipulate the abstract syntax tree" by itself is nothing new, though it's something that very few languages have. For example, many languages these days have some kind of an eval function -- but it should be obvious that that's not manipulating the abstract syntax tree, instead, it is a manipu... |
6,494,113 | 6,494,381 | Just trying to recursively print a list, nothing prints though | I would like to go through a list (which may have nested lists) and have it evaluate to one flattened list with all of the elements. I can't even get a recursive function to evaluate to anything other than nil
(defun pl(lst)
(if (atom lst)
lst
(progn
(pl (car lst))
(pl (cdr lst)))))
I'll then c... | A function will normally only return one value, which is value of its body. If you look closely at pl you see that it is an if form, so pl either returns the value of lst or the value of progn.
The first thing I have to point out here is that the return value of a (progn ...) form is the value of its last expression, ... |
6,497,816 | 6,499,017 | python delayed execution | To implement streams as delayed lists in Lisp it's recommended to use Lisp macros.
(defmacro cons-stream (a b)
(cons ,a (delay ,b)))
(defmacro delay (expr)
`(memo-proc (lambda () ,expr)))
What would by Python and Perl way to do the same thing?
EDIT. Is it possible to use such a cool construct as streams
(define... | Perl
runrig suggested the techniques from Mark Dominus's excellent Higher Order Perl. Using the Stream module from HOP's freely available sample code, the sieve of Eratosthenes is
#! /usr/bin/env perl
use strict;
use warnings;
use Stream qw/ filter head node promise show tail upfrom /;
use subs 'sieve'; # no parens... |
6,499,388 | 6,503,109 | How can I make a string with expandable keywords in Scheme? | I'm writing a GIMP script to export layers to files. I want to provide a user-specifiable field where they can provide the format for the filenames to be exported, with tilde-character combinations for each element (ie. a file named "foo" with layers "bar" and "baz", with the output filename format being "~f-~l.png", w... | There is no standard Scheme procedure to do this. I wrote the following in-efficient but portable procedure:
(define (expand-keywords string tokens)
(let loop ((slist (string->list string))
(in-replace-mode #f)
(result ""))
(if (not (null? slist))
(let ((c (car slist)))
... |
6,505,184 | 6,531,623 | Why can't GIMP handle this script? | I have this script as an .scm in Gimp:
;MIT license.
(define (script-fu-export-layers img drw path outnameformat)
; credit to Vijay Mathew on Stack Overflow for the expand keywords function
(let ((expand-keywords (lambda(format tokens)
(let loop ((slist (string->list string))
(in-replace-mode #f)
... | This behavior is consistent with what would happen if the line endings were missing (the comments commenting out all subsequent text). Check to make sure your editor isn't doing something ridiculous like saving your file with CR line endings on Windows.
|
6,510,681 | 6,510,881 | Executes a function until it returns a nil, collecting its values into a list | I got this idea from XKCD's Hofstadter comic; what's the best way to create a conditional loop in (any) Lisp dialect that executes a function until it returns NIL at which time it collects the returned values into a list.
For those who haven't seen the joke, it's goes that Douglas Hofstadter's “eight-word” autobiograph... | This is easy. I don't want to write a solution, so instead I will -- but it'll be the crappy elisp version, which might lead to unexpected enlightenment if you'll follow through:
(defun so-function (f str)
(let (x '())
(while str (setq x (cons str x)) (setq str (funcall f str)))
(reverse x)))
To try this ou... |
6,523,396 | 6,523,520 | Scheme core language specification | I am learning my way around Scheme, and I am especially interested in how the language is constructed. I'm trying to find a nice description of the core syntax for a Scheme implementation. I don't know enough about the standards, but I assume that they all contain macro systems. If not, I'd like to read about a standar... | Although it may be a bit dry, you should read over the R5RS spec or the R6RS spec.
The docs really do not take that long to read through and you can just skim most of the sections until you need more detail. But either document does cover all of the minimal syntax required, including macros.
|
6,529,523 | 6,530,366 | Mapping Untyped Lisp data into a typed binary format for use in compiled functions | Background: I'm writing a toy Lisp (Scheme) interpreter in Haskell. I'm at the point where I would like to be able to compile code using LLVM. I've spent a couple days dreaming up various ways of feeding untyped Lisp values into compiled functions that expect to know the format of the data coming at them. It occurs t... | Do you mean, "I just don't know which [type] might be sent to the function at runtime"? It's not that the data isn't typed; certainly 1 and '() have different types. Rather, the data is not statically typed, i.e., it's not known at compile time what the type of a given variable will be. This is called dynamic typing.
Y... |
6,532,634 | 6,533,283 | Switching between auto-inserts on the fly / by context | Using emacs for multiple projects from legacy to current ones, I have to use multiple conventions, e.g. for comments or file headers. For example, I use this function to insert file headers for C++ files:
(defun mg-c-file-header()
"Inserts a c/c++ file header"
(if (boundp 'mg-auto-insert-style)
(case mg-auto-... | I use auto-insert package, together with different templates to implement this. See my config as example (+ templates)
|
6,546,834 | 6,548,692 | Install lisp on my linux machine | I use Vim as my editor. "Practical common Lisp" suggest installing Lispbox, I don't know how to use emacs, don't know how to run lisp code with that T.T after that i find lisp plugin for vim called limp.vim with a long and hard install instruction :((
Finally i installed "Clisp" and i can run lisp code with a simple c... | Install and learn the following things:
SBCL the compiler
install a binary from http://www.sbcl.org/platform-table.html Once your used to it, compile from source and keep the source around. This way you can easily jump to the definitions of functions of SBCL with M-. in Emacs.
Emacs
watch this screencast to see som... |
6,548,041 | 6,549,772 | lisp macro expand with partial eval | I have following code which confuse me now, I hope some can tell me the difference and how to fix this.
(defmacro tm(a)
`(concat ,(symbol-name a)))
(defun tf(a)
(list (quote concat) (symbol-name a)))
I just think they should be the same effect, but actually they seem not.
I try to following call:
CL-USER> (... | First, note that
`(concat ,(symbol-name a))
and
(list (quote concat) (symbol-name a))
do the exact same thing. They are equivalent pieces of code (backquote syntax isn't restricted to macro bodies!): Both construct a list whose first element is the symbol CONCAT and whose second element is the symbol name of whateve... |
6,591,043 | 35,263,420 | how to answer yes or no automatically in emacs | I binded function semantic-symref to key C-c C-r like this:
(global-set-key (kbd "C-c C-r") 'semantic-symref)
everytime I pressed C-c C-r, it prompted:
Find references for xxxxx? (y or n)
How can I answer it automatically? I tryed using lambda function like this, but failed
(global-set-key (kbd "C-c C-r") (lambda() ... | The answer by @huitseeker is quite neat and effective. After four years, with flet and defadvice being obsolete, I wrote the following functions to answer yes automatically. Maybe it's useful for someone.
(defun my/return-t (orig-fun &rest args)
t)
(defun my/disable-yornp (orig-fun &rest args)
(advice-add 'yes-or... |
6,638,885 | 6,638,940 | Column of buffer position in Emacs Lisp? | In Emacs Lisp, if you have a buffer position stored in a variable, how do you find what column it is in?
| Check out documentation for columns and for save-excursion.
(save-excursion (goto-char pos) (current-column))
|
6,645,428 | 6,645,527 | LISP SICP Video Lecture 2a Average Damp Question | In the following code, I am trying to understand how the variable whatami gets its value. In following the logic, I see that the procedure (lambda (y) (/ x y)) is the parameter that I am passing to the method average-damp, and is represented within that method as the variable f. It seems as though (/ x y) and (averag... | The average-damp procedure takes a procedure as its argument and returns a procedure as its value. When given a procedure that takes one argument, average-damp returns another procedure that computes the average of the values before and after applying the original function f to its argument. It's inside the fixed-poin... |
6,694,695 | 6,697,438 | Most idiomatic way of replacing a list subsection in Lisp | What is the best way of replacing a specific subsequence of a list?
Say I wanted to replace the subsequence (m e) with an i:
(sub-substitute 'i '(m e) '(y o u a n d m e))
⇒ (Y O U A N D I)
Nota bene: This is very similar to the function substitute:
(substitute 'u 'i '(i are hungry))
⇒ (U ARE HUNGRY)
| I'm not sure if this is homework, and it's a legitimate practical question, so I'll give you a simple solution your teacher won't expect and will be curious about, if you have just been introduced to simple list processing. It works for sequences (vectors, lists, strings), and uses a few of CL's sequence functions:
(de... |
6,702,239 | 6,705,246 | Lispy dialects with good multi-dimensional array programming support | Are there any Lisp or scheme dialects that have good support for Array and linear algebraic manipulations. By good support I do not mean interfaces to BLAS/LAPACk, but efficient array primitives in the language itself. I would consider it efficient if it can hold its own against Numpy, say. I have heard Stalin to be ve... | Arrays in standard Common Lisp can be multi-dimensional.
The Array Dictionary describes the available operations.
CL-USER 12 > (defparameter *a* (make-array '(3 2 4) :initial-element 'foo))
*A*
CL-USER 13 > *a*
#3A(((FOO FOO FOO FOO) (FOO FOO FOO FOO))
((FOO FOO FOO FOO) (FOO FOO FOO FOO))
((FOO FOO FOO FOO) (... |
6,712,654 | 6,930,267 | Circumflex accent before c IN LISP | I'm studing lisp and I found this: (zoom in)^C ^C , but the text don't explain it, and I searched "^C ^C" in other places but didn't found anything. Can someone here help-me?
(I'm studying english yet, sorry if I wrote anything wrong)
| "^C^C" is not AutoLisp; that would be for/is the macro language for menus and such.
Caret-C does "mean" CTRL-C.
What it does in the macro language:
^c means: cancel
^c^c means: cancel twice.
In AutoCAD we hit the ESC key (twice to cancel a command). The ^C^C is "good practice". -i.e. Before we issue or start a new co... |
6,720,954 | 6,721,021 | flet equivalent of let*? | There is not an flet* for flet as there is let* for let that I can find in emacs lisp -- so are any of these four alternatives more idiomatic for defining a function used multiple times by a single function defined by flet? In this example, add1 is the function that I want to reused within add1twice but not used outsid... | Though not too clear in the documentation for flet, its macroexpansion reveals that it tolerates sequential binding:
(defun add2 (x)
(flet ((add1 (x) (1+ x))
(add1twice (x)
(add1 (add1 x))))
(add1twice x)))
The documentation mentions establishing "let-style bindings"—not let*—but the definiti... |
6,737,684 | 6,738,781 | Trouble grabbing lisp input from the web using hunchentoot and sbcl | A lisp question here. I've been slowly learning lisp over the last couple of months and have ran into a problem when trying to grab input from a web browser vs. grabbing input from a REPL.
The specific problem is when trying to evaluate this code:
Assume sexp is '(look north).
(member (car sexp) '(look walk pickup dro... | You need to make sure what the input is you get. Is it a symbol? Common Lisp has functions like TYPE-OF, INSPECT and DESCRIBE to get more information about data.
* (describe 'north)
COMMON-LISP-USER::NORTH
[symbol]
* (type-of 'north)
SYMBOL
The next question is: if it is a symbol, in which package is it?
* (symb... |
6,743,066 | 6,743,167 | How to break out of an infinite loop in emacs lisp ? (environment: emacs) | I tried using ctrl-c then :a
But It doesn't work here.
My code is like:
(defun game-repl()
(loop (print (eval (read)))))
then I run
(game-repl())
look()
| (require 'cl)
(loop (setq x (read))
(if (eq x 'exit)
(return)
(print (eval x))))
|
6,752,305 | 6,753,308 | How to get C-x C-e to display only decimal and hexadecimal? | This is a follow-up to How to get C-x C-e to display the result in octal and hexadecimal by default?
Is there a way to get C-x C-e to to display the result in decimal and hexadecimal only?
e.g.
(+ 40 2)
should produce
42 (#x2a)
instead of
42 (#o52, #x2a, ?*)
| You just need to rewrite/tweak the routine that creates the printed format for this. Add the following to your .emacs and you'll be good to go.
(require 'simple)
(defun eval-expression-print-format (value)
"Format VALUE as a result of evaluated expression.
Return a formatted string which is displayed in the echo are... |
6,758,308 | 6,758,722 | Memory allocation in Lisp | > (cons 2 3)
(2 . 3)
The Lisp environment needs to allocate only a single cons cell to connect the two items.
Above is from the Lisp book "Land of Lisp". I don't understand why this pair is only located in a single cons cell. What does the memory look like for this data?
| A cons cell always holds two values, called car and cdr:
+-----+-----+
| car | cdr |
+-----+-----+
To represent a cons cell, Lisp has the "dot notation":
(car . cdr)
The function cons creates such a cons cell from its two arguments:
(cons 1 2)
=> (1 . 2)
which can be thought of like this:
+-----+-----+
| 1 | 2 |... |
6,787,036 | 14,974,201 | Using asdf can I load a system providing only previously made FASLs | I have a development machine and a production machine which are identical (Copy of a vm image).
I want to deliver the application to the production machine along with the asd file but I don't want to deliver source code. I have thought of 2 ways:
1.Having asdf load a system by providing only the FASL files in the prod... | As of February 2013, ASDF 3 now offers a way to do exactly what you want, using FASL-OP and PRECOMPILED-SYSTEM.
|
6,788,212 | 6,844,304 | Javascript to clojure | I am aware of ClojureScript - possibility to compile clojure code to javascript, but is it possible to do the reverse, take some subset of javascript code and translate it back to clojure?
| Yes, although it wouldn't really make sense.
Clojure -> JavaScript makes sense because:
JavaScript is the only suitable target language for a wide class of web applications
It allows effective use of the Google Closure compiler for whole program optimisation
Clojure is a great "source" language because of its macro fe... |
6,794,230 | 6,794,259 | Using "map" in scheme language without procedure? | I have a question about the usage of "map" - Here is the piece of code,
(for-each
(lambda (x) (if (member x sb-id-list) (set! si-exists? #t)))
(append (map thread-id sb1-thread) (map thread-id sb2-thread)))
First of all, I'm sure this code is working correctly - It's taken from the source code of a solver. Wha... | My assumption is that "thread-id" is some sort of procedure.
|
6,827,819 | 6,830,511 | Treating the values from a list of slots and strings | I want to do a macro in common lisp which is supposed to take in one of its arguments a list made of slots and strings. Here is the prototype :
(defclass time-info ()
((name :initarg name)
(calls :initarg calls)
(second :initarg second)
(consing :initarg consing)
(gc-run-time :initarg gc-run-time)))
(def... | I would base this on format. The idea is to build a format string
from your arg-list.
I define a helper function for that:
(defun make-format-string-and-args (arg-list)
(let ((symbols ()))
(values (apply #'concatenate 'string
(mapcar (lambda (arg)
(ctypecase arg
... |
6,865,142 | 6,865,187 | Lisp, cons and (number . number) difference | What is the difference between
(cons 2 3)
and
'(2 . 3)
in Lisp?
| '(2 . 3) is a dotted pair.
(cons 2 3) creates a dotted pair too. So these should evaluate to the same thing.
So one is a literal for a dotted pair, the other one creates a dotted pair.
|
6,882,502 | 6,882,567 | how do I use a function as a variable in lisp? | I'm trying to write a function which checks if every element in the list x has property a, so I wrote:
(defun check (a x)
(if (listp x)
(eval (cons 'and (mapcar #'a x)))))
but it doesn't work. (Basically I want a to be the name of a function, say blablabla, and in the body of the check-function, by #'a I want to... | There is no need to use the sharp-quote syntax here. Its purpose is to use a function name in a variable position, but a is a variable already. Just write a instead of #'a.
|
6,883,184 | 6,883,346 | Why the function/macro dichotomy? | Why is the function/macro dichotomy present in Common Lisp?
What are the logical problems in allowing the same name representing both a macro (taking precedence when found in function position in compile/eval) and a function (usable for example with mapcar)?
For example having second defined both as a macro and as a fu... | I think that Common Lisp's two namespaces (functions and values), rather than three (macros, functions, and values), is a historical contingency.
Early Lisps (in the 1960s) represented functions and values in different ways: values as bindings on the runtime stack, and functions as properties attached to symbols in the... |
6,887,903 | 6,894,245 | invoking functions defined by flet in another function | I have a collection of functions defined in foo that I want to also want to use in bar. I have these functions defined in foo because I want foo to be self-contained -- otherwise I know that I can define these functions externally (globally) to be accessible to foo and bar and other functions, or define both foo and ba... | Emacs Lisp has dynamic binding. This is different from the lexical binding used by pretty much all other Lisps. For example, if you try to do the following in Common Lisp, you will get an error message saying that FOO is not defined:
(defun bar ()
(foo 10))
(flet ((foo (x) (1+ x)))
(bar))
In Emacs Lisp, however, ... |
6,898,710 | 6,904,563 | Emacs/AUCTeX: Rewriting the Okular-make-url function to work with new synctex (full path + "./") syntax | The basic problem:
Need to write an Emacs lisp function that handles forward search from a TeX file in Emacs to a line in the PDF output corresponding to the current position within the TeX file. Synctex allows for this sort of operation. However, synctex files are referenced differently as of the new version of TeXliv... | The following seems to work:
Update to latest version of Okular (v0.13) - this may or may not be necessary.
Define new expander to get current directory of TeX source:
Go to "Customize AUCTeX" choose "TeXCommand" then go to "TeX Expand List" and add one:
Add:
Key: %(dir)
Expander: (lambda nil default-directory)
In... |
6,952,369 | 6,952,408 | Java-Mode Argument Indenting in Emacs | My java-mode in emacs wants to indent function arguments like this:
someLongFunctionName(
argumentNumberOne,
argumentNumberTwo,
argumentNumberThree,
argumentNumberFour
);
There are two problems here. Firstly, it wa... | Try this
(defun my-indent-setup ()
(c-set-offset 'arglist-intro '+))
(add-hook 'java-mode-hook 'my-indent-setup)
From http://www.emacswiki.org/emacs/IndentingC
|
6,954,347 | 6,954,900 | How to implement the Observer Design Pattern in a pure functional way? | Let's say I want to implement an event bus using a OO programming language.
I could do this (pseudocode):
class EventBus
listeners = []
public register(listener):
listeners.add(listener)
public unregister(listener):
listeners.remove(listener)
public fireEvent(event):
for (lis... | Some remarks on this:
I am not sure how it is done, but there is something called "functional reactive programming" which is available as a library for many functional languages. This is actually more or less the observer pattern done right.
Also the observer pattern is usually used for notifying changes in state, as i... |
6,955,544 | 6,955,737 | How to overcome the lack of local variable for emacs lisp closure | I'm now studying Emacs Lisp from the reference manual and Common Lisp from a LISP Book.
from the Common Lisp book
>> (setf power-of-two
(let ((previous-power-of-two 1))
#'(lambda ()
(setf previous-power-of-two
(* previous-power-of-two 2)))))
>> (funcall power-of-two)
2
>> (funcall ... | Update:
By now, Emacs 24 has been officially released, and it supports lexical binding without using lexical-let, when the buffer-local variable lexical-binding is non-nil. See also M-: (info "(elisp) using lexical binding") and pokita's answer.
You can use lexical-let from the Common Lisp Extensions (the "CL package"... |
6,963,603 | 6,969,368 | Does adding f-exprs simplify the implementation of macros from fundamental expressions in LISP? | This guy reckons that adding fexprs to LISP dramatically simplifies the implementation of the language in scheme.
Here we see how macros would be implemented using MacCarthy's LISP.
My question is - does adding f-exprs simplify the implementation of macros in LISP?
| I'm that guy. :)
Fexprs, as in the Kernel language, dramatically simplify the language - Kernel has only three built-ins: $define! (for adding a new binding to an environment), $if (the usual), and $vau (similar to lambda, but doesn't evaluate its arguments).
Furthermore, macros (fexprs) may be used as functions can - ... |
6,980,846 | 6,981,490 | Emacs php-mode font-lock properties are not applied to certain chars | For example variable dollar signs.
php-mode.el line 1087:
'("\\$\\(\\(?:\\sw\\|\\s_\\)+\\)" (1 font-lock-variable-name-face)) ; $variable
If I'm not mistaken the regexp should match $variable including the dollar sign.
Now, i'm trying to figure out why isn't the font-lock property applied to the dollar sign also.
In t... | The 1 in there means match the first capture group denoted by (escaped) parens. The $ is outside that capture group. So it could either be moved inside, or change the 1 to a 0 which means use the entire regexp.
|
6,986,880 | 6,986,934 | In lisp, how do I use the second value that the floor function returns? | When I do (floor 4 3) I got
1
1/3
But how do I use that 1/3?
| You can for instance bind it to a variable using multiple-value-bind.
(multiple-value-bind (quot rem)
(floor 4 3)
(format t "The remainder is ~f~%" rem))
Another possibility, if you're only interested in one non-primary value, is nth-value.
(format t "The remainder is also ~f~%" (nth-value 1 (floor 4 3)))
For r... |
7,023,485 | 13,522,660 | how to setup linedit support CCL in initial file? | I use quicklisp to install linedit, http://www.cliki.net/Linedit say "Should work on Lispworks and OpenMCL/CCL." how to write $HOME/.ccl-init.lisp?
| In the meantime, linedit has been made to work with ccl (linedit 0.17.5 with ccl 1.8).
I added this to .ccl-init.lisp:
(when (interactive-stream-p *standard-input*)
(ql:quickload "linedit")
(funcall (intern "INSTALL-REPL" :linedit)))
|
7,046,950 | 7,047,170 | Lazy Evaluation vs Macros | I'm used to lazy evaluation from Haskell, and find myself getting irritated with eager-by-default languages now that I've used lazy evaluation properly. This is actually quite damaging, as the other languages I use mainly make lazily evaluating stuff very awkward, normally involving the rolling out of custom iterators ... | Lazy evaluation can substitute for certain uses of macros (those which delay evaluation to create control constructs) but the converse isn't really true. You can use macros to make delayed evaluation constructs more transparent -- see SRFI 41 (Streams) for an example of how: http://download.plt-scheme.org/doc/4.1.5/htm... |
7,052,963 | 7,053,300 | Are Project-Specific DSLs a Liability? | I've forked this question from a similar question I made in a comment I made to one of the many great answers I recieved. I was originally asking about AST macros, which mostly provoked very detailed and thoughtful responses from Lispers. Thanks.
Lazy Evaluation vs Macros
The question I made in a comment was whether pr... | There are of course arguments in favor of DSLs and against them, and there's of course a vague line between "a library" or "an API" and "a DSL". That part you've covered well in the question, so I'll avoid those subjective points and focus on just the question of whether they're a liability.
A good project to consider... |
7,066,604 | 7,067,079 | Is it possible to dynamically add one more super class in existing class | In Common-Lisp CLOS
Is it possible to dynamically add one more super class
in existing class.
Update:
I wanted to defined defassoc kind of macro that will associated some behaviour
with method/function using same argument
e.g.
(defassoc (gname (s (g group)))
((name1 (name ((corresponding-task task g) s)))
(rec... | Yes, it's possible. The easiest way would be to simply redefine the class. You do that by issuing another call to DEFCLASS. If you want to do more complicated things, you have to resort to the MOP (MetaObject Protocol). Essentially everything you'd ever want to do is possible using the MOP, but I would need more detail... |
7,072,980 | 7,074,878 | How do you compile macros in a Lisp compiler? | In a Lisp interpreter, there can easily be a branch in eval that can expand a macro, and in the process of expanding it, call functions to build up the expanded expression. I've done this before using low-level macros, it's easily concieved.
But, in a compiler there aren't any functions to call to build up the expanded... | How this works is very different in various Lisp dialects. For Common Lisp it is standardized in the ANSI Common Lisp standard and the various Common Lisp implementations differ mostly whether they use a compiler, an interpreter or both.
The following assumes Common Lisp.
EVAL is not the interpreter. EVAL can be implem... |
7,074,122 | 7,079,572 | Possible to reset user environment in Scheme REPL? | Scheme newbie question-
Is there a way for me to reset my current REPL environment (i.e. the default user environment) without quitting and restarting my REPL? Basically I'd like a way to wipe out my current environment so that none of my previous defines are in effect. This is using GNU/MIT Scheme.
If this is impossib... | I think that this is implementation specific, but in MIT Scheme you can clear the REPL environment with:
1 ]=> (ge (make-top-level-environment))
The function (ge [environment]) "Changes the current REP loop environment to [environment]." and the function make-top-level-environment "returns a newly allocated top-level... |
7,114,797 | 7,126,161 | Is there a way to link my GCL Lisp file with a separate C++ program on Windows? | I have looked for some info on this and haven't found anything very helpful.
Background
What I have is GNU Common Lisp installed. I can create a Lisp file and compile it to a .o object file using the command:
gcl -compile <my lisp filename>
Once I have that .o file I use the command (using MinGW):
g++ -o myProgram.exe... | First of all, I'm not sure it is possible to call GCL compiled functions from C++ at all. Compare definitions of your CL's and C++'s functions:
(defun fib (x) ...)
and
int fib(int)
Second function is strictly typed, while first one takes and returns any object. So, what function should g++ search for in your temp.o ... |
7,134,733 | 7,134,870 | Tree Search Saving Execution State | I have a tree,
A
/ \
B C
/\ \
D E F
represented as a list,
(A (B (D) (E)) (C (F)))
It actually is a very large tree so what I would like to do is start the search if I can't find what I am looking for in say 100 ms save state, return, do some house keeping and then call search again and contin... | Threading is likely to be the easiest solution, but it's not very difficult to manage it yourself on a single thread. "Simulation" environments that only give you 100ms often don't allow any new threads, so this is an alternative.
The basic idea is to create a closure representing the work that needs to be done to fini... |
7,138,331 | 7,138,372 | Is there a way to convert a list to a set in Scheme? | I want to test for equality amongst lists, but I really only care that the members are the same, not the ordering. Are there any simple operators to check for this?
A rather trivial example
(my-equal? (a b) (b a))
Should return #t.
Obviously, this particular example can easily be done by checking for both lists and t... | If your implementation has SRFI 1 available, there is lset= to achieve what you want:
Set operations on lists
|
7,165,301 | 7,165,338 | How to assign multiple constants within one macro call | I want to assign multiple constants within one macro call. But the code below only assigns the last constant, the constants which where defined before are not available.
; notes.lisp
(defconstant N_oct0 0)
(defmacro N_defheight(_oct _note _offset)
`(defconstant ,(read-from-string (concatenate 'string _note _oct))
... | You need to expand to a progn form
(defmacro N_octave(_octave)
`(progn
(N_defheight ,_octave "c" 0)
(N_defheight ,_octave "c#" 1)
(N_defheight ,_octave "des" 1)
(N_defheight ,_octave "d" 2)
(N_defheight ,_octave "d#" 3)
(N_defheight ,_octave "es" 3)
(N_defheight ,_octave "e" ... |
7,211,615 | 7,212,097 | Reload .emacs for all active buffers | A question already has been asked how to reload a .emacs file after changing it.
The proposed solutions were to use M-x load-file or M-x eval-region RET on the changed region.
Neither of these solutions affect other open buffers for me. Is there a way to reload the .emacs file for all open buffers?
I should also note t... | Your .emacs file is a global configuration that gets evaluated once only. It does not get applied to each buffer individually.
How you actually achieve what you want is really going to depend on what those .emacs changes are. Some elisp will only take effect the first time it is evaluated; or when a buffer changes majo... |
7,211,731 | 7,211,766 | Writing recursive enumeration function in Scheme | I'm writing a recursive enumeration function, and I'm having a simple error somewhere.
Here's what should happen:
(enum 1 0.5 2.5)
> (1.0 1.5 2.0 2.5)
Here's the code:
(define enum
(lambda (start step stop)
(if (not (<= stop start))
(cons start (enum (+ start step) step stop))
('(... | I believe that your problem is in the line
('(stop))
I think you have the right idea that you want to stop executing the recursion once you've hit the end, but this isn't the way to do it. Because you have put this in double parentheses, this is interpreted as "evaluate 'stop', then try calling it as a function." Ho... |
7,224,823 | 7,224,914 | Where to learn how to practically use Common Lisp | I am a C++ programmer trying to learn Common Lisp. I have looked at some books like Land of Lisp and read numerous online articles about the various virtues of Lisp. However, I need some advice.
Almost everything I have read about Common Lisp has to do with how amazing it is and how amazingly fast you can get stuff don... | I would propose reading 'Practical Common Lisp', since it already answers some of your questions.
There are probably three to four books you should read:
Basic introduction to Common Lisp: Common Lisp: A Gentle Introduction to Symbolic Computation
Practical introduction to Common Lisp: Practical Common Lisp
More advan... |
7,271,312 | 7,275,058 | Change Emacs window appearance when it loses focus | When I program I use two screens with Emacs on both with two buffers split in each window totaling 4 open source files on screen at any one time.
I switch between buffers with C-x b and between Windows with Alt-TAB. I change the appearance of buffers when I switch between them by defining different faces for mode-line ... | It may depend on your window manager and how it manages multiple windows, or frames, in emacs parlance. The code below works like a champ in fvwm but not always in gnome.
I map a keystroke, C-o, to go between frames, this helps when you want to go to the other frame but an alt-tab would take you through a number of su... |
7,276,234 | 7,276,311 | What is happening with this Common Lisp code? | I've written the following bit of code to simulate rolling a six-sided die a number of times and counting how many times each side landed up:
(defun dice (num)
(let ((myList '(0 0 0 0 0 0)))
(progn (format t "~a" myList)
(loop for i from 1 to num do
(let ((myRand (random 6)))
... | This is a result of using a constant list in the initializer:
(let ((myList '(0 0 0 0 0 0)))
Change that line to:
(let ((myList (list 0 0 0 0 0 0)))
and it will behave as you expect. The first line only results in an allocation once (since it's a constant list), but by calling list you force the allocation to occur ... |
7,278,843 | 7,279,138 | Define n functions at once in Lisp | Suppose I want to do the following:
(loop for i from 1 to n do
(defun ith(lst)
(nth i lst)))
Apparently what I really want to do is the following:
(defun 1th(lst)(nth 1 lst))
(defun 2th(lst)(nth 2 lst))
(defun 3th(lst)(nth 3 lst))
(defun 4th(lst)(nth 4 lst))
......
(defun 100th(lst)(nth 100 lst))
How can ... | Here you go. Note that |1th| would return the second value:
(defmacro make-nths (n)
`(progn
,@(loop for i from 1 to n
collecting `(defun ,(intern (format nil "~ath" i)) (list)
(nth ,i list)))))
As Xach pointed out in the comments, macrolet might be preferable here, since ... |
7,279,721 | 7,286,868 | Running Emacs ispell command doesn't ask confirmation to save to private dictionary | Everytime I run ispell-buffer and add things to the private dictionary. It asks me confirmation whether I want to save it or not at the end. Can I turn this off?? So it doesn't ask me the confirmation and just automatically saves it.
Then on a side note in addition to that. After I add something to the personal diction... | Added
(setq ispell-silently-savep t)
to the .emacs file.
Rupert's answer let me know the function to set. Seems when doing this that it also solves problem 2 if you are running it on that word. If you run it on a region the red underline still remains.
|
7,279,974 | 7,280,613 | Modify Alt+f in Emacs for tex-mode | Alt+f in emacs when writing in tex mode seems to not include the . as part of the word. So how do I modify the alt+f behavior to remain the same exact when going forward if there is punctiation to include that as part of the word.
I have a separate file that loads for when writing in tex so I will just throw it in ther... | The following code should work for you:
(defun unpunctuate-syntax (str)
"Make the characters of the given string word characters."
(let ((st (copy-syntax-table (syntax-table))))
(dotimes (n (length str))
(modify-syntax-entry (elt str n) "w" st))
(set-syntax-table st)))
(defun dots-are-not-punctuation... |
7,293,835 | 7,305,723 | Navigating top-level Lisp/Clojure forms in Vim | I use Vim for Clojure development. I'd like a movement key or mapping that will jump through the top-level forms in the buffer. { and } are close, but stop if there's a blank line in the middle of the form. slimv-paredit's ( and ) move within a top-level forms. Here's an example:
(def foo :bar)
(defn plus [x y]
(+ x... | I have added mappings [[ and ]] for moving to the previous/next defun in Slimv's paredit.vim. Please fetch it from the Slimv repository.
|
7,295,016 | 7,295,575 | Clojure Method Missing | Does anybody know how to implement method_missing (à la Ruby) in Clojure?
E.g.
(defn method_missing [name & args]
(foo name args))
It would be very useful for a DSL, if used correctly.
Thanks in advance!
| In Ruby, method_missing is one of the primary constructs for metaprogramming. It's tightly bound to Ruby's object oriented structure, dynamically creating methods in a class from 'metaclasses'. This can be done because in Ruby classes are objects too.
Since Clojure is a functional language, mimicking this Rubyism makes... |
7,334,281 | 7,349,752 | Make an arbitrary function safe to run? | I'm writing the docs of my program online, in a wiki, and my intent is to rip that content from the program itself, either from time to time or on demand.
For extra leetness, it would be cool to the get the display functions themselves online, but this I cannot do unless I'm assured that they are safe to run, ie, they... | It sounds like you want to be able to run your elisp code in a sandbox. A bit of googling lead me to sandbox.el. I haven't tried it, but it might be a good place to start.
|
7,356,894 | 7,356,958 | Problems with Nth in common lisp | I'm trying to write a function that can calculate GPA. Now I can do limited calculation(only 3 ),but I stuck on how to calculate more , without using loop or recursion (that's the requirement of subject) how to expend nth function? like: (nth n) ,if so ,is that mean i need to write a lambda expression? As an newbie, I... | If you're using nth to traverse a list, you're doing it wrong. In this case, you might want to write a summing function:
(defun sum (items)
(reduce #'+ items))
|
7,366,093 | 7,366,754 | A prototyping language with the ability to be fast | as an engineering student with a strong mathemathical background, i dealing some problems like this at university:
(numerical) Simulations
AI Problems
Robotics
Control Systems
and some more
as you can see some are just numerical ones, others have to process some kinds of symbols.
currently i'm working with java, but ... | Common Lisp using SBCL is pretty fast if you take the time to make it fast.
Why does this fit what you want?
symbolic computations
good number handling
compiles to native on demand by default.
|
7,368,882 | 7,413,297 | How to replace the number in a nested list with symbols? | It seems that I have to make it in detail; it's my homework. I don't
want to copy the code written by you. I'm a newbie; what I'm trying
to learn is how to decompose a subject to single pieces, and then
focus on what function should I use to solve the problem. It's a
little hard to finish these problems by my own, b... | Okay roccia, you have posted your answer. Here comes mine hacked in a few minutes, but it should give you some ideas:
First let's start with the data:
(defparameter *storms2004*
'((BONNIE 65)
(CHARLEY 150)
(FRANCES 145)
(IVAN 165)
(JEANNE 120)))
(defparameter *storm-categories*
'((39 73 tropical-... |
7,369,182 | 7,369,355 | Clojure macro throws "CompilerException java.lang.IllegalStateException: Var clojure.core/unquote is unbound" when called | I'm trying to write a clojure macro that lets me call a function and retrieve the arguments from a map/struct using the provided key values such as:
(with-params {:apple 2 :banana 3 :cherry 7} + :apple :banana)
;; 5
but when I try to use the macro that I wrote:
(defmacro with-params [s f & symbols]
`(~f ~@(ma... | The reason that `(~f ~@(map ~s ~symbols)) doesn't work is that the compiler chokes on the unnecessary unquote (~) inside the unquote-splicing (~@). The unquote-splicing unquotes the outer syntax-quote (`), so the inner two unquotes don't have any matching syntax-quote, which is why you were getting the "unbound" error.... |
7,369,307 | 7,369,373 | How can I compare strings the user has entered in? | I want to compare user input from READ with a string, like so:
CL-USER 36 > (equalp (read) "same")
same
NIL
However, as you can see, even though I type in "same," EQUALP says my input and the string are different. How can I compare these two?
| You can use read-line for this:
CL-USER> (equalp (read-line) "same")
same
T
read would return a symbol:
CL-USER> (type-of (read))
same
SYMBOL
From the Hyperspec:
read parses the printed representation of an object from input-stream
and builds such an object.
You just want to read a string, whereas read parses the... |
7,375,960 | 7,376,154 | "is not of type LIST" error | I am doing Exercise 14.11 in "A Gentle Introduction to Symbolic Computation," and wrote the following function:
(defmacro compile-machine (nodes)
`(progn ,@(mapcar #'compile-node nodes)))
When calling (compile-machine *nodes*), where *nodes* is a list of NODE structures, I get the following error:
Error: *NODES* is ... | The value of *NODES* is a list, but itself it is a symbol.
|
7,376,994 | 7,402,304 | draw a polygon over closed polylines | i try to describe this problem well with my humble English skills :
i have closed blocks on my dwg file, these blocks are consist of many Polylines which are joined together but they are not uni-body (integrated), all i want is a lisp to draw a polygon over this block and create a uni-body block. is there any way aroun... | Assuming that:
when you say "joined" you mean their ends are touching,
when you say "uni-body" you actually mean "joined" in the AutoCAD sense,
then try the following:
(defun convert_block_to_polyline (block / old_entlast new_entlast curr polylines_set)
(setq old_entlast (entlast))
(command "explode" block)
(... |
7,377,878 | 7,378,454 | Trouble with load Lift package | When I try load Lift package through emacs-slime.
(load "/home/user/lib/lift")
I catch the next error
; compiling (LOAD "/home/user/lib/lift");; swank:close-connection: encoding error on stream
#<SB-SYS:FD-STREAM
for "socket 127.0.0.1:36328, peer: 127.0.0.1:59724"
... | From the CL spec, LOAD is used for loading Common Lisp source or compiled files. I'm guessing that /home/user/lib/lift is a directory on your system, and that's why LOAD isn't working.
You'll probably have the most luck if you install LIFT using Quicklisp, then load the library like it says in the LIFT User's Guide:
(i... |
7,381,491 | 7,381,562 | Use of Labels in Common Lisp | In this question on code review I have been told to use labels instead of defun. I have looked on the internet, but I couldn't find any way to use it and still keep my code the way it is.
How could I use labels in my code?
| (defun example ()
(let ((a 0)
(f nil))
(macrolet ((next (state)
`(setf f (function ,state))))
(labels ((init ()
(setf a 0)
(next inc))
(inc ()
(incf a)
(next inc)
(when (> a 5)
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.