lisp

Variable passed to macro gets resolved in wrong namespace?

 ̄綄美尐妖づ 提交于 2019-12-19 05:57:28
问题 The Noir macro defpage is giving me a little bit of trouble. I am trying to construct a call similar to this: (defpage [:post "some/url"] [data] ;; some stuff... ) However, instead of using the keyword :post I would like to use a variable, like this: (def my-method :post) (defpage [my-method "some/url"] [data] ;; some stuff... ) The problem is that when the macro expands, it wants to resolve the variable my-method in the compojure.core namespace instead of my own, giving me the error: No such

Determining function argument list in Common Lisp

无人久伴 提交于 2019-12-19 05:22:20
问题 Is it possible to find out the argument list of a function, given a function object (or a function's symbol) in common lisp? 回答1: This is different for each CL implementation but the Swank package (provides Slime which can show arglists in f.e. Emacs' minibuffer) wraps this up in a single function: * (defun testfn (arg1 arg2 &key (arg3 :a)) (declare (ignore arg1 arg2 arg3))) TESTFN * (swank-backend:arglist #'testfn) (ARG1 ARG2 &KEY (ARG3 :A)) This will also work for methods: * (defmethod

Lisp string formatting with named parameters

喜欢而已 提交于 2019-12-19 05:17:35
问题 Is there a way in Lisp to format a string using named parameters? Perhaps something with association lists like (format t "All for ~(who)a and ~(who)a for all!~%" ((who . "one"))) in order to print "All for one and one for all" . Similar to this python question, or this scala one, or even c++, but in Lisp. If this functionality isn't in the language, does anyone have any cool functions or macros that could accomplish the same thing? 回答1: Use CL-INTERPOL. (cl-interpol:enable-interpol-syntax)

(Scheme) Recursive function to compute all possible combinations of some lists?

邮差的信 提交于 2019-12-19 04:14:30
问题 What is an example of a recursive function to compute all possible combinations of lists? For example, (combine (list 1 2 3) (list 1 2)) should return '((1 1) (1 2) (2 1) (2 2) (3 1) (3 2)) . 回答1: Here's my solution. Requires SRFIs 1 and 26 to be available. (define (cartesian-product first . rest) (define (iter l result) (define (prepend-all x) (map (cut cons <> x) l)) (concatenate (map prepend-all result))) (map reverse (fold iter (map list first) rest))) 回答2: Here's my take; I first define

Common lisp :KEY parameter use

拜拜、爱过 提交于 2019-12-19 03:46:07
问题 The :KEY parameter is included in some functions that ship with Common Lisp. All of the descriptions that I have found of them are unhelpful, and :KEY is difficult to search in a search engine because the ":" is usually ignored. How would it be used, for example, in the member function which allows both :TEST and :KEY ? 回答1: Imagine that we have a list of cities: (defparameter *cities* ; City Population Area km^2 '((Paris 2265886 105.4) (Mislata 43756 2.06) (Macau 643100 30.3) (Kallithea

Mysterious Racket error: define: unbound identifier; also, no #%app syntax transformer is bound in: define

落爺英雄遲暮 提交于 2019-12-18 15:54:12
问题 This program produces an error: define: unbound identifier; also, no #%app syntax transformer is bound in: define When pasted into the REPL (to be exact, the last line: (displayln (eval-clause clause state ))), it works. When run in definition window, it fails. I don't know why. #lang racket (define *state* '((a false) (b true) (c true) (d false))) (define *clause* '(a (not b) c)) (define (eval-clause clause state) (for ([x state]) (eval `(define ,(first x) ,(second x)))) (eval (cons 'or (map

Using Lisp in C#

北慕城南 提交于 2019-12-18 15:09:36
问题 As a lot of people pointed out in this question, Lisp is mostly used as a learning experience. Nevertheless, it would be great if I could somehow use my Lisp algorithms and combine them with my C# programs. In college my profs never could tell me how to use my Lisp routines in a program (no, not writing a GUI in Lisp, thank you). So how can I? 回答1: Try these .Net implementations of Lisp: IronScheme IronScheme will aim to be a R6RS conforming Scheme implementation based on the Microsoft DLR. L

Running Clojure and other Lisp at the same time on Emacs

风格不统一 提交于 2019-12-18 13:30:49
问题 I use Aquamacs, and Aquamacs is pre-equipped with SLIME. (setq inferior-lisp-program "/usr/local/bin/sbcl") #####!!! (add-to-list 'load-path "/Library/Application Support/Aquamacs Emacs/SLIME/contrib") (add-to-list 'load-path "/Library/Application Support/Aquamacs Emacs/SLIME") (require 'slime) (slime-setup) As is asked in somewhere, I try to use Clojure by adding this code. (add-to-list 'load-path "~/clojure/clojure-mode") (setq inferior-lisp-program "/Users/smcho/bin/clj") ################

Lisp binary size

对着背影说爱祢 提交于 2019-12-18 12:58:53
问题 As i am Interested in artificial intelligence, I recently decided to give Lisp a try. After compiling a very basic application with the common lisp compiler sbcl I noticed that the resulting binary was very big (around 43MB). I am interested of the reason for that. Is this common issue for (common) lisp and what is the technical background of this behavior? 回答1: There are several different architectures in Common Lisp implementations: interpreter byte code engine (CLISP is an example)

How to make a GUI using Lisp: DrScheme or Common Lisp

≯℡__Kan透↙ 提交于 2019-12-18 12:23:55
问题 Or the basic work need to do to create a GUI. I know the basic Components of GUI, but where to begin. I'm just a self-study person and I'm reading "How to Design Program" (HtDP) at the end of the book the author suggest that knowledge of GUI and CGI computer network are needed to be a programmer. The information of the last two is easy to find. But it seems there are little book talking about how to create a GUI. I guess maybe it's too "low" in the process designing the computer program that