I am a beginner to elisp. I am facing an error evaluating the simple code given below:
(let (set-id 1) (
(message set-id))
I am getting the error:
Debugger entered--Lisp error: (invalid-function (message set-id))
((message set-id))
eval(((message set-id)) nil)
eval-last-sexp-1(t)
eval-last-sexp(t)
eval-print-last-sexp()
call-interactively(eval-print-last-sexp nil nil)
Can anyone show me some light?
The proper syntax is this:
(let ((set-id 1))
(message "%s" set-id))
Related
I have a problem with js promises:
I'm trying to convert this js code:
stripe.createToken(card).then(function(result) {
if (result.error) {
// Inform the customer that there was an error.
var errorElement = document.getElementById('card-errors');
errorElement.textContent = result.error.message;
} else {
// Send the token to your server.
stripeTokenHandler(result.token);
}
And I have the following:
(go
(let [result (<!
(.createToken stripe #(subscribe [:card-element]))
)]
(prn "result is" result)
;; (if (.-error result)
;; (.textContent (js/document.getElementById "card-errors") (.-message .-error result))
;; (prn "response is" (js/stripeTokenHandler (.-token result)))
;; )
)
)
But I get "No protocol method ReadPort.take! defined for type object: [object Promise]"
How do I do the js .then() part in cljs?
It seems you are a little bit confused with JavaScript interop. You can take a look at the Cheatsheet under the JavaScript Interop section.
Here are some quick examples:
JS CLJS
object.method(arg1, arg2) <=> (.method object arg1 arg2)
object.field <=> (.-field object)
object.field = "foo" <=> (set! (.-field object) "foo")
object.nested.field <=> (.-field (.-nested object))
To improve readability, you can use the -> arrow macro:
object.nested.field <=> (-> object .-nested .-field)
You can then rewrite your example as:
(-> (.createToken stripe card)
(.then (fn [result]
(if-let [error (.-error result)]
(-> (.getElementById js/document "card-errors")
(.-textContent)
(set! (.-message error)))
(js/stripeTokenHandler (.-token result)))))
;; if there is a `catch` branch
(.catch (fn […] …)))
I'm trying to configuring Emacs on Windows and there is one package "use-package" which I wanna to insert in this on my configuration, but when I press to execute on Emacs show the message "Symbol's function definition is void: use-package"
(setq inhibit-startup-message t)
(require 'package)
(setq package-enable-at-startup nil)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
(add-to-list 'package-archives '("gnu" . "https://elpa.gnu.org/packages/"))
(package-initialize)
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))
Sometimes I receive error message "use-package is unavailable."
Debugger entered--Lisp error: (void-function package-installed-p)
(package-installed-p (quote use-package))
(if (package-installed-p (quote use-package)) nil (package-refresh-contents) (package-install (quote use-package)))
eval((if (package-installed-p (quote use-package)) nil (package-refresh-contents) (package-install (quote use-package))) nil)
elisp--eval-last-sexp(nil)
eval-last-sexp(nil)
funcall-interactively(eval-last-sexp nil)
call-interactively(eval-last-sexp nil nil)
command-execute(eval-last-sexp)
You should be able to find use-package in the list produced with M-x package-list-packages. If that is the case, then (package-install 'use-package) should succeed: the package is available on MELPA.
To use it, you have to add
(require 'use-package)
to your .emacs (or equivalent).
Sorry if this is a silly question; I am a complete novice when it comes to emacs.
Recently, I began to do research on how to set up emacs and stumbled upon a great video series by Mike Zamansky. However, whilst following this video (creating an org init file), all of the packages I installed onto my emacsclient proceeded to not work. During initialization, there was an error - namely, "Symbol's value as variable is void: Removes." I copied his tutorial verbatim and I don't see any potential syntactical errors - perhaps I overlooked some errors. However, I've been searching throughout the internet, but could not find any answers to this problem.
Here is the contents of the init.el file:
(require 'package)
(setq package-enable-at-startup nil)
(add-to-list 'package-archives
'("melpa" . "http://melpa.org/packages/"))
(package-initialize)
;; Bootstrap 'use-package'
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))
(org-babel-load-file (expand-file-name "~/.emacs.d/myinit.org"))
Here is the error:
Warning (initialization): An error occurred while loading
‘/Users/Kyojin/.emacs.d/init.el’:
Symbol's value as variable is void: Removes
To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file. Start Emacs with
the ‘--debug-init’ option to view a complete error backtrace.
Debugger Output (--debug-init):
Debugger entered--Lisp error: (void-variable Removes)
eval-buffer(#<buffer *load*-527594> nil
"/Users/Kyojin/.emacs.d/myinit.el" nil t) ; Reading at buffer position
8
load-with-code-conversion("/Users/Kyojin/.emacs.d/myinit.el"
"/Users/Kyojin/.emacs.d/myinit.el" nil nil)
load("/Users/Kyojin/.emacs.d/myinit.el" nil nil t)
load-file("/Users/Kyojin/.emacs.d/myinit.el")
(progn (load-file exported-file) "Loaded")
(if compile (progn (byte-compile-file exported-file (quote load))
"Compiled and loaded") (progn (load-file exported-file) "Loaded"))
(message "%s %s" (if compile (progn (byte-compile-file exported-file
(quote load)) "Compiled and loaded") (progn (load-file exported-file)
"Loaded")) exported-file)
(let* ((age (function (lambda (file) (float-time (time-subtract
(current-time) (nth 5 ...)))))) (base-name (file-name-sans-extension
file)) (exported-file (concat base-name ".el"))) (if (and (file-exists-
p exported-file) (> (funcall age file) (funcall age exported-file)))
nil (setq exported-file (car (last (org-babel-tangle-file file
exported-file "emacs-lisp"))))) (message "%s %s" (if compile (progn
(byte-compile-file exported-file (quote load)) "Compiled and loaded")
(progn (load-file exported-file) "Loaded")) exported-file))
org-babel-load-file("/Users/Kyojin/.emacs.d/myinit.org")
eval-buffer(#<buffer *load*> nil "/Users/Kyojin/.emacs.d/init.el"
nil t) ; Reading at buffer position 358
load-with-code-conversion("/Users/Kyojin/.emacs.d/init.el"
"/Users/Kyojin/.emacs.d/init.el" t t)
load("/Users/Kyojin/.emacs.d/init" t t)
#[0"\205\266\306=\203\307\310Q\202?\311=\204\307\312Q\202?\313\307
\314\315#\203* \316\202?\313\307\314\317#\203>\320\321\322!D\nB\323
\202?\316\324\325\324\211#\210\324=\203e\326\327\330\307\331Q!\"\325
\324\211#\210\324=\203d\210\203\247\332!\333\232\203\247\334!
\211\335P\336!\203\201\211\202\214\336!\203\213\202\214\314\262\
\203\245\337\"\203\243\340\341#\210\342\343!\210\266\f\205\264\314\325
\344\324\211#)\262\207"[init-file-user system-type
delayed-warnings-list user-init-file inhibit-default-init inhibit-
startup-screen ms-dos "~" "/_emacs" windows-nt "/.emacs" directory-
files nil "^\\.emacs\\(\\.elc?\\)?$" "~/.emacs" "^_emacs\\(\\.elc?\\)?
$" initialization format-message "`_emacs' init file is deprecated,
please use `.emacs'" "~/_emacs" t load expand-file-name "init" file-
name-as-directory "/.emacs.d" file-name-extension "elc" file-name-sans-
extension ".el" file-exists-p file-newer-than-file-p message "Warning:
%s is newer than %s" sit-for 1 "default"] 7]()
command-line()
normal-top-level()
Search for the word Removes in your init file, "/Users/Kyojin/.emacs.d/myinit.el" (or possibly in some file that it loads).
If you don't find it immediately then recursively bisect your init file to find the code that is problematic. You can do that by commenting out first 1/2, then 3/4, then 7/8,... of the file until you locate the problem. You can comment a block of text/code by selecting it and then using M-x comment-region. You can uncomment a selection the same way, but with C-u first: C-u M-x comment-region.
I am unable to access remote files in my usual way:
C-x C-f
[server]:[path][file]
and am thrown this error:
Wrong Type Argument: listp, [[server]:[path][file]
I'm not even sure how to debug this further.
any help is appreciated.
edit:
output when trying to debug:
Debugger entered: nil
(progn (debug) (ido-mode t) (progn (ad-add-advice (quote completing-read) (quote (foo nil
t (advice lambda nil (if (boundp ...) ad-do-it (setq ad-return-value ...))))) (quote
around) (quote nil)) (ad-activate (quote completing-read) nil) (quote completing-read)) (define-key global-map [(meta 120)] (function (lambda nil (interactive) (call-interactively
(intern (ido-completing-read "M-x " (all-completions "" obarray ...))))))))
(if (fboundp (quote ido-mode)) (progn (debug) (ido-mode t) (progn (ad-add-advice (quote
completing-read) (quote (foo nil t (advice lambda nil (if ... ad-do-it ...)))) (quote
around) (quote nil)) (ad-activate (quote completing-read) nil) (quote completing-read))
(define-key global-map [(meta 120)] (function (lambda nil (interactive) (call-
interactively (intern (ido-completing-read "M-x " ...))))))))
eval-buffer() ; Reading at buffer position 16103
call-interactively(eval-buffer)
(lambda nil (interactive) (call-interactively (intern (ido-completing-read "M-x " (all-
completions "" obarray (quote commandp))))))()
call-interactively((lambda nil (interactive) (call-interactively (intern (ido-completing-
read "M-x " (all-completions "" obarray (quote commandp)))))) nil nil)
recursive-edit()
debug(debug)
implement-debug-on-entry()
* ido-find-file()
call-interactively(ido-find-file nil nil)
And this from my init.el:
(require 'ido)
(if (fboundp 'ido-mode)
(progn
(debug)
(ido-mode t)
(defadvice completing-read
(around foo activate)
(if (boundp 'ido-cur-list)
ad-do-it
(setq ad-return-value
(ido-completing-read
prompt
(all-completions "" collection predicate)
nil require-match initial-input hist def))))
(define-key global-map [(meta ?x)]
(lambda ()
(interactive)
(call-interactively
(intern
(ido-completing-read "M-x " (all-completions "" obarray 'commandp))))))))
Check what command C-x C-f is bound to (use C-h k). Is it the standard binding find-file? (It doesn't sound like it.)
If not, check its interactive spec. The command is expecting to receive a list as argument, and it is instead receiving (what looks like) a string.
This is the interactive spec of find-file:
(interactive
(find-file-read-args "Find file: " (confirm-nonexistent-file-or-buffer)))
If the interactive spec of your C-x C-f command, like this one, has a non-string as its argument, then you can either M-x debug-on-entry THE-FUNCTION, where THE-FUNCTION is the function called for the argument (find-file-read-args, in the case of find-file), or wrap that argument so that the debugger is invoked:
(progn (debug) (WHATEVER-WAS-THERE-BEFORE))
Either way, the debugger will open for the interactive part of reading the file name, and you can walk through the debugger to see what goes wrong.
But probably you can figure out the problem just by inspecting the code -- the interactive spec. The argument to your command (whatever it is) is expected to be a list, but it is a string.
I would start by seeing what happens with a local file name. Do you get an error for that too?
Another thing I notice is that the error reports an extra [, in front of what you say you typed as input. That should provide a clue too. What you think it is reading is not what it has read.
I'm beginner in ANTLR and I'm learning it by an example. I use C as my target language.
The example is a Scheme R5RS grammar file taken from this question, with a little modification(rename the grammar name and add some options with the grammar specification untouched).
antlr generated the lexer and parser, and I compile it with a test main() in which I just do some initialization and simply call the parser. When runing the test program with a piece of scheme code, the parser detect some syntax error(which should not happen!)
main function in test.c
#include <stdio.h>
#include "r5rsLexer.h"
#include "r5rsParser.h"
int main(int argc, char *argv[])
{
pANTLR3_UINT8 fname;
pANTLR3_INPUT_STREAM input;
pr5rsLexer lexer;
pANTLR3_COMMON_TOKEN_STREAM tstream;
pr5rsParser parser;
r5rsParser_parse_return parse_return;
if (argc != 2)
{
ANTLR3_FPRINTF(stderr, "usage: %s file\n", argv[0]);
exit(1);
}
fname = (pANTLR3_UINT8)argv[1];
input = antlr3FileStreamNew(fname, ANTLR3_ENC_8BIT);
if (!input)
{
ANTLR3_FPRINTF(stderr, "open file stream failed\n");
exit(1);
}
lexer = r5rsLexerNew(input);
if (!lexer)
{
ANTLR3_FPRINTF(stderr, "new lexer failed\n");
exit(1);
}
tstream =
antlr3CommonTokenStreamSourceNew(ANTLR3_SIZE_HINT, TOKENSOURCE(lexer));
if (!tstream)
{
ANTLR3_FPRINTF(stderr, "open token stream failed\n");
exit(1);
}
parser = r5rsParserNew(tstream);
if (!parser)
{
ANTLR3_FPRINTF(stderr, "new parser failed\n");
exit(1);
}
parse_return = parser->parse(parser);
printf("succeed!\n");
return 0;
}
scheme code in test.scm:
(define-syntax should-be
(syntax-rules ()
((_ test-id value expression)
(let ((return-value expression))
(if (not (equal? return-value value))
(for-each (lambda (v) (display v))
`("Failure: " test-id ", expected '"
value "', got '" ,return-value "'." #\newline))
(for-each (lambda (v) (display v))
'("Passed: " test-id #\newline)))))))
(should-be 1.1 0
(let ((cont #f))
(letrec ((x (call-with-current-continuation (lambda (c) (set! cont c) 0)))
(y (call-with-current-continuation (lambda (c) (set! cont c) 0))))
(if cont
(let ((c cont))
(set! cont #f)
(set! x 1)
(set! y 1)
(c 0))
(+ x y)))))
the terminal output:
$> ls
r5rs.g test.c test.scm
$> antlr3 r5rs.g
$> ls
r5rs.g r5rs.tokens r5rsLexer.c r5rsLexer.h r5rsParser.c r5rsParser.h test.c test.scm
$> gcc -o test test.c r5rsLexer.c r5rsParser.c -lantlr3c
$> ./test test.scm
test.scm(1) : error 4 : Unexpected token, at offset 0
near [Index: 1 (Start: 154513905-Stop: 154513917) ='define-syntax', type<5> Line:1
LinePos:0]
: unexpected input...
expected one of : <EOR>
test.scm(2) : error 4 : Unexpected token, at offset 3
near [Index: 8 (Start: 154513932-Stop: 154513943) ='syntax-rules', type<7> Line: 2
LinePos:3]
: unexpected input...
expected one of : <EOR>
test.scm(2) : error 4 : Unexpected token, at offset 17
near [Index: 11 (Start: 154513946-Stop: 154513946) =')', type<82> Line: 2 LinePos:17]
: unexpected input...
expected one of : <EOR>
test.scm(2) : error 4 : Unexpected token, at offset 17
near [Index: 11 (Start: 154513946-Stop: 154513946) =')', type<82> Line: 2 LinePos:17]
: unexpected input...
expected one of : <EOR>
I've read through the grammar specification and it is correct. I can't figure out where the problem lies ... can someone help? thanks!
===================== reply =========================
Following the grammar rule of pattern and template, I went down to the code fragment below. I think the parse is going to match template with it and failed because template doesn't have an quasiquote alternative.
`("Failure: " test-id ", expected '" value "', got '" ,return-value "'." #\newline)
I believe the grammar rule for template follows the R5RS specification correctly, and the code is accepted by other R5Rs scheme implementation(I tested it in scheme48 and guile). How can this happen?
I think there must be something wrong in my analyse ...
It is a back-tick in
`("Failure: " test-id ", expected '"
that trips the parser.
If you follow grammar rules for pattern and template, you'll see that they don't reach quasiquotation rule that match both QUASIQUOTE and back-tick. They do however reach expressionKeyword that contains QUASIQUOTE.
You should fix grammar to include abbreviated forms in template or fix your input not to use them.