lisp

Priority queue for Common Lisp?

梦想与她 提交于 2019-12-24 00:59:28
问题 I've been looking everywhere for a priority queue implementation for Common Lisp that works, and so far, I've not had much luck. As I'm fairly new to Common Lisp, whenever I see a huge warning/error dump from the REPL, I'm not really sure what to do about it. This isn't helped by the fact that all the priority queue implementations I've found seem to be really old. Could someone suggest one to me? 回答1: A quick search for "queue" on http://quickdocs.org turned up a few choices. I looked at the

LISP: Why doesn't mapcan accept my list give as parameters?

回眸只為那壹抹淺笑 提交于 2019-12-23 20:49:12
问题 To simplify my question: why this works (mapcan #'(lambda (l) (list '1 '2) ) '(a b)) and this doesn't (mapcan #'(lambda (l) '(1 2) ) '(a b)) ? I have to write a function that substitutes an element through all elements of list D at all levels of a given list L, using Map Functions. I tried using mapcan for this: (defun subAll (l k d) (cond ((and (atom l) (eq l k)) d) ((and (atom l) (not (eq l k))) (cons l '())) (t (cons (mapcan #'(lambda (l) (subAll l k d)) l) '())))) but I get following

Converting some LISP to C#

六眼飞鱼酱① 提交于 2019-12-23 20:23:10
问题 I'm reading Paul Graham's A Plan for Spam and want to understand it better but my LISP is really rusty. He has a snippet of code that calculates probability as such: (let ((g (* 2 (or (gethash word good) 0))) (b (or (gethash word bad) 0))) (unless (< (+ g b) 5) (max .01 (min .99 (float (/ (min 1 (/ b nbad)) (+ (min 1 (/ g ngood)) (min 1 (/ b nbad))))))))) My question is twofold: (1) is there a web resource that will convert LISP to a different language? (my preference would be a C based

Use package shadowing symbols

那年仲夏 提交于 2019-12-23 19:50:39
问题 For instance I have this package definition which shadows COMMON-LISP:LISTEN : (defpackage :shadows (:use :common-lisp) (:shadow #:listen) (:export #:listen)) And then I want to use this package from another package, say (defpackage :light (:use :common-lisp :shadows)) What is the purpose of shadow if I cannot actually override Common Lisp symbols when using the package ? 回答1: Simple The :shadow argument to defpackage affects the definition of the package shadows , not the later use of

About generalized variable in onlisp

…衆ロ難τιáo~ 提交于 2019-12-23 19:17:10
问题 I am not sure what is going on here, a macro example in the text. Basically, not comfortable with how to use get-setf-method , a built-in macro (maybe function?). To be specific, how about the case that some of the return values of get-setf-method are nil? e.g. (get-setf-method 'x) NIL ; NIL ; (#:NEW-3069) ; (SETQ X #:NEW-3069) ; X And why this example code set the fifth return value to the second return value first, for initialization? Finally how it can handle the order of setting the

Modifying function; saving to new function in lisp

可紊 提交于 2019-12-23 18:33:54
问题 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, they are also reflected in the new function on which it is based. Note: I am not the one writing the original function so I can't necessarily encapsulate the common parts in a

Common lisp, CFFI, and instantiating c structs

巧了我就是萌 提交于 2019-12-23 18:29:09
问题 I've been on google for about, oh, 3 hours looking for a solution to this "problem." I'm trying to figure out how to instantiate a C structure in lisp using CFFI. I have a struct in c: struct cpVect{cpFloat x,y;} Simple right? I have auto-generated CFFI bindings (swig, I think) to this struct: (cffi:defcstruct #.(chipmunk-lispify "cpVect" 'classname) (#.(chipmunk-lispify "x" 'slotname) :double) (#.(chipmunk-lispify "y" 'slotname) :double)) This generates a struct "VECT" with slots :X and :Y,

list with initial-element are start from 99 to 0 in Lisp

不羁的心 提交于 2019-12-23 18:20:31
问题 Function that takes a positive number and creates a list of all numbers between 0 (included) and the number passed as an argument (excluded). By default, it's 100 (defun list-numbers (&optional (n 100)) (mapcar #'abs (make-list n :initial-element (- n 1)))) if you want to see the result https://ideone.com/Jbz5u3 (99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99

Why does SBCL eval function lose the macrolet it's running in?

纵然是瞬间 提交于 2019-12-23 17:58:21
问题 (print x) prints exactly what I want to eval, but (eval x) fails, but if I run x it works! What am I missing? Please tell me why this doesn't work, or if I'm doing something stupid. I'm trying to print a table of dynamic size and setting lambda variables to eventually evaluate an expression for each cell in the table. BTW I figured out why eval fails. (eval x) is losing the macrolet, but WHY?! This works: (defvar varlist '(a b c d)) (defvar vvars '(c d)) (defvar hvars '(a b)) (macrolet (

Clojure: iterate over map of sets

為{幸葍}努か 提交于 2019-12-23 17:21:35
问题 This is pretty much a follow-up to my last question (Clojure idiomatic way to update multiple values of map), but not quite the same. (keep in mind that I'm fairly new to Clojure and functional languages alike) suppose I have the following data structure, defined as a map of sets: (def m1 {:1 #{2} :2 #{1 3} :3 #{1}}) and a map of maps as such: (def m2 {:1 {:1 0 :2 12 :3 23} :2 {:1 23 :2 0 :3 4} :3 {:1 2 :2 4 :3 0}}) What I want to do is update the registries of m2 that have a correspondence