lisp

Example of Sharpsign Equal-Sign reader macro?

廉价感情. 提交于 2019-12-06 12:12:02
问题 I've seen this used once, but couldn't understand what it does. The reference says that it is #n=object reads as whatever object has object as its printed representation. However, that object is labeled by n, a required unsigned decimal integer, for possible reference by the syntax #n#. The scope of the label is the expression being read by the outermost call to read; within this expression, the same label may not appear twice. Which to me reads as just 56 randomly selected words of English

How to know whether a symbol represents function or macro?

不羁岁月 提交于 2019-12-06 11:56:55
I'm writing a macro for function / macro composition (mixed combinations are possible). Inside of the macro I have to treat symbols which represent functions and those that name macros differently. It is because result function must work with any number of arguments (if 'lowest' function in composition can), and I cannot apply apply to macros. My question: how to determine what a given symbol represents: function or macro? Macro: CL-USER 8 > (macro-function 'bar) NIL CL-USER 9 > (macro-function 'lambda) #<Function LAMBDA 41100B7E94> Function: CL-USER 15 > (and (fboundp '+) (not (macro-function

Is there a use for double unquote (double comma) when defining a Lisp macro?

自闭症网瘾萝莉.ら 提交于 2019-12-06 11:56:30
问题 When one is defining a macro that uses a macrolet, or defining a macro that defines a macro, it seems one uses ,', or , to unquote things. Is there ever a case when I need to use ,, ? 回答1: Sure. Here is code from Graham's "On Lisp": (defmacro =defun (name parms &body body) (let ((f (intern (concatenate 'string "=" (symbol-name name))))) `(progn (defmacro ,name ,parms `(,',f *cont* ,,@parms)) (defun ,f (*cont* ,@parms) ,@body)))) Another example is from clx/gcontext.lisp : (macrolet ((def-gc

load external with emacs-slime

回眸只為那壹抹淺笑 提交于 2019-12-06 10:42:30
I'd like to install slime on my Emacs 23.2.1. Since M-x slime doesn't succeed in start it, I modified the ~/.emacs file. (setq inferior-lisp-program "/usr/bin/sbcl") (add-to-list 'load-path "/usr/share/emacs/site-lisp/slime/") (require 'slime) (slime-setup) Of course this doesn't work for the slime path in the second line of ~/.emacs file should be /usr/share/common-lisp/source/swank instead. However, after I changed this directory, the error remains. It says like this: Couldn't load "/usr/share/emacs/site-lisp/slime/swank-loader.lisp": file does not exist. Why would this load external remain

Function name and dynamic binding in Common Lisp

孤者浪人 提交于 2019-12-06 10:09:59
I'm reading Peter Norvig's Paradigms of AI . In chapter 6.2, the author uses code like below ( not the original code, I picked out the troubling part ): Code Snippet: (progv '(op arg) '(1+ 1) (eval '(op arg))) As the author's original intent, this code should return 2 , but in sbcl 1.1.1 , the interpreter is apparently not looking up op in the environment, throwing out op: undefined function . Is this implementation specific? Since the code must have been tested on some other lisp. p.s Original code You probably mean (progv '(op arg) '(1+ 1) (eval '(funcall op arg))) Edit(2013-08-21): PAIP was

Implementing basic library functions in LISP (manually)

可紊 提交于 2019-12-06 09:41:22
Is there any way by which I can define functions my_list , my_cons , my_append which perform similar function as list , cons and append respectively? Otherwise where can I find the implementation of these functions? Thanks For my_list and my_append, the solutions are: (defun my_list (&rest arguments) `(,@arguments) ) (defun my_append (a_list an_item) `(,@a_list ,an_item) ) (my_append (my_list 'a 'b 'c) 'd) I'm probably wrong but I dont know any alternative method to make pairs, so an alternative to cons do not seems possible. Still, I'm quite new to the LISP world. If you want your lists to be

Error setting load-noisily? and auto-exiting in MIT-Scheme

自作多情 提交于 2019-12-06 08:46:24
In order to debug MIT-Scheme scripts with Vim, I want to be able to run the script file currently being edited as conveniently as possible. Here is what I'm doing: sicp.scm (set! load-noisily? #t) (define (abs x) (cond ((> x 0) x) ((= x 0) 0) ((< x 0) (- x)) ) ) (abs 42) (abs -24) (exit) After executing :!mit-scheme --eval "(load \"sicp\")" when editing sicp.scm in Vim, I get: Image saved on Saturday May 17, 2014 at 2:39:25 AM Release 9.2 || Microcode 15.3 || Runtime 15.7 || SF 4.41 || LIAR/x86-64 4.118 Edwin 3.116 ;Loading "sicp.scm"... Kill Scheme (y or n)? There are two main issues: The

How to stop evaluating lisp form when passed as function parameter?

喜夏-厌秋 提交于 2019-12-06 08:18:37
I am learning Lisp. Now I am trying to create a function that takes some valid Lisp form as argument and returns a function that executes the Lisp forms when called. For example: (defun fn (name action) (setf (symbol-function name) #'(lambda () action))) When I am passing say (+ 4 5 6) the function is getting created with specific name and when called returning the sum. (fn 'add (+ 4 5 6)) (add) ==> 15 But if I invoke (fn 'error (assert (= 2 3)) it is throwing error (= 2 3) must evaluate to a non-NIL value. and the function with name error is not created. How can I stop this evaluation of

Eval and lexical variables

我的未来我决定 提交于 2019-12-06 08:18:18
I'm doing a small project just for fun, and I added eval support for it to make debug easier. But later I found a problem: (let ((x 1)) (eval (1+ x))) (defun foo (x form) (eval form)) (foo 1 '(1+ x)) Code above won't work. Could someone please explain why and how to work it around? Thanks very much. First, though (let ((x 1)) (eval (1+ x))) may look like it does work (it certainly does something), it is likely not doing, what you intend it to do. eval is a regular function, so it receives its arguments evaluated by the caller. Effectively, you are calling eval with an integer value of 2 --

Extract the second level headline

六眼飞鱼酱① 提交于 2019-12-06 08:08:24
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 ideal way of extracting the second level? All you have to do to get the second element of (org-get-outline