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
1,971,349
1,971,376
elisp: Is there a way to get the name of the current .el module (like __FILE__ in C)?
At the top of my elisp module, I want to do something as simple as: (message (concat "Loading " (expand-file-name (current-elisp-module) ".")))
You can use the variable load-file-name, which is set by the function load, documented as follows: Full name of file being loaded by `load'. As elaborated in the manual: When Emacs is in the process of loading a file, this variable’s value is the name of that file, as Emacs found it during the search described earli...
1,986,961
1,987,053
How is the `*var-name*` naming-convention used in clojure?
As a non-lisper coming to clojure how should I best understand the naming convention where vars get a name like *var-name*? This appears to be a lisp convention indicating a global variable. But in clojure such vars appear in namespaces as far as I can tell. I would really appreciate a brief explanation of what I shou...
It's a convention used in other Lisps, such as Common Lisp, to distinguish between special variables, as distinct from lexical variables. A special or dynamic variable has its binding stored in a dynamic environment, meaning that its current value as visible to any point in the code depends upon how it may have been bo...
1,987,883
1,987,904
Why does this script-fu not work?
(define (script-fu-create-camo image colA colB)) (script-fu-register "script-fu-create-camo" "Camoflauge" "Creates a camoflauge pattern on an image" "Jeffrey Aylesworth <jeffrey@aylesworth" "Copyright (c) 2009 Jeffrey Aylesworth" "2009/12/31" "" SF-IMAGE "Image" 0 SF-COLOR "Colour ...
I created a few script-fu scripts which I used on my mac. I always placed them in: /Applications/Gimp.app/Content/Resources/share/Gimp/2.0/scripts/ And on my register I would prepend the "<Image>/Filters/Render" with an underscore, so _"<Image>/Filters/Render" Hope this helps, been a while since I was messing with thi...
1,994,075
2,058,388
Processing text with elisp
Since I've converted to the Church of Emacs, I've been trying to do everything from inside it, and I was wondering how to do some text processing quickly and efficiently with it. As an example, let's take this list that I was editing some minutes ago on org-mode. ** Diego: b QI ** bruno-gil: b QI ** Koma: jo ** um: rs...
This is my second attempt. I wrote a little macro and some functions to deal with such data. (defun better-numberp (s) (string-match "^ *[0-9.,]* *$" s)) (defmacro awk-like (&rest args) (let ((arg (car (last args))) (calls (mapcar #'(lambda (l) (cond ...
1,997,838
1,997,864
What are the good "rich" IDEs for Lisp?
What are the good "rich" IDEs for Lisp? To clarify by "rich" I mean it should have a good look-up reference, auto complete, auto inclusion, checking of various sorts, some kind of compilation support, version management, REPL, etc. I have reviewed some of the previous questions/answers (Such as What’s a good Common L...
Lispworks. A friend of mine bought a copy himself to develop Lisp programs in his sparse time. (He is very experienced in Lisp) Lispworks also has a free personal edition.
1,998,835
1,999,140
How do I fix a broken Lisp directory path for Emacs?
I installed a new version of emacs (new for me). I didn't want to overwrite the stock copy so I put it in a group-readable directory ~admin/sw. I point my $PATH there and I'm able to pick it up, but when I run ~admin/sw/bin/emacs I get a whole bunch of warnings and errors: Warning: arch-dependent data dir (/usr/local/l...
Rather than make install prefix=~admin/sw try: ./configure --prefix=~admin/sw make make install This may require an absolute path.
2,000,910
2,001,266
How to create data structure in Tcl?
I am translating some lisp code to Tcl and wonder if there is anything like lisp's defstruct in Tcl for creating data structures? If nothing is built into Tcl, what extension packages to Tcl would you recommend that can be used in a commercial application. Thanks. -William
Consider using dictionaries, which work more or less like a hashmap. You can set the key/value pairs much like you would any other structure.
2,001,138
2,001,797
How to create dynamical scoped variables in Python?
I am translating some code from lisp to Python. In lisp, you can have a let construct with the variables introduced declared as special and thus having dynamic scope. (See http://en.wikipedia.org/wiki/Dynamic_scope#Dynamic_scoping) How can I do likewise in Python? It seems the language does not support this directly,...
I feel Justice is plain right in his reasoning here. On the other hand -- I can't resist implementing proof of concept for still another programing paradigm "unnatural" to Python -- I simply love doing this. :-) So, I created a class whose objects'attributes are scopped just like you require (and can be created dynam...
2,018,008
2,018,220
Help understanding Continuations in Scheme
I have been working alongside The Little Schemer to learn Scheme and using PLT-Scheme for my environment. The Little Schemer has helped me tremendously with recursion (it is straightforward for me now) but I'm stuck on a portion of the book that introduces "collectors" and calls the function as a whole a continuation. ...
Try something simpler to see how this works. For example, here's a version of a list-sum function that receives a continuation argument (which is often called k): (define (list-sum l k) (if (null? l) ??? (list-sum (cdr l) ???))) The basic pattern is there, and the missing parts are where the interesting thi...
2,018,208
2,024,268
Problem Installing Lispy Package Manager
I am installing Hunchentoot on a new machine. This time I thought I would try out Lispy, because it appears to be simplest way of managing the dependencies for Hunchentoot in a standard and hopefully automatic way. However, when I install it, it trips on not being able to verify a key. I have seen ASDF-INSTALL try t...
Install gpg wget http://common-lisp.net/project/lispy/key.asc gpg --import key.asc You should be good to go.
2,022,911
2,023,356
Idiomatic clojure for progress reporting?
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 tak...
The great thing about clojure is you can attach the reporting to the data itself instead of the code that does the computing. This allows you to separate these logically distinct parts. Here is a chunk from my misc.clj that I find I use in just about every project: (defn seq-counter "calls callback after every n'th...
2,026,340
2,026,488
Generating PDF documents from LISP
I want to generate a technical report from lisp (AllegroCL in my case) and I studied various packages/project to help me do this. Requirements: Need to generate a PDF May create an intermediate format like RTF, Restructured TEXT, HTML, Word DOC or Latex Need to be flexible to be able to add content throughout my app...
we are using cl-pdf and cl-typesetting for the last 3 years and it has numerous issues... (like its confusion around encodings, or silently not rendering things that don't fit, or...) so, i don't recommend new development based on them. currently we are in the process of moving all our export mechanisms to open documen...
2,036,244
2,137,228
What's so great about Lisp?
I don't know enough Lisp to say whether it's good or bad. It seems like everyone who has used Lisp loves it, yet the most popular languages these days are descended from C. So what is it about Lisp that is so great and why isn't it used more? Is there anything just plain bad about Lisp (other than the incessant amount ...
Lisp is the Chuck Norris of programming languages. Lisp is the bar other languages are measured against. Knowing Lisp demonstrates developer enlightenment. I've heard of 3 weaknesses (and their counter-arguments): Dynamic typing. There's an argument for statically typed languages out there revolving around giving th...
2,045,564
2,046,950
Connect SBCL on Windows to SQL Server using Integrated Authentication
What is the path of least resistance in getting an SBCL application running on Windows to connect to a SQL Server instance, using integrated authentication? I have found posts on connecting from CL-SQL to SQL Server using ODBC connections but as far as I can tell, there is no way to this without first manually setting ...
There is a cl-mssql library that uses FreeTDS to communicate with MSSQL server. According to http://www.freetds.org/userguide/domains.htm, FreeTDS will use Integrated Authentication if you specify the login like 'DOMAIN\Username'. So it might work with cl-mssql (though I haven't used it).
2,060,744
2,061,755
What are the benefits of letrec?
While reading "The Seasoned Schemer" I've begun to learn about letrec. I understand what it does (can be duplicated with a Y-Combinator) but the book is using it in lieu of recurring on the already defined function operating on arguments that remain static. An example of an old function using the defined function recur...
So you have a few answers that cover the readability issue, which should be fine. But one question that is unclear is whether there are any performance issues. On a shallow look, it seems that the letrec version, like the named-let one (which is really the same) should be faster since there are less arguments to pass...
2,064,116
2,064,227
Write C as s-expressions
I want to write C in s-expressions and use compile-time macros. Does anybody know of anything that does this? It should translate the s-expressions into standard C.
http://voodoo-slide.blogspot.com/2010/01/amplifying-c.html http://www.unmutual.info/software/scexp/ Related: http://news.ycombinator.com/item?id=1071222 http://www.thinlisp.org/whitepaper.html http://www.bitc-lang.org/ http://en.wikipedia.org/wiki/PreScheme http://neontology.com/posts/2007/08/11/whats-nu
2,076,862
2,076,875
Integer division in Common Lisp?
When I do (/ 7 2), what should I do to get the result 3? If I do (/ 7 2.0), I get 3.5, which is as expected.
(floor 7 2) Ref: http://rosettacode.org/wiki/Basic_integer_arithmetic#Common_Lisp
2,104,672
2,105,200
Is it possible to rewrite recursive function as macro in lisp?
I wrote this quicksort function: (defun quicksort (lst) (if (null lst) nil (let ((div (car lst)) (tail (cdr lst))) (append (quicksort (remove-if-not (lambda (x) (< x div)) tail)) (list div) (quicksort (remove-if (lambda (x) (< x div)) tail)))))) bu...
You're mixing macro and runtime; or in other words, you're mixing values and syntax. Here's a very simple example: (defmacro while (condition &body body) `(when ,condition ,@body (while ,condition ,@body))) The bad thing here is that the macro doesn't execute the body, it just constructs a piece of code with the gi...
2,114,819
2,116,517
Why is the Lisp community so fragmented?
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 i...
The Lisp community is fragmented, but everything else is too. Why are there so many Linux distributions? Why are there so many BSD variants? OpenBSD, NetBSD, FreeBSD, ... even Mac OS X. Why are there so many scripting languages? Ruby, Python, Rebol, TCL, PHP, and countless others. Why are there so many Unix shells? sh...
2,128,708
2,179,180
Is there a typical name for a function like 'map' that operates on a list of argument lists instead of multiple lists of arguments?
(I finally posted and accepted an answer to the effect of "no, there isn't, and the question isn't actually that general".) Consider the Common Lisp function 'mapcar'. It takes a function and some lists as arguments, and calls the function with arguments pulled from the same position in each list. Do standard libraries...
There's not really a typical "functional programming" name for that specific operation. In fact, the way I phrased the question presupposes a language that works like Lisp, where functions are applied to lists of arguments. It also assumes that "mapping" in the first place means doing something like Lisp's 'mapcar'. No...
2,129,253
2,130,855
Clojure Jython interop
I was wondering if anyone has tried somehow calling Jython functions from within Clojure, and how you went about doing this if so. I have not used Jython, but I would imagine the Jython interpreter can be invoked in the same way as any other java code, and Python programs can be run within it. However I wonder if it ...
A note: I just realised that the question is specifically about calling Jython functions from Clojure and not about building a full-fledged Jython-Clojure interop solution... But! I've already produced a smallish write-up on my initial thoughts on the latter and I guess that's the logical next step anyway. I mean, how'...
2,129,840
2,129,958
Check if a string is all-caps in Emacs lisp?
all. I was wondering if Emacs lisp had a built-in function for checking if a string is made entirely out of capitalized characters. Here is what I'm using right now: (setq capital-letters (string-to-list "ABCDEFGHIJKLMNOPQRSTUVWXYZ")) (defun chars-are-capitalized (list-of-characters) "Returns true if every character...
In reference to other answers: Using upcase is not a good idea: it will allocate a new string, it will not find if the string has non-alphabetic characters (it seems that you want to forbid that), and it works on integers too (which Emacs uses for characters). Using string-match is better -- it fixes all of these issu...
2,142,028
2,142,160
Minimum steps to display a table-view in Cocoa OSX
Hi I am trying to create a table-view programatically using a cocoa lisp bridge called clozure CL. Now I doubt many people are familiar with this package so I will not go into specifics of my code but I am getting some very strange errors when I try to call addSubview to add my tableView to my window. I have initiali...
1 - Create a scroll view (because the table's size will vary). 2 - Create the table view. 3 - Create columns (set their titles, data cells and identifiers if you're using data source protocol). 4 - Add the columns to the table. 5 - Bind the columns to an appropriate controller (if using bindings) or set the table's -da...
2,143,605
2,143,627
Why isn't there a good scheme/lisp on llvm?
There is Gambit Scheme, MIT Scheme, PLT Scheme, Chicken Scheme, Bigloo, Larceny, ...; then there are all the lisps. Yet, there's not (to my knowledge) a single popular scheme/lisp on LLVM, even though LLVM provides lots of nice things like: easier to generate code than x86 easy to make C FFI calls ... So why is it th...
LLVM provides a lot, but it's still only a small part of the runtime a functional language needs. And C FFI calls are uncomplicated because LLVM leaves memory management to be handled by someone else. Interacting the Garbage Collector is what makes FFI calls difficult in languages such as Scheme. You might be intereste...
2,149,717
2,149,868
How do I stop tracing a function in clisp?
I've been tracing a function example with this call (trace example) and now I wish to stop tracing it, how can I do this?
In common lisp it's as easy as calling untrace: (untrace example)
2,149,727
2,162,013
Are there open source Common Lisp COM wrappers?
I have an application that is written in SBCL and is deployed as an executable on Windows. The need has arisen for it to interact with Excel via COM and another application via DDE (I know, I know). DDE is simple enough for me to have quickly wrapped what I needed in a very small, simple to maintain C library. COM, on ...
There are bindings called cl-win32ole, implemented using CFFI. You are asking for Excel integration, so the Excel example included in cl-win32ole might be of interest to you:
2,156,540
2,156,586
cross-package defgeneric/defmethod in Common Lisp?
What is the right way to define a generic in package A and to provide a method for this generic in package B in CLOS? Thank you in advance! Example: (defpackage :common (:use :cl)) (in-package :common) (defgeneric compare (a b)) (defmethod compare ((a number) (b number)) (cond ((< a b) -1) ((= a b) 0) ...
Methods and functions don't belong to packages. Symbols belong to packages. (defpackage :common (:use :cl)) (in-package :common) (defgeneric compare (a b)) (defmethod compare ((a number) (b number)) (cond ((< a b) -1) ((= a b) 0) (T 1))) (defpackage :a (:use :cl)) (in-package :a) (defclass foo (a b)) If...
2,162,601
2,180,921
Lisp chaining functions macro
Is there a ready made lisp macro that allows chaining (piping) of functions? I couldn't find one. I'll try to explain what I mean with this example. Instead of using let* with lots of unused intermediate variables like this: (let* ((var1 (f1 x y)) (var2 (f2 x var1)) (var3 (f1 var2 z))) var3) I would like to h...
Something like this? (defun chain-expander (forms) (cond ((null (cdr forms)) (car forms)) (t `(let ((it ,(car forms))) ,(chain-expander (cdr forms)))))) (defun chain-counted-expander (forms counter) (cond ((null (cdr forms)) (car forms)) (t (let* ((name (format nil "_~d" counter)) (ana...
2,172,176
2,172,508
How to 'destroy/dispose' frame% in plt-scheme?
I want to destory my previously shown frame when a certain event is triggered. I can't find anything regarding this in the reference manual.
You don't need to -- just (send frame show #f) to hide it. When the value is no longer reachable, it will be garbage-collected.
2,195,105
2,195,828
Is there an equivalent to Lisp's "runtime" primitive in Scheme?
According to SICP section 1.2.6, exercise 1.22: Most Lisp implementations include a primitive called runtime that returns an integer that specifies the amount of time the system has been running (measured, for example, in microseconds). I'm using DrScheme, where runtime doesn't seem to be available, so I'm looking fo...
current-milliseconds is a function that returns the current millisecond count from the system, but it might decrease. current-inexact-milliseconds is similar, but returns a guaranteed-to-increase floating point number. There are also a bunch of similar functions that you can find on that page, but if all you need is t...
2,199,463
2,199,522
Emacs/AUCTeX: run command on file that is not currently open
I edit my LaTeX files in Emacs using AUCTeX. To compile, I press C-c C-c, which will run pdflatex root, if root.tex is the file displayed in the current buffer. But what if I want it to run pdflatex on a file that is not displayed in the current buffer? For example, I am editing an included .tex file, chapter2.tex, an...
When you create a new file AUCTeX will ask you about the "master" document for it. If you define a master, C-c C-c will compile the master instead of the currently open file. AUCTeX keeps track of this by adding a footer with the information it needs. Assuming you have a master document index.tex, the footer would look...
2,205,121
2,205,445
emacs programmatically change window size
I would like to implement automatic collapse of compilation buffer to small size (but not close at a delete windows), such that upon successful compilation to window is shrunk to minimum size. get-buffer-create returns a buffer. how can I shrink-window on window associated with that buffer? also, is there a way to sto...
I believe there are two ways to solve this problem. The first is to use the hook `'compilation-finish-functions', which is: [A list of f]unctions to call when a compilation process finishes. Each function is called with two arguments: the compilation buffer, and a string describing how the process finished. Whi...
2,209,440
2,209,567
emacs how to tell window orientation?
How do I tell in emacs window orientation, e.g. if it was created by vertical or horizontal split? alternatively, how can I tell if window can be resized vertically or horizontally? on a related note, is there a tutorial for programming emacs windows, e.g. size, buffers associated, properties, etc.? Thank you very much...
I'm assuming you're using the term 'window' to mean Emacs windows and not top level application windows (which in Emacs terminology are frames). If that's what you're looking for, zdav's answer provides some useful information. There are two functions window-height and window-width. You could trivially code up a functi...
2,215,298
2,215,328
emacs interactive function with optional numeric prefix
How do I specify a function which has optional numeric prefix, if not, it prompts for a number? basically how goto-line behaves? (defun my-function(&optional n) ; I have tried (interactive "N") ; reads string, no prompt (interactive "p") ; defaults to one (interactive (if (not n) (read-number "N: "))) ; runti...
Take a look at how 'goto-line is defined (M-x find-function goto-line RET). (defun my-function (n) "Example function taking a prefix arg, or reading a number if no prefix arg" (interactive (if (and current-prefix-arg (not (consp current-prefix-arg))) (list (prefix-numeric-value current-prefix-arg)) (...
2,223,310
2,223,703
how to override functions in emacs lisp for specific mode?
How can I override emacs function with my own implementation for a specific mode? example/reference would be great Thanks
This seems like an odd thing to want to do, but you could do it by advising the function, I suppose. Example: (defadvice * (around ultimate-answer activate) (if (and (eq major-mode 'html-mode) (equal (ad-get-args 0) '(6 9))) (setq ad-return-value 42) ad-do-it)) After evaluating this advice, the * function...
2,234,860
2,234,991
lisp filter out results from list not matching predicate
I am trying to learn lisp, using emacs dialect and I have a question. let us say list has some members, for which predicate evaluates to false. how do I create a new list without those members? something like { A in L: p(A) is true }. in python there is filter function, is there something equivalent in lisp? if not,...
These functions are in the CL package, you will need to (require 'cl) to use them: (remove-if-not #'evenp '(1 2 3 4 5)) This will return a new list with all even numbers from the argument. Also look up delete-if-not, which does the same, but modifies its argument list.
2,235,064
2,235,598
Common Lisp Exercises/Problems
I'm working through Practical Common Lisp presently http://www.gigamonkeys.com/book/ It's an excellent book with some practical assignments towards the end, but I'm looking for basic problems that explore the use of functions, variables and macros. Can anybody suggest a suitable resource to work through in order to re...
Project Euler is a great source of programming problems also, there is Rosetta Code
2,236,690
2,236,785
F# vs Haskell vs Lisp - which language to learn?
I've heard a lot about functional programming languages and I'm willing to learn one. I guess it will be mostly for fun, however, I hope it will improve my programming skills. I have mostly C#/.NET background, so my first choice is to learn F# (because of .NET and familiarity with Visual Studio). On the on other hand, ...
F# is my language of choice, but I'd strongly recommend learning them all. They are all quite different and interesting in their own right. Here's a quick over view to each one (with perhaps a slight F# bias), you can easily find more info by googling: F# - is a language that makes it easy to program in the functional ...
2,238,114
2,238,575
How to write a recursive macro call on a &REST parameter in Lisp?
I've been writing some simple test cases for one of my assignments, and have built up a bit of a test suite using macros. I have run-test and run-test-section and so on. I'd like run-test-section to take a number of parameters which are run-test invocations and count up the number of PASSes and FAILs. run-test returns ...
At macro expansion time, cdr is not evaluated. So (count-true t t nil) hits an infinite expansion like this: (count-true t t nil) => (1+ (count-true (cdr (t t t nil)))) => (1+ (1+ (count-true (cdr (cdr (t t t nil)))))) => (1+ (1+ (1+ (count-true (cdr (cdr (cdr (t t t nil)))))))) => ... Well, actually this happens for ...
2,239,643
2,239,799
Lisp, a couple of questions about lists and recursion
sorry to overflow with so many questions. I have the following: (defun recursive-function (string) "returns list of strings" ;I am trying to return flat list ; create list L (append (mapcar 'recursive-function L))) But since recursive-function returns a list, I end up with a list of a list of a list..., whereas I want...
If I understood correctly, you can combine reduce and append to flatten the list before returning it. Example: (reduce 'append '((1) (2) (3))) Output: (1 2 3) In your case this might work: (reduce 'append (mapcar 'recursive-function L))
2,239,923
2,240,096
Change an editable-text value in Allegro CL
I'm trying to change the value of an Editable-Text control in Allegro CL (version 8.0.1) by clicking a Default-Button. I've read about (setf value) but haven't found any examples. The function I have ttached to the on-click event is the following (defun form1-default-button-2-on-click (dialog widget) (declar...
(setf (slot-value widget 'value) "foo") Something like the above. You need get the symbol value in the correct package. probably there is also an accessor function like WIDGET-VALUE . Then (setf (widget-value widget) "foo") might work... I'm not an ACL user - there are probably better ways. ACL specific questions ...
2,240,762
2,240,809
can if be a proper function rather than a special form
I finally started learning functional languages (emacs lisp) and it makes explicit distinction between functions and special forms such as flow control , for example if. Is there a fundamental/theoretical reason why special forms are distinct from functions? do any languages provide functional if? Thanks
With eager evaluation the distinction is required, languages with lazy evaluation (i.e. Haskell) if et al. can be functions. Eager evaluation: The function's arguments are evaluated before calling the function, and only the results are passed to the function. Lazy evaluation: A function's arguments evaluated if and onl...
2,242,572
2,242,801
Emacs :TODO indicator at left side
I want to have sort of indiacator at left side of the line wherever I have in the source code #TODO: some comment //TODO: some comments The indicator could be a just mark and I already enabled line numbers displayed at emacs.
This command will do something like you want. (defun annotate-todo () "put fringe marker on TODO: lines in the curent buffer" (interactive) (save-excursion (goto-char (point-min)) (while (re-search-forward "TODO:" nil t) (let ((overlay (make-overlay (- (point) 5) (point)))) (overlay-put over...
2,245,854
2,246,675
SBCL initialization file
I would like to know where I should save my .sbclrc file. I tried saving it in my .sbcl folder, but it doesn't seem to be working. I'm using Windows XP with Emacs version 23. I'm trying to set up asdf-install, that is why I'm mucking around with the initialization file. Thanks for your time.
What is the result of evaluating this in the repl: (SB-IMPL::USERINIT-PATHNAME)
2,256,261
2,256,613
Why is consing in Lisp slow?
I read in the book 'On Lisp' that one should avoid excessive use of cons in the body of expanded macros. Why is cons considered to be an inefficient operation? Does Lisp not do structure sharing with the cons cells?
You need to understand the jargon first. CONS is a primitive operation to create a fresh cons cell. Consing means allocation of memory on the heap in general, not only cons cells: Consing of numbers, Consing of arrays, Consing of CLOS objects, ... The definition from the 'memory management glossary' says: cons(1) In L...
2,259,469
2,259,670
emacs lisp skip-syntax-forward help
I am trying to implement function which moves to the next blank/whitespace character. I have read manual, and it seems I can use skip-syntax functions. However, I cannot figure out how to use them correctly. Here is what I have: (skip-syntax-forward " ") However, this does not seem to work. If I use "^ " it works, but...
(when (= 0 (skip-syntax-forward "^ ")) (skip-syntax-forward " ") (skip-syntax-forward "^ "))
2,263,758
2,273,179
How to change emacs config in Lisp In A Box
I have been a programmer for a decade now, but I believe this is the first time I've ever asked a question on a forum. I just can't figure this out and can't find the answer already online. I am trying to turn on CUA mode so that emacs is more bearable for a windows user (normal copy paste functions). I am running Wi...
For GNU/Emacs, you can choose to use any one of the following three file names as the start-up configuration file: ${HOME}/.emacs ${HOME}/.emacs.el ${HOME}/.emacs.d/init.el It would probably be a good idea to decide on one of the three options and then stick to it - the first one seems to be the most widely used one. ...
2,282,928
2,285,524
Schliemann's method of programming language learning
Background: 19th-century German archeologist Heinrich Schliemann was of course famous for his successful quest to find and excavate the city of Troy (an actual archeological site for the Troy of Homer's Iliad). However, he is just as famous for being an astonishing learner of languages - within the space of two years,...
Rosetta Code may be useful. To quote the site:- Rosetta Code is a programming chrestomathy site. The idea is to present solutions to the same task in as many different languages as possible, to demonstrate how languages are similar and different, and to aid a person with a grounding in one approach to a problem in lea...
2,287,308
2,287,339
Convert code from Lisp to F#
I have the following code in Lisp: (defun Is_List_Even (lista) (cond ((null lista) t) ((null (cadr lista)) nil) (t (Is_List_Even (cddr lista))))) Can someone help me to write in F#? I'm new to F# and I'm in a hurry. Regards, Voicu.
let rec even = function | [] -> true | [_] -> false | _::_::l -> even l
2,289,603
2,290,198
What are best practices for including parameters such as an accumulator in functions?
I've been writing more Lisp code recently. In particular, recursive functions that take some data, and build a resulting data structure. Sometimes it seems I need to pass two or three pieces of information to the next invocation of the function, in addition to the user supplied data. Lets call these accumulators. What ...
If you want to write idiomatic Common Lisp, I'd recommend the loop and variables for iteration. Recursion is cool, but it's only one tool of many for the Common Lisper. Besides, tail-call elimination is not guaranteed by the Common Lisp spec. That said, I'd recommend the labels approach if you have a structure, a tree...
2,300,758
2,304,720
Lexical closures over macrolet?
Is there a way to do something like lexical closures using macrolet? What I want to do is make the following macro a local recursive helper that calls a function on each combination instead of generating a list as it does now calling the macro in the repl results in: CL-USER> (combinations nil '(1 2 3) '(4 5 6)) ((1 4...
Macros are not first-class objects in Common Lisp, so you can't really have the equivalent of a lexical closure as a macro. You could get a similar effect by creating a function that generates a list that is a valid Lisp program, and then evals it. That probably isn't a very good solution to your problem though. As Rai...
2,317,382
2,317,448
An Emacs alternative which exposes a text model to a scriptable environment?
everybody out there! I'm currently seeking for a technical solution to create a nice literate programming environment. Unfortunately, most editors are too much hard coded, and their functionalities just cover most famous needs, and can't cleanly cover special needs. I came to Emacs (later after some others), but I also...
JEdit seems to be very scriptable with Java, BeanShell, Jython and other languages targeting the JVM. Most of its functionality is implemented with OSGI plugins. If you really like LISP, maybe you could even try with Clojure! :-)
2,331,106
2,332,733
sbcl runs forever on second call of function
The function: Given a list lst return all permutations of the list's contents of exactly length k, which defaults to length of list if not provided. (defun permute (lst &optional (k (length lst))) (if (= k 1) (mapcar #'list lst) (loop for item in lst nconcing (mapcar (lambda (x) (cons item x)) ...
One thing that's wrong in your code is your use of EQ. EQ compares for identity. EQ is not for comparing numbers. EQ of two numbers can be true or false. Use EQL if you want to compare by identity, numbers by value or characters. Not EQ. Actually (remove-if (lambda (x) (eql x item)) list) is just (remove item list) F...
2,350,788
2,351,247
What features is lisp lacking?
I have read that most languages are becoming more and more like lisp, adopting features that lisp has had for a long time. I was wondering, what are the features, old or new, that lisp does not have? By lisp I mean the most common dialects like Common Lisp and Scheme.
Pass-by-reference (C++/C#) String interpolation (Perl/Ruby) (though a feature of CL21) Nice infix syntax (though it's not clear that it's worth it) (Python) Monadic 'iteration' construct which can be overloaded for other uses (Haskell/C#/F#/Scala) Static typing (though it's not clear that it's worth it) (many language...
2,350,836
2,350,853
Lisp simple question
I have some not understanding actions from gnu clisp Suppose, I have some code like (let ((x "Hi!"))(print x)). If I execute it from console (like, clisp fileName.lisp) I see Hi! But, when I execute it from interpreter, I see this text twice. Why? Help me, please.
The interpreter always outputs the value of the last expression. print also returns the parameter as a value, "Hi!" in your case. That's why you see it twice. (print "Hi!") will give the same result.
2,353,353
2,363,651
How to process input and output streams in Steel Bank Common Lisp?
I'm trying to figure out how to use the output stream of one program I start with RUN-PROGRAM so it can be used as the input of another program started with RUN-PROGRAM (i.e., the moral and perhaps literal equivalent of piping). I've tried using a number of combinations of the :INPUT, :OUTPUT and :WAIT keyword argument...
I got a working answer from Raymond Toy on comp.lang.lisp. His solution was for CMUCL, but it worked with the essentially identical RUN-PROGRAM function on the closely related SBCL, and with minor changes it will work on CCL as well, because CCL's RUN-PROGRAM is basically a clone of the one from CMUCL/SBCL. The secret...
2,353,497
2,353,533
The subsets-sum problem and the solvability of NP-complete problems
I was reading about the subset-sums problem when I came up with what appears to be a general-purpose algorithm for solving it: (defun subset-contains-sum (set sum) (let ((subsets) (new-subset) (new-sum)) (dolist (element set) (dolist (subset-sum subsets) (setf new-subset (cons el...
All of the NP-complete problems have solutions. As long as you're willing to spend the time to compute the answer, that is. Just because there's not an efficient algorithm, doesn't mean there isn't one. For example, you could just iterate over every potential solution, and you'll eventually get one. These problems ...
2,379,103
2,383,916
LISP community and web frameworks
In the reddit interview with Peter Norvig, he says “For various reasons the set of web libraries and protocols were slower to develop in LISP than in other languages” and consequently lisp adoption among the web community went down, and people went after languages with richer library sets. Is there a reas...
Mr. Norvig's remark seemed to me to be more historical than an assessment of the current situation. Perhaps in the mid to late 90s web related libraries didn't appear as quickly in Common Lisp as they did in other languages like Java. But certainly today that is not the case. I can name no less than five Common Lisp...
2,380,991
2,381,081
List without nil in Lisp
I know that in Lisp a list must end with nil, but expression like (print (cons 1 (cons 3 2))) does not throw any errors. It prints: (1 3 . 2) Is it correct? I'm using GNU Clisp.
What you have is a dotted list, which is a kind of improper list. A chain of CONS cells where the last CDR is NIL is a proper list.
2,382,082
2,382,124
Inheritance classes in Scheme
Now I research OOP-part of Scheme. I can define class in Scheme like this: (define (create-queue) (let ((mpty #t) (the-list '())) (define (enque value) (set! the-list (append the-list (list value))) (set! mpty #f) the-list) (define (deque) (set! the-list (cdr the-list)) ...
Well, I wouldn't call that a class, but that's just me. That's simply closures and raw scheme. Scheme itself does not have an object system. However, Scheme is capable of implementing a class system. If you would like to use an oop system, there are several written for Scheme that you can try. Here is a link that lists...
2,384,314
2,384,368
List of evented / asynchronous languages
I'm working on a system than has to be pretty scalable from the beginning. I've started looking at / playing around with asynchronous/evented approaches to writing serverside code. I've played around with both ruby's EventMachine and node.js. EventMachine is cool, but doesn't have asynchronous file I/O, which I need. T...
Erlang may be the language with the highest intrinsic scalability for server-side code (it manages multiprocessing for you, mostly by doing async, cooperative task switching "under the covers") -- if you can stomach its peculiar syntax and (often) peculiar semantics. Python has twisted (very general purpose for all net...
2,391,711
2,391,794
Best practices in building and deploying Clojure applications: good tutorials?
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-...
A couple of quick hints, then some links: Don't use lein uberjar during development; prefer lein jar. The difference is that lein uberjar puts all your dependencies in the generated jar (including Clojure itself), so that your single jar is an entirely self contained package with your app inside; lein jar only jars you...
2,393,506
2,394,425
Traversing Scheme function as a list
Isn't it possible to treat functions in Scheme as any other list? Basically, what I want do to is something like this: (define (foo) "hello") (cdr foo) ; or similar, should return the list ((foo) "hello") I've found a similar discussion about this, and I feel a bit disappointed if this is not possible with Scheme. ...
I have often wanted to be able to do the same thing csl. Below is a quick example of how you could go about doing this in mzscheme. DrScheme 4.2 (module qdefine mzscheme (provide ;(all-from-except mzscheme let) (rename define olddefine) (rename quote-define define) (rename quote-cdr cdr) (rename quote-car...
2,395,428
2,395,778
What are circular lists good for (in Lisp or Scheme)?
I note that Scheme and Lisp (I guess) support circular lists, and I have used circular lists in C/C++ to 'simplify' the insertion and deletion of elements, but what are they good for? Scheme ensures that they can be built and processed, but for what? Is there a 'killer' data structure that needs to be circular or tail-...
Saying it supports 'circular lists' is a bit much. You can build all kinds of circular data structures in Lisp. Like in many programming languages. There is not much special about Lisp in this respect. Take your typical 'Algorithms and Datastructure' book and implement any circular data structure: graphs, rings, ... Wh...
2,403,400
2,403,626
Cocoa equivalent of the Carbon method getPtrSize
I need to translate the a carbon method into cocoa into and I am having trouble finding any documentation about what the carbon method getPtrSize really does. From the code I am translating it seems that it returns the byte representation of an image but that doesn't really match up with the name. Could someone give ...
GetPtrSize is a function from the Memory Manager. When you allocated memory with NewPtr (another Memory Manager function), the Memory Manager would keep track of how much memory you asked for, so that you could retrieve that number with GetPtrSize. The modern replacement for NewPtr is malloc, which provides no such fun...
2,403,484
2,403,613
Lisp Style question label local functions or not?
I was wondering if there is a standard practice regarding the use of labels in Lisp. I've been messing around with a Lisp implementation of the algorithm described in the first answer here Generating permutations lazily My current version uses labels to break out portions of functionality. (defun next-permutation (pm...
No, it's fine. Writing named functions makes the code a little bit more self-documenting and more modular. Sometimes I would also list all variables used in the functions arglist and not use the variables from the enclosing function. That makes the interface a little bit clearer and helps moving the function around in ...
2,413,454
2,413,531
Getting reference to the JavaScript Function object behind an operator
Here is a lisp procedure that simply adds 'a' to the absolute value of 'b': (define (a-plus-abs-b a b) ((if (> b 0) + -) a b)) I think this is beautiful, and I am trying to find the best way of writing this in JavaScript. But my JavaScript code is not beautiful: var plus = function(a,b) { return a + b; }; var m...
It's a very cool idea - would be great for evaluating mathematical expressions but you simply can't set an operator (or the logic behind it) to a variable. Sorry :-)
2,437,162
2,438,294
UVa #112 Tree Summing
I'm working on UVa #112 Tree Summing. I have what I think should be a working solution but it is not accepted by the online judge due to a basic misunderstanding of the problem on my part. Consider the following inputs: -1 (-1()()) 77 (77(1()())()) or diagrammatically, the trees look like: -1 77 / \ ...
Easy. The tree: (77(1()())()) A leaf is of this form: (integer () ()) Thus the tree has only one leaf: (1 () ()) The sum of the nodes to this leaf is 78. 78 is not 77. Result: no. What you think is a rightmost path, is none according to the definition. The first tree: (-1()()) It is just a single leaf node. One path....
2,443,068
2,443,674
Problems with ltk (common lisp)
I installed ltk to Steel Bank Common Lisp with asdf-install, but I can't even start using it V_V. The code below is the simplest example in the documentation, and is copied almost verbatim. (asdf:operate 'asdf:load-op :ltk) (defun hello-1() (with-ltk () (let ((b (make-instance 'button ...
You have to import the symbols into the package you want it to work in. The generic "user" package is cl-user, and a "virgin" image will put you there. In order to import the (exported) symbols from another package, issue (use-package :another-package). Example on the REPL: (asdf:load-system :ltk) (use-package :ltk) ...
2,448,202
2,448,311
Vector addition of lists
If I had a N lists each of length M, how could I write a nice clean function to return a single list of length M, where each element is the sum of the corresponding elements in the N lists? (starting to learn lisp - go easy!)
This is a job for the map and apply functions. Here is a way to do it, with an EDIT suggested by Nathan Sanders: (define (add-lists . more) (apply map + more))
2,458,805
2,513,592
nohup SBCL ubuntu couldn't read from standard input
On Ubuntu I compiled sbcl 1.0.35 with threading. I can happily use sbcl from the command line and my hunchentoot website works with threading but when I logout it's gone. When I attempt to nohup sbcl nohup ./src/runtime/sbcl --core output/sbcl.core I get (SB-IMPL::SIMPLE-STREAM-PERROR "couldn't read from ~S" # 9) I'...
Dmity-vk sent me on the right track, thank you. SBCL tries to start a repl when you start it up, and reads from the standard in. When you use nohup the standard in is redirected and cannot be read. SBCL then drops to the debugger which tries to read from standard in ... hence the endless loop. The --script tag comes cl...
2,501,046
2,501,210
Newbie: Keybindings error in Elisp
I am trying to make a simple keybinding to the "na" function. When I execute (na) it inserts "å" in the current buffer, which it is supposed to, but the when I try the keybinding as described in the first line I get the error: "Wrong argument: commandp, na". I am not sure if it matters, but I have also put the (local-s...
What you're missing is a call to interactive: (defun na () "Liten å" (interactive) (setq varlol "å") (insert varlol)) From the documentation for it: This special form declares that a function is a command, and that it may therefore be called interactively (via M-x or by entering a key sequence bound t...
2,503,908
2,504,102
How to write a LISP interpreter for actionscript 3?
I know there is one, but it's not easy to implement the way I want. I would like to know the steps to interpret the lisp language and what functions are essential to be implemented.
First, you learn Lisp, then read LiSP and (given you know ActionScript well enough) you just start. PAIP also has sections about implementing Lisp interpreters and compilers. To get an idea how it generally can be approached, you can have a look at Write Yourself a Scheme in 48 hours. It uses Haskell as an implementati...
2,519,407
2,851,155
Why is there no way to resize SRFI-4 vectors in Scheme?
I see that SRFI 4 does not mention resizing of vectors. I'm using f64vectors (for which I need fast access), and I'd like to be able to resize them quickly (similar to what realloc does in C), and not necessarily copy the whole vector. Since I didn't find any references to a "resize-f64vector" procedure, I'd like to kn...
Couple reasons. By having a homogeneous vector type within the language, the compiler can make some solid assumptions about performance. Ideally, in some heavily optimized scenarios, the reference to the vector can be little more than a point to a block of memory. Not saying any Scheme implementations actually do this,...
2,523,155
2,524,860
Macro doesn't work in the function
I have problems with following code: http://lisper.ru/apps/format/96 The problem is in "normalize" function, which does not work. It fails on the fifth line: (zero-p a indexes i) (defun normalize (a &optional indexes i) "Returns normalized A." (progn (format t "Data=~A ~A ~A" a indexes i) (if (zero-p a indexe...
Note that the macros ZERO-P and REF-OF are expanded when you evaluate, compile or load the DEFUN for NORMALIZE. Their arguments are the symbols INDEXES and INDEX, and both of those are not NIL, so the IFs in the REF-OF forms will all take the first branch and expand into AREF forms where INDICES and INDEX can't be boun...
2,526,777
2,557,990
How are vector patterns used in syntax-rules?
I have been writing Common Lisp macros, so Scheme's R5Rs macros are a bit unnatural to me. I think I got the idea, except that I don't understand how one would use vector patterns in syntax-rules: (define-syntax mac (syntax-rules () ((mac #(a b c d)) (let () (display a) (newline) (displa...
A macro might not require its arguments to be written as a vector, yet provide useful behaviour for when they are. The most notable example would probably be quasiquote: ;; a couple of test variables (define foo 1) (define bar 2) ;; vector literals in Scheme are implicitly quoted #(foo bar) ; returns #(foo bar), i.e. ...
2,535,478
2,555,518
How do I disable warnings in lisp (sbcl)
How do I disable all warnings in sbcl? The extra output is rather annoying.
this is what i use to muffle both compile-time and runtime (load-time) redefinition warnings: (locally (declare #+sbcl(sb-ext:muffle-conditions sb-kernel:redefinition-warning)) (handler-bind (#+sbcl(sb-kernel:redefinition-warning #'muffle-warning)) ;; stuff that emits redefinition-warning's )) foll...
2,536,036
2,536,888
How can I SETF an element in a tree by an accessor?
We've been using Lisp in my AI course. The assignments I've received have involved searching and generating tree-like structures. For each assignment, I've ended up writing something like: (defun initial-state () (list 0 ; score nil ; children 0 ; value 0)) ; something else and building my f...
Use CLOS for data structures The best way out of this is to quickly learn the basics of CLOS. (defclass state () ((score :accessor state-score :initform 0) (children :accessor state-children :initform nil) (value :accessor state-value :initform 0))) (defun make-initial-state () (make-instance 'st...
2,541,872
2,542,598
Adding an element to a list in Scheme
I'm using R5RS Scheme and I just want to implement a function that returns the intersection of two given lists, but I can't do that because I cannot add an element to a list. Here is my code. How can I fix it? I'm really a beginner in Scheme - this is my first work using Scheme. thx in advance.. (define list3 '()) (def...
Here is a recursive version that does the intersection instead of the union. (define (intersect list1 list2) (cond ((null? list1) list1) ((member (car list1) list2) (cons (car list1) (intersect (cdr list1) list2))) (t (intersect (cdr list1) list2))))
2,542,037
2,542,077
Lisp: Determine if a list contains a predicate
As part of a homework assignment in Lisp, I am to use apply or funcall on any predicates I find. My question (uncovered in the coursework) is: how do I know when I've found a predicate in my list of arguments? I've done some basic google searching and come up with nothing so far. We're allowed to use Lisp references...
The canonical reference is the Common Lisp Hyperspec. I don't know what your assignment is exactly, but you can either check each argument against a list of possible predicates, or perhaps determine if your argument is a function (functionp), if you can assume that all functions passed in would be predicates.
2,557,089
2,557,273
Greenspun's 10th rule in Perl?
Greenspun's Tenth Rule of Programming is a common aphorism in computer programming and especially programming language circles. It states: Any sufficiently complicated C or Fortran program contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp. The questions are, Would you...
You might like the preface (as well as the rest of the book) for Mark Jason Dominus's Higher-Order Perl, whose subject is essentially your question. He says: If you pick up a good book about Lisp, there will be a section that describes Lisp's good features. For example, the book Paradigms of Artificial Intelligence Pr...
2,575,819
2,575,854
Common lisp error: "should be lambda expression"
I just started learning Common Lisp a few days ago, and I'm trying to build a function that inserts a number into a tree. I'm getting an error, *** - SYSTEM::%EXPAND-FORM: (CONS NIL LST) should be a lambda expression From googling around, it seems like this happens when you have too many sets of parenthesis, but afte...
Correct! The problem is in the line right after that, where it says ((cons nil lst) (append lst nil) (insertat nil lst 3) ... The issue is the two opening parentheses. Parentheses can change meaning in special contexts (like the cond form you're using), but in this context, the parentheses signify regular function app...
2,585,591
2,585,696
Examples of excellent Common Lisp code?
I've learned enough Common Lisp to be able to muddle my way through writing an application. I've read Seibel's Practical Common Lisp What libraries or programs should I be reading to understand the idioms, the Tao, of Common Lisp?
CL-PPCRE is often cited as a good example, for good reason. Actually, probably any of Edi Weitz's libraries will make good reading, but CL-PPCRE is particularly clever and it's a useful and impressive library. Beyond that a lot of CL implementations are written mostly in CL. It can be pretty productive to pick some par...
2,608,114
2,608,246
F# equivalent to Eval
Is there an F# equivalent to eval? My intent is to have my app load a small code sample from a file and essentially let file = "c:\mysample" let sample = loadFromFile file let results = eval(sample) I am new to F# and trying to figure out some of the limitations before I apply it to a project. Thank you
There is no function that would allow you to do this directly. However, when you want to compile an F# source file programatically, you can invoke the F# compiler from your application. The easiest way to do this is to use F# CodeDOM provider, which is available as part of the F# PowerPack (in the FSharp.Compiler.CodeD...
2,618,233
2,618,245
lisp: consolidate a list-of-lists into a single list?
Still working on lisp recipes and idioms. I have a list like this: ((a b c) (d e f) nil (g h)) I'd like to consolidate that to one list, (a b c d e f g h) Seems like there oughta be a one-liner for that.
(apply #'append '((a b c) (d e f) (g h i))) or (loop for outer in '((a b c) (d e f) (g h i)) nconcing (loop for inner in outer collecting inner))
2,625,843
2,625,939
Writing an Eval Procedure in Scheme?
My problem isn't with the built-in eval procedure but how to create a simplistic version of it. Just for starters I would like to be able to take this in '(+ 1 2) and have it evaluate the expression + where the quote usually takes off the evaluation. I have been thinking about this and found a couple things that might ...
Firstly, if you're doing what you're doing, you can't go wrong reading at least the first chapter of the Metalinguistic Abstraction section of Structure and Interpretation of Computer Programs. Now for a few suggestions from myself. The usual thing to do with a symbol for a Scheme (or, indeed, any Lisp) interpreter is...
2,664,333
2,664,480
lisp, differences in assignment functions
I'm pretty new to lisp, so apologies for what may be a simple question, Whilst I understand the difference between DEFVAR and DEFPARAMETER (defvar only sets undefined variables), and the LET is for local scope only, what is the is the use of SETF as opposed to the other, previously mentioned assignment functions?
DEFVAR and DEFPARAMETER define and set global special (dynamically bound) variables. SETF and SETQ set variables (global or local, special or lexical), but don't define them. SETF has more capabilities than SETQ, since it can set 'places' (like elements in lists, arrays, object's slots, ...). Edit: Paul says that in CL...
2,664,618
2,664,632
What does it mean that "Lisp can be written in itself?"
Paul Graham wrote that "The unusual thing about Lisp-- in fact, the defining quality of Lisp-- is that it can be written in itself." But that doesn't seem the least bit unusual or definitive to me. ISTM that a programming language is defined by two things: Its compiler or interpreter, which defines the syntax and the ...
Probably what Paul means is that the representation of Lisp syntax as a Lisp value is standardized and pervasive. That is, a Lisp program is just a special kind of S-expression, and it's exceptionally easy to write Lisp code that manipulates Lisp code. Writing a Lisp interpreter in Lisp is a special case, and is not ...
2,680,621
2,680,715
Sum of Squares in Lisp
I need to write a non-recursive version of the function sum-squares and Use a do-loop that is based on the length of the argument list.
Here's how it's done generally: (defun sum-squares (list) (loop for x in list for y = (* x x) summing y into total finally (return total))) A do loop solution is even simpler, but not half as elegant: (defun sum-squares (list) (let ((sum 0)) (do ((i 0 (1+ i))) ...
2,692,464
2,698,573
Connecting .NET to Common Lisp
I have a fairly involved LispWorks Common Lisp module that sits atop some .NET modules via RDNZL. It has come up that I need to expose some of its functionality to some other .NET applications, and I'm not sure the best (shortest) way to approach this without re-writing the module in C#. I know there are a few CLR Lisp...
"It has come up that I need to expose some of its functionality to some other .NET applications" The following isn't exactly what you're asking for, but if you want to think out of the box for a moment, I think that perhaps using messaging would be easiest (this based entirely on the statement quoted above). Some...
2,704,382
2,751,865
emacs: how do I use edebug on code that is defined in a macro?
I don't even know the proper terminology for this lisp syntax, so I don't know if the words I'm using to ask the question, make sense. But the question makes sense, I'm sure. So let me just show you. cc-mode (cc-fonts.el) has things called "matchers" which are bits of code that run to decide how to fontify a region ...
According to (elisp)Top > Debugging > Edebug > Edebug and Macros you have to tell Edebug how to debug a macro by defining it with debug statements or by using def-edebug-spec. This tells it what parameters should be evaluated and which shouldn't. So it can be done. In fact it looks as if c-lang-defconst already been...
2,736,037
2,737,693
LISP: Keyword parameters, supplied-p
At the moment I'm working through "Practical Common Lisp" from Peter Seibel. In the chapter "Practical: A Simple Database" (http://www.gigamonkeys.com/book/practical-a-simple-database.html) Seibel explains keyword parameters and the usage of a supplied-parameter with the following example: (defun foo (&key a (b 20) ...
Let's reindent the function foo: (defun foo (&key a (b 20) (c 30 c-p)) (list a b c c-p)) If you indent it like this you will see that the function has three keyword parameters: a, b and c. These are available in the body of the function. For the keyword parameter c there is a varia...
2,738,777
2,738,793
Lisp's "some" in Python?
I have a list of strings and a list of filters (which are also strings, to be interpreted as regular expressions). I want a list of all the elements in my string list that are accepted by at least one of the filters. Ideally, I'd write [s for s in strings if some (lambda f: re.match (f, s), filters)] where some is d...
There is a function called any which does roughly want you want. I think you are looking for this: [s for s in strings if any(re.match(f, s) for f in filters)]
2,748,940
2,762,174
Are incremental Macro definition possible?
I often find the following type of incremental definition useful: (define (foo) (display "bar")) (foo) ;prints bar (define foo (let ((bar foo)) (lambda () (display "foo") (bar)))) (foo) ;prints foobar How do I preform this type of incremental definition with macros? I cou...
FWIW (and this is definitely not much, since this is pretty much an exercise in target practicing with your feet), here is how you would do this in PLT Scheme with only hygienic syntax-rules macros: (define-syntax foo (syntax-rules () [(foo x) (list 'x '= x)])) (define-syntax foo (let ([old (syntax-local-value ...
2,750,421
2,751,119
What type of lambda calculus would Lisp loosely be an example of?
I'm trying to get a better grip on how types come into play in lambda calculus. Admittedly, a lot of the type theory stuff is over my head. Lisp is a dynamically typed language, would that roughly correspond to untyped lambda calculus? Or is there some kind of "dynamically typed lambda calculus" that I'm unaware of?...
Lisp is a dynamically typed language, would that roughly correspond to untyped lambda calculus? Yes, but only roughly. In the "pure" untyped lambda calculus, everything is coded as functions. (You can google for the popular "Church encoding" and the less popular "Scott encoding".) Lisp has non-functional data, lik...
2,758,963
2,760,086
Equivalence Classes LISP
I need to write a program for equivalence classes and get this outputs... (equiv '((a b) (a c) (d e) (e f) (c g) (g h))) => ((a b c g h) (d e f)) (equiv '((a b) (c d) (e f) (f g) (a e))) => ((a b e f g) (c d)) Basically, A set is a list in which the order doesn't matter, but elements don't appear more than once. T...
That sounds like a typical homework question. It's not that difficult, though. A simple recursive function over the input list will do. The ingredients of the function are already mentioned in the task description: simple set operations. If it is homework, then this applies: The typical strategy for homework questions ...
2,775,440
2,775,502
"Inlining" (kind of) functions at runtime in C
I was thinking about a typical problem that is very JIT-able, but hard to approach with raw C. The scenario is setting up a series of function pointers that are going to be "composed" (as in maths function composition) once at runtime and then called lots and lots of times. Doing it the obvious way involves many virtua...
You might want to look at LLVM. They have a library that allows for JITing code (and much more things) from C, it supports many platforms and it's an open source project: http://llvm.org/
2,812,954
2,813,126
Lisp vs Python -- Static Compilation
Why can Lisp with all its dynamic features be statically compiled but Python cannot (without losing all its dynamic features)?
There is nothing that prevents static compilation of Python. It's a bit less efficient because Python reveals more mutable local scope, also, to retain some of the dynamic properties (e.g. eval) you need to include the compiler with the compiled program but nothing prevents that too. That said, research shows that most...
2,816,019
2,816,084
In Lisp, Avoid "Cannot open load file" when using require
I am working on a custom .emacs file that I will be able to use on several different computers. I would like to be able to load a mode if it exists on the system. If it does not exist I would like Emacs to stop showing the error: File error: Cannot open load file, X. For example: (require 'darkroom-mode) Results in: F...
If you just want to keep require from issuing an error, you can do: ; third arg non-nil means to not signal an error if file not found ; a symbol provides documentation at the invocation (and is non-nil) (require 'darkroom-mode nil 'noerror) From the documentation (C-h f require RET): require is a built-in function i...
2,829,699
10,331,177
[org-mode]: repeating task in every Mon, Wed, Fri at 18:00, need help with sexp
As I had written in title, I need a little help with improvement of this sexp: * TODO remeber about thingie. SCHEDULED: <%%(or (= 1 (calendar-day-of-week date)) (= 3 (calendar-day-of-week date)) (= 5 (calendar-day-of-week date)))> Now it shows itself in the following days, b...
* TODO remeber about thingie. SCHEDULED: <2012-05-07 Mon 18:00 +1w> SCHEDULED: <2012-05-09 Wed 18:00 +1w> SCHEDULED: <2012-05-11 Fri 18:00 +1w>