all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Pascal J. Bourguignon" <pjb@informatimago.com>
To: help-gnu-emacs@gnu.org
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	[thread overview]
Message-ID: <87r4op4nas.fsf@kuiper.lan.informatimago.com> (raw)
In-Reply-To: 657d823b-990f-4a2b-a57c-2c644099ddcd@z2g2000yqj.googlegroups.com

Swami Tota Ram Shankar <tota_ram@india.com> 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 {}.


  parent reply	other threads:[~2012-10-23  8:15 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-21 10:37 string to list or string to array Swami Tota Ram Shankar
2012-10-21 11:16 ` Pascal J. Bourguignon
2012-10-21 19:03   ` Swami Tota Ram Shankar
2012-10-21 20:22     ` Pascal J. Bourguignon
2012-10-23  1:16       ` Style Issues in Lisp and Scheme programming, setq versus let ... and onion structure with multiple cores or eyes or kernels " Swami Tota Ram Shankar
2012-10-23  2:36         ` PJ Weisberg
     [not found]         ` <mailman.11503.1350959781.855.help-gnu-emacs@gnu.org>
2012-10-23  3:02           ` Swami Tota Ram Shankar
2012-10-24 15:03             ` Stefan Monnier
2012-10-25  3:20               ` gnuist007
2012-10-25  8:25                 ` José A. Romero L.
2012-11-21 21:56                 ` Pascal J. Bourguignon
2012-10-23  8:15         ` Pascal J. Bourguignon [this message]
2012-10-24  8:05         ` Thien-Thi Nguyen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r4op4nas.fsf@kuiper.lan.informatimago.com \
    --to=pjb@informatimago.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.