It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have a list of expressions that I want to evaluate in order inside a macro and return the value of the last one. I've tried this, but the compiler doesn't like it:
(defmacro foo lst-of-exprs
',#lst-of-exprs)
and
(defmacro foo lst-of-exprs
'(progn ,#(lst-of-exprs))
Is there a way to do this without using a do loop?
You want
(defmacro foo lst-of-exprs
`(progn ,#lst-of-exprs))
although really this is just defining a synonym for progn itself.
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I'm currently trying to recreate an old program written in UCI Lisp using Common lisp but I'm not very fluent with Lisp.
The original function is:
(DE SETROLE (ROLE FILLER CD)
(CONS (HEADER:CD CD)
(APPEND (FOR (PAIR IN (ROLES:CD CD))
(WHEN (NOT (EQUAL (ROLE:PAIR PAIR) ROLE)))
(SAVE PAIR))
(LIST (LIST ROLE FILLER]
Here's my common lisp interpretation:
(defun setrole (role filler cd)
(cons (header/cd cd)
(append (loop for pair in (roles/cd cd)
do (when (not (equal (role/pair pair) role))
(save pair)))
(list (list role filler)))))
This is the error that comes up:
*** - EVAL: variable WHEN has no value
My initial thinking is that there is no equivalent 'save' function. The description of the function is:
SETROLE Makes a new CD form with (ROLE FILLER) added or replacing the old (ROLE ...) pair.
Kindly help, I'm stumped
I found the bug. There was a loose 'when' in the wild below the code.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
Find the setf way of doing the equivalent of fset in lisp.
(symbol-function 'foo) is a Generalized Variable in elisp, so you can use:
(setf (symbol-function 'forward-word) #'backward-word)
as an alternative to:
(fset 'forward-word #'backward-word)
(As a side-note, you can do the same thing with cl-letf as a replacement for the deprecated flet when you want to override a function using dynamic scope.)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How can i get something like:
(my-macro name) => (foo "foo-transformed-arg-name")
I only obtained
(foo \#" foo-transformed-arg-name \#")
How can i avoid the #" in my macro output?
(defmacro foo (sym)
(symbol-name sym))
or
(defmacro foo (sym)
(string-downcase (symbol-name sym)))
I don't get why you would need any macro like this, but you will know best.
This is probably what you want to do:
(defmacro static-string (func &rest characters)
`(,func ,(coerce characters 'string)))
Perhaps it may make sense if you need to define some string constants instead of creating them at run time...
And this is the only way I can think of you being able to arrive at your current result:
(defmacro quote-symbol-quote (func symbol)
(list func #\" symbol #\"))
Stackoverflow highlighting is misleading. What you are getting in the result is a function called with three arguments: the quote character, the symbol foo-transformed-arg-name and the quote character again.
The resolution was very simple. My real probem was how can I convert mi argument symbol of a macro to an string.
(my-macro foo) => (other-func "foo")
That is convert the sybol foo to "FOO".
For that i used the symbol-name function
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I want to have a menu which I would call when I'll need it. I think that minor mode -- is the way to go. So I've written a minor mode, which only defines keymap and easy-menu:
;; keymap:
(defvar bk-mdanalysis-mode-map
(let ((map (make-sparse-keymap)))
map)
"Keymap for bk-mdanalysis minor mode")
;; menu:
(easy-menu-define mda bk-mdanalysis-mode-map "bk-mdanalysis-mode menu"
'("BK-MDA"
["Test" (lambda () (interactive) (insert "test!")) t]
))
(define-minor-mode bk-mdanalysis-mode
nil nil nil
bk-mdanalysis-mode-map)
(provide 'bk-mdanalysis-mode)
For some reason it doesn't work. What is wrong?
Edit:
Wait a minute -- it works!
Should I delete it now -- or what?
You placed bk-mdanalysis-mode-map as 5th argument to define-minor-mode whereas it should be the 4th argument. Lucky for you define-minor-mode will use it by default anyway, so it still works and this 5th argument will just be ignored.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I've been struggling with this question for the past few hours, scoured the internet for help, and I still can't seem to figure it out.
The question is simple:
Write a recursive program (in lisp) that takes a list and returns the number of 'a atoms in the list.
From the research I've done, it seems like LISP has an implicit counter in it, where if you just do (+ 1) it will keep track? Is this off?
Please help, I'm pretty frustrated...
The idea here is not to use a global variable, but instead to keep the count "in the stack".
Here's a Scheme solution. I'm sure you'll be able to convert this to whatever Lisp dialect you're using:
(define (count-a lst)
(cond ((null? lst) 0)
((eq? (car lst) 'a) (+ (count-a (cdr lst)) 1))
(else (count-a (cdr lst)))))
If that's not DRY enough for you, here's a more condensed version:
(define (count-a lst)
(if (null? lst) 0
(+ (count-a (cdr lst)) (if (eq? (car lst) 'a) 1 0))))
You just need to have a counter carry along in a parameter. I haven't used LISP in forever but just a simple (+ counterName 1) as a parameter should keep track. Don't forget to throw it a starting value though.