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

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

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


From: Pascal J. Bourguignon
Subject: Re: 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: Tue, 23 Oct 2012 10:15:07 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux)

Swami Tota Ram Shankar <address@hidden> writes:

> 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?

See http://www.informatimago.com/articles/usenet.html#Variables

> 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.

No, the issue is when it's short, with short, unmeaningful names.

If you use whole words and whole propositions as identifiers, then it
can read as English.

  (mapcar (function list) (get-keys alist)  (get-values alist))

vs.

  (m (f l) (k a) (v a))



> 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.

Sorry, I don't have the time right now.


> 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.

The functions I presented you in this thread were procedural.  You may
be confused because in lisp, scope is limited to parentheses too.

  (when cond
     expr1
     expr2)

is different from:

  (mapcar fun
      expr1
      expr2)

You have to read the operator first.  That's why it's in the first
position in the lists: it's the most important thing you have to read to
understand lisp code.  And that's why lisp operators are rarely cryptic
characters or single-letter. (The exceptions being +, -, *, etc, but
originally it was PLUS, MINUS, MULTIPLY, etc).

So when you read "when", you should know that it's a macro and that it
has some specific rules of evaluation of its arguments.  You should then
read those arguments following those rules of evaluations.  Namely, when
evaluates its first argument, and if it returns true, then it evaluates
in sequence the other arguments.  This is not functional, this is
procedural!

On the other hand, when you read "mapcar", you should know that it's not
a macro or a special operator, so it's a function, and therefore all its
arguments are evaluated in order, and passed to the function that's
called last.  Here you have an "onion", since you have to read inside
out to follow the flow of control.

But with macros and special operators, the flow of control can be
anything the macro is designed to implement.  So you have to know  your
macros and special operators.



> Whats your method or habit of reading?

Read the reference.

Common Lisp:
    http://www.lispworks.com/documentation/HyperSpec/Front/index.htm


emacs lisp:
    An Introduction to Programming in Emacs Lisp
    http://www.gnu.org/software/emacs/emacs-lisp-intro/  or  M-: (info 
"(eintr)Top") RET

    Emacs Lisp Manual
    http://www.gnu.org/software/emacs/manual/elisp.html  or  M-: (info 
"(elisp)Top") RET


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.


reply via email to

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