From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Swami Tota Ram Shankar Newsgroups: gmane.emacs.help Subject: Style Issues in Lisp and Scheme programming, setq versus let ... and onion structure with multiple cores or eyes or kernels Re: string to list or string to array Date: Mon, 22 Oct 2012 18:16:58 -0700 (PDT) Message-ID: <657d823b-990f-4a2b-a57c-2c644099ddcd@z2g2000yqj.googlegroups.com> References: <62642868-f757-4115-a047-34c319a1c30f@o5g2000yqi.googlegroups.com> <87pq4c848a.fsf@kuiper.lan.informatimago.com> <4e87f58c-72fc-457b-8596-c792c39472e5@m4g2000yqb.googlegroups.com> <87zk3f7ey7.fsf@kuiper.lan.informatimago.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1350955212 900 80.91.229.3 (23 Oct 2012 01:20:12 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 23 Oct 2012 01:20:12 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Oct 23 03:20:21 2012 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TQTAK-0007FV-3G for geh-help-gnu-emacs@m.gmane.org; Tue, 23 Oct 2012 03:20:20 +0200 Original-Received: from localhost ([::1]:36403 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TQTAC-0007xr-9v for geh-help-gnu-emacs@m.gmane.org; Mon, 22 Oct 2012 21:20:12 -0400 Original-Received: by 10.224.186.20 with SMTP id cq20mr6870863qab.8.1350955018591; Mon, 22 Oct 2012 18:16:58 -0700 (PDT) Original-Received: by 10.236.115.33 with SMTP id d21mr1035523yhh.12.1350955018558; Mon, 22 Oct 2012 18:16:58 -0700 (PDT) Original-Path: usenet.stanford.edu!x14no4929927qar.0!news-out.google.com!r17ni57592152qap.0!nntp.google.com!x14no4929921qar.0!postnews.google.com!z2g2000yqj.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help,comp.emacs,comp.lang.lisp,comp.lang.scheme Complaints-To: groups-abuse@google.com Injection-Info: z2g2000yqj.googlegroups.com; posting-host=108.82.92.30; posting-account=dlefMQoAAABzowG6c0cULB8igkwPchCd Original-NNTP-Posting-Host: 108.82.92.30 User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 5.1; rv:12.0) Gecko/20100101 Firefox/12.0,gzip(gfe) Injection-Date: Tue, 23 Oct 2012 01:16:58 +0000 Original-Xref: usenet.stanford.edu gnu.emacs.help:195043 comp.emacs:102645 comp.lang.lisp:311478 comp.lang.scheme:89158 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:87372 Archived-At: On Oct 21, 1:22=A0pm, "Pascal J. Bourguignon" wrote: > Swami Tota Ram Shankar writes: > > > On Oct 21, 4:16=A0am, "Pascal J. Bourguignon" > > wrote: > >> Since the syntax of this text is exactly the printed representation of > >> an emacs lisp vector, you can read it directly with read. > > >> (defun get-vectors-from-buffer () > >> =A0 =A0(let ((vectors '())) > >> =A0 =A0 =A0(goto-char (point-min)) > >> =A0 =A0 =A0(while (re-search-forward "\\[[0-9.+-\\ ]+\\]" nil t) > >> =A0 =A0 =A0 =A0 (goto-char (match-beginning 0)) > >> =A0 =A0 =A0 =A0 (push (read (current-buffer)) vectors)) > >> =A0 =A0 =A0(nreverse vectors))) > > >> ;; [1 2 3.0] [4 5 6] > >> ;; [7 +8 -9] > > >> (get-vectors-from-buffer) > >> --> ([[0-9\.+-\\] +] > >> =A0 =A0 =A0[[0-9\.+-\\] +\\] > >> =A0 =A0 =A0[17.16 -17.16 17.16 17.16 17.16 17.16 17.16 17.16] > >> =A0 =A0 =A0[[0-9\.+-\\] +\\] > >> =A0 =A0 =A0[1 2 3.0] > >> =A0 =A0 =A0[4 5 6] > >> =A0 =A0 =A0[7 8 -9]) > > > Hi Pascal, Thanks for the reply but there are some problems. I > > understood your change to regexp. > > > However, you are doing too much in your and I need only read one > > string at a specific location at a time, not the whole buffer. > > > Thus, I am having difficulty and need help. Let me write the modified > > story again. > > > (when (looking-at "\\[[0-9.+-\\ ]+\\]") > > (forward-char (+ (string-width (match-string 0)) 1)) > > (setq V (match-string 0)) > > (setq V (read-from-string (intern (match-string 0)))) > > 0- What's the purpose of moving the point? > 1- Don't use setq, use let. > 2- Don't bind two different things to the same variable! > 3- read-from-string reads from a string, not a symbol, so why are you > =A0 =A0interning a symbol? > > Let me advise you to read: > > =A0 =A0 =A0 =A0 =A0 An Introduction to Programming in Emacs Lisp > =A0 =A0 =A0 =A0 =A0http://www.gnu.org/software/emacs/emacs-lisp-intro/=A0= or =A0M-: (info "(eintr)Top") RET > > =A0 =A0(defun get-vector-at-point () > =A0 =A0 =A0(when (looking-at "\\[[0-9.+-\\ ]+\\]") > =A0 =A0 =A0 =A0(goto-char (match-beginning 0)) > =A0 =A0 =A0 =A0(read (current-buffer)))) > Hi Pascal, I like your advice above a lot, especially concerning setq versus let. I will later ask you to elaborate more on your point (2), however, for now I want to focus solely on point (1). I had to write a wrapper function to one I was writing and I soon ran into a name space conflict because of setq. Temporarily I relieved, due to the urgency to complete the task, by renaming the variables. However, I want an expert such as you to address some style issues in lisp programming. For this reason, I am renaming my post as Style Issues in Lisp and Scheme programming, setq versus let Here are my questions. Does setq cause some kind of permanent persistence of the variable like a global? In the lingo of computer science, such as lexical scoping, dynamic scoping, static binding, dynamic binding, what is its meaning and what is the meaning of these four terms? Even more important question is the impact on program structure and readability. For example, the imperative programming style, flows nicely from top to bottom. The eye has to move L->R and top to bottom to understand the screenful module, as in C. I have found that let, and functional style leads to an onion type structure. f(g(h(x,y),z,k(alpha,beta,l(theta)))w) If it is short, its not an issue, but the multiple cores or eyes of the onion, makes it impossible to grasp the structure. I ask you to focus your brain intensely and come up with some COMPELLING rules of thumb, so I can write programs that are readable. I know, some of you are such brilliant minds that there will not emerge one in maybe 100 years as smart as you, so write these rules for newbies. and sprinkle some examples. I want to apply to my own thing, but you also tell us how to read these programs since when I look at yours, it becomes digestable only after persisting with it and going to the cores and reading inward out. Whats your method or habit of reading? Swami