help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Style Issues in Lisp and Scheme programming, setq versus let ... and on


From: Swami Tota Ram Shankar
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)
User-agent: G2/1.0

On Oct 21, 1:22 pm, "Pascal J. Bourguignon" <p...@informatimago.com>
wrote:
> Swami Tota Ram Shankar <tota_...@india.com> writes:
>
> > On Oct 21, 4:16 am, "Pascal J. Bourguignon" <p...@informatimago.com>
> > 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 ()
> >>    (let ((vectors '()))
> >>      (goto-char (point-min))
> >>      (while (re-search-forward "\\[[0-9.+-\\ ]+\\]" nil t)
> >>         (goto-char (match-beginning 0))
> >>         (push (read (current-buffer)) vectors))
> >>      (nreverse vectors)))
>
> >> ;; [1 2 3.0] [4 5 6]
> >> ;; [7 +8 -9]
>
> >> (get-vectors-from-buffer)
> >> --> ([[0-9\.+-\\] +]
> >>      [[0-9\.+-\\] +\\]
> >>      [17.16 -17.16 17.16 17.16 17.16 17.16 17.16 17.16]
> >>      [[0-9\.+-\\] +\\]
> >>      [1 2 3.0]
> >>      [4 5 6]
> >>      [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
>    interning a symbol?
>
> Let me advise you to read:
>
>           An Introduction to Programming in Emacs Lisp
>          http://www.gnu.org/software/emacs/emacs-lisp-intro/ or  M-: (info 
> "(eintr)Top") RET
>
>    (defun get-vector-at-point ()
>      (when (looking-at "\\[[0-9.+-\\ ]+\\]")
>        (goto-char (match-beginning 0))
>        (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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]