From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: srinik001@hotmail.com Newsgroups: gmane.emacs.help Subject: Re: Using setq to obtain a symbol from a list, so that I can assign a function to it Date: Tue, 22 Apr 2008 21:40:31 -0700 (PDT) Organization: http://groups.google.com Message-ID: <530940ca-d019-42d4-ba15-c8674a8eb858@59g2000hsb.googlegroups.com> References: <48505b79-009c-42c9-912f-219a06474731@f24g2000prh.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1208989875 25948 80.91.229.12 (23 Apr 2008 22:31:15 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 23 Apr 2008 22:31:15 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Apr 24 00:31:50 2008 connect(): Connection refused Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1JonVD-0006r2-R6 for geh-help-gnu-emacs@m.gmane.org; Thu, 24 Apr 2008 00:31:48 +0200 Original-Received: from localhost ([127.0.0.1]:55349 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JonUX-0006hC-UO for geh-help-gnu-emacs@m.gmane.org; Wed, 23 Apr 2008 18:31:05 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!postnews.google.com!59g2000hsb.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 70 Original-NNTP-Posting-Host: 24.6.229.192 Original-X-Trace: posting.google.com 1208925631 823 127.0.0.1 (23 Apr 2008 04:40:31 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Wed, 23 Apr 2008 04:40:31 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: 59g2000hsb.googlegroups.com; posting-host=24.6.229.192; posting-account=80yX_goAAADR1ljaDcvuAw9eDZS-8Z3p User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14,gzip(gfe),gzip(gfe) Original-Xref: shelby.stanford.edu gnu.emacs.help:158127 X-Mailman-Approved-At: Wed, 23 Apr 2008 18:26:57 -0400 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:53503 Archived-At: On Apr 22, 5:54 am, Barry Margolin wrote: > In article > , > > srinik...@hotmail.com wrote: > > Oops... I got the subject wrong. Instead of > > > " Using setq to obtain a symbol from a list, so that I can assign a > > function to it", it should read, "Using setq to assign value to the > > result of a function". Sorry about that. > > Use set instead of setq. > > -- > Barry Margolin, bar...@alum.mit.edu > Arlington, MA > *** PLEASE post questions in newsgroups, not directly to me *** > *** PLEASE don't copy me on replies, I'll read them in the group *** Thanks for the tip. Now, it does not throw an error. But I still don't get what I want. Here is what I did: (setq grammar '((sentence ::= subject predicate) (subject ::= article noun) (predicate ::= verb))) --> This of course worked. I could see the individual elements, their car's and cdr's etc. Then I defined the "leaf" level things: (defun article() (insert "article")) (defun noun() (insert "noun")) (defun verb() (insert "verb")) Then I tried this: (dolist (x grammar) (set (car x) (dolist (y (cdr (cdr x))) (funcall y))) It threw an error saying that it did not know what subject was. Of course, the way the grammar was described in the list, it did not know that. So I tried reversing the grammar, thinking that if it went the other way, it would understand subject before it came to sentence. So, I tried this. (dolist (x (reverse grammar)) (set (car x) (dolist (y (cdr (cdr x))) (funcall y)))) It still gave the same error! It seems that when it does a set operation, it forgets it in the next iteration of the loop. I apologize if these are trivial questions, but while being *very* addictive, Lisp seems unlike anything else that I have done before; perhaps I need to study Lisp a lot more before giving myself exercises like these, by studying Pascal's reply more carefully - I need to look up many of the functions/terms he uses. For example, I don't really get the difference between the quoted and the unquoted - I know they are different but can't seem to be able to put my finger on the exact difference. Thanks, Regards, SK