lisp

Extract the second level headline

為{幸葍}努か 提交于 2019-12-22 12:21:38
问题 For my global TODO list, I am showing breadcrumbs as suggested here : (concat \"[ \"(org-format-outline-path (org-get-outline-path)) \" ]\") ") to produce following: I would like to show only the second level of project breadcrumb. So in this case, I would only display [Project A] . I think if I can make a function that can extract the second level, I just need to prepend with %? so that [Tasks] does not appear for Tasks, but only project names would appear for Projects. What would be an

Why won't my little lisp QUOTE?

倖福魔咒の 提交于 2019-12-22 12:17:13
问题 I've been writing up a micro-mini-lisp based on the encoding in minilisp, the McCarthy paper (as emended by the Roots of Lisp), and using a (possibly objectionable) style based on the J Incunabulum. And using the PP_NARG macro from here. I was also motivated by my previous project, a codegolf'ed lambda calculus interpreter which I later discovered to be eerily similar to the 1999 ioccc Lisp interpreter, particularly in the use of cursors rather than pointers to refer to memory addresses. It

How can I view the definition of a function in lisp (sbcl)?

ε祈祈猫儿з 提交于 2019-12-22 08:48:20
问题 I use sbcl+emacs+slime . I writing a function in lisp, I use C-c C-c compile, but i've already deleted it. I can't find it. I want to know how I define it. I tried use function-lambda-expression , but I get this: (function-lambda-expression #'b) T B I hope someone can give me some help.Thanks very much in advance! Thanks Vsevolod. If function define in repl , i can use (descri #'function-name) get how i define the function, but if i through C-c C-c define it, i just get source file My attempt

Understanding tailp in Common Lisp

自闭症网瘾萝莉.ら 提交于 2019-12-22 08:29:32
问题 While looking through the "Common Lisp Quick Reference" by Bert Burgemeister, I stumbled over tailp . First, I misunderstood the definitions of this function. And I tried: (tailp '(3 4 5) '(1 2 3 4 5)) But it returned NIL CLTL2 says, tailp is true iff the first argument is any (nthcdr n list) with existing n . (nthcdr 2 '(1 2 3 4 5)) ;; (3 4 5) I further tried: (tailp '(3 4 5) '(1 2 3 4 5)) ;; NIL - and I would expect: T following the definition above. (tailp '() '(1 2 3 4 5)) ;; T (tailp '5

Why does function apply complain about long lists?

给你一囗甜甜゛ 提交于 2019-12-22 08:24:54
问题 As part of some Eulerian travails, I'm trying to code a Sieve of Eratosthenes with a factorization wheel. My code so far is: (defun ring (&rest content) "Returns a circular list containing the elements in content. The returned list starts with the first element of content." (setf (cdr (last content)) content)) (defun factorization-wheel (lst) "Returns a circular list containing a factorization wheel using the list of prime numbers in lst" (let ((circumference (apply #'* lst))) (loop for i

Is there a better way to get the nth item in a list?

做~自己de王妃 提交于 2019-12-22 08:09:11
问题 The following two expressions are equivalent: (third (list 1 2 3 4)) (first (nthcdr 2 (list 1 2 3 4))) However, using "third," "fourth," "fifth," etc. isn't always practical and (first (nthcdr n list)) seems a little verbose. Is there a way to say something like (item 2 (list 1 2 3 4)) to get the nth item in a list? 回答1: (nth 3 (list 1 2 3 4)) returns 4th item (zero based!) According to the HyperSpec: Accessor NTH Description: nth locates the n th element of list , where the car of the list

Racket: Identifying tail recursion?

自古美人都是妖i 提交于 2019-12-22 07:18:08
问题 I wrote two different functions in racket to determine whether a list of numbers is ascending: (define (ascending list) (if (<= (length list) 1) #t (and (< (car list) (car (cdr list))) (ascending (cdr list))))) (define (ascending-tail list) (ascending-tail-helper #t list)) (define (ascending-tail-helper prevBool rest) (if (<= (length rest) 1) prevBool (ascending-tail-helper (and prevBool (< (car rest) (car (cdr rest)))) (cdr rest)))) I had the hardest time determining whether or not the first

How can I define the address that swank server should listen to?

点点圈 提交于 2019-12-22 05:53:18
问题 There is no argument for setting the address to bind to when starting swank server: * (describe 'swank:create-server) => ... Lambda-list: (&KEY (PORT DEFAULT-SERVER-PORT) (STYLE *COMMUNICATION-STYLE*) (DONT-CLOSE *DONT-CLOSE*) (CODING-SYSTEM *CODING-SYSTEM*)) ... How can I do it? 回答1: Bind swank::*loopback-interface* to a string containing the ip address for the swank server. It defaults to the localhost ("127.0.0.1"). For security, take care that the swank address is not wide open to the

Can one safely ignore the difference between a macro and a built-in?

主宰稳场 提交于 2019-12-22 04:49:12
问题 I'm starting out with Clojure, which is also my first lisp. There's obviously a lot to take in, and in an attempt to lessen the cognitive load, I try to find the parts which I can safely ignore (for now). Can one safely treat forms with macros and forms with built-ins the same, or are there pitfalls that will spring up later? In other words, will I ever run into a situation where I need to know that (defn f1 []) expands to (def f1 (.withMeta (clojure.core/fn f1 ([])) (.meta (var f1)))) 回答1:

Why is the @ sign needed in this macro definition?

自古美人都是妖i 提交于 2019-12-22 04:47:23
问题 In the following when macro: (defmacro when (condition &rest body) `(if ,condition (progn ,@body))) Why is the there an at sign? 回答1: It's very easy to see the difference by making a little experiment > (let ((x '(1 2 3 4))) `(this is an example ,x of expansion)) (THIS IS AN EXAMPLE (1 2 3 4) OF EXPANSION) > (let ((x '(1 2 3 4))) `(this is an example ,@x of expansion)) (THIS IS AN EXAMPLE 1 2 3 4 OF EXPANSION) As you can see the use of ,@ will place the elements of the list directly inside in