all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* a little help with  basic elisp
@ 2015-02-20  6:47 Glen Stark
  2015-02-20  7:39 ` Barry Margolin
  2015-02-20  7:52 ` Drew Adams
  0 siblings, 2 replies; 3+ messages in thread
From: Glen Stark @ 2015-02-20  6:47 UTC (permalink / raw)
  To: help-gnu-emacs

Hi everyone

I'm having trouble with the basics of lisp, and I'd like some help 
understanding and correcting what I am doing wrong in the following mce:


(defun gas-push-sr-pair ()
  "I want to add a apair consisting of a the string I prompted for at the 
mini-buffer, and the string yo"
  (interactive)
  (let (to-string)
	(setq to-string (read-from-minibuffer (concat (thing-at-point 
'symbol) " to: ")))
	(add-to-list 'gas-sr-stack  '(to-string . "yo") )
	)
  )


When I run this, and do   (insert (pop gas-sr-stack)), I get the 
following:

  gas-pop-word: Wrong type argument: char-or-string-p, (to-string . "yo")

From this I can see that I probably can't insert a char-or-string-p.  I 
guess I can figure that out -- it's not really part of my end goal 
problem anyway.

What's tripping me up is it seems that the values stored in the char-or-
string-p are to-string and "yo".

I wanted to store the value which is currently in to-string, and "yo".  

Can someone please explain to me what I am doing wrong?  I'd like to 
understand the language better, and of course solve my concrete problem.

Cheers


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: a little help with  basic elisp
  2015-02-20  6:47 a little help with basic elisp Glen Stark
@ 2015-02-20  7:39 ` Barry Margolin
  2015-02-20  7:52 ` Drew Adams
  1 sibling, 0 replies; 3+ messages in thread
From: Barry Margolin @ 2015-02-20  7:39 UTC (permalink / raw)
  To: help-gnu-emacs

In article <ILAFw.813229$394.409278@fx25.am4>,
 Glen Stark <mail@glenstark.net> wrote:

> Hi everyone
> 
> I'm having trouble with the basics of lisp, and I'd like some help 
> understanding and correcting what I am doing wrong in the following mce:
> 
> 
> (defun gas-push-sr-pair ()
>   "I want to add a apair consisting of a the string I prompted for at the 
> mini-buffer, and the string yo"
>   (interactive)
>   (let (to-string)
> 	(setq to-string (read-from-minibuffer (concat (thing-at-point 
> 'symbol) " to: ")))
> 	(add-to-list 'gas-sr-stack  '(to-string . "yo") )
> 	)
>   )
> 
> 
> When I run this, and do   (insert (pop gas-sr-stack)), I get the 
> following:
> 
>   gas-pop-word: Wrong type argument: char-or-string-p, (to-string . "yo")
> 
> From this I can see that I probably can't insert a char-or-string-p.  I 

No, you can ONLY insert a char-or-string-p. It's telling you what type 
it's supposed to be. Since it wasn't, you got an error.

> guess I can figure that out -- it's not really part of my end goal 
> problem anyway.

> 
> What's tripping me up is it seems that the values stored in the char-or-
> string-p are to-string and "yo".

(to-string . "yo") is a cons. Its car is the symbol to-string, its cdr 
is the string "yo". You can't insert a cons.

> 
> I wanted to store the value which is currently in to-string, and "yo". 

When you quote something, you prevent evaluation of the contents. If you 
want to get the value of to-string, you have to access it without 
quoting:

(add-to-list 'gas-sr-stack (cons to-string "yo"))

> 
> Can someone please explain to me what I am doing wrong?  I'd like to 
> understand the language better, and of course solve my concrete problem.
> 
> Cheers

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***


^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: a little help with  basic elisp
  2015-02-20  6:47 a little help with basic elisp Glen Stark
  2015-02-20  7:39 ` Barry Margolin
@ 2015-02-20  7:52 ` Drew Adams
  1 sibling, 0 replies; 3+ messages in thread
From: Drew Adams @ 2015-02-20  7:52 UTC (permalink / raw)
  To: Glen Stark, help-gnu-emacs

> (defun gas-push-sr-pair ()
>   "I want to add a apair consisting of a the string I prompted for at the
> mini-buffer, and the string yo"
>   (interactive)
>   (let (to-string)
> 	(setq to-string (read-from-minibuffer (concat (thing-at-point
>                                                      'symbol)
>                                                     " to: ")))
> 	(add-to-list 'gas-sr-stack  '(to-string . "yo"))))
> 
> When I run this, and do (insert (pop gas-sr-stack)), I get the
> following:
>   gas-pop-word: Wrong type argument: char-or-string-p, (to-string . "yo")
> 
> What's tripping me up is it seems that the values stored in the char-or-
> string-p are to-string and "yo".
> I wanted to store the value which is currently in to-string, and "yo".
> 
> Can someone please explain to me what I am doing wrong?  I'd like to
> understand the language better, and of course solve my concrete problem.

(defvar gas-sr-stack () "...")

(defun gas-push-sr-pair ()
  (interactive)
  (let ((to-string (read-from-minibuffer (concat (thing-at-point 'symbol) " to: "))))
    (add-to-list 'gas-sr-stack  `(,to-string . "yo"))))

And you want this instead of just (pop (car gas-sr-stack)):

(let ((gas-sr  (pop gas-sr-stack)))
  (insert (car gas-sr) (cdr gas-sr)))

1. Just bind `to-string' directly to the value you want it to have.
   (Not an error; it's just simpler.)
2. You need to evaluate `to-string' for the cons you want to add to the list.
   Instead, you were inserting the constant cons (to-string . "yo") each time.
   So use a comma inside a backtick - or use (cons to-string "yo").
3. The main problem was that you were trying to insert the cons, not its car
   and cdr (which are strings).  Use `C-h f insert' to see info about `insert'.



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-02-20  7:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-20  6:47 a little help with basic elisp Glen Stark
2015-02-20  7:39 ` Barry Margolin
2015-02-20  7:52 ` Drew Adams

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.