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
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
> 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.
> 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?
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.
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
> On Mon, Oct 22, 2012 at 6:16 PM, Swami Tota Ram Shankar
> <tota_...@india.com> wrote:
> > 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)
> That could be valid C code, but it's probably not Lisp code, unless
> you really do have a function named "x,y".
> > If it is short, its not an issue, but the multiple cores or eyes of
> > the onion, makes it impossible to grasp the structure.
> Just one small tip: when reading lisp code, pay more attention to the
> indentation then to the parentheses. Of course the
> compiler/interpreter doesn't pay attention to the indentation, but the
> author probably did.
Can you suggest some skeleton
(defun function (var1 var2 var3)
""
(interactive "swith strings and \ns to allow suggested defaults and
avoid typing and simply RTN")
taking care of defaults if null or ""
(let* (()()())
)
)
btw, lisp's prefix notation, (f x y z) is more expressive and
convenient for expressing currying (((f x) y) z) than f(x y z).
I expect incisive and penetrating analysis of code organization and
using that to improve readability.
From: "Pascal J. Bourguignon" <p...@informatimago.com>
Date: Tue, 23 Oct 2012 10:15:07 +0200
Local: Tues, Oct 23 2012 4:15 am
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
Swami Tota Ram Shankar <tota_...@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?
> 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.
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
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
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
On Wednesday, October 24, 2012 11:47:32 AM UTC-4, John Cowan wrote:
> One of the things Kernel got right is that by convention you > write $if, $when, $lambda, etc.
To me syntatic sugar like this is a crutch. If you know the language having to type extra '$' is a pain in the butt.
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
damosan <damo...@gmail.com> writes:
> On Wednesday, October 24, 2012 11:47:32 AM UTC-4, John Cowan wrote:
>> One of the things Kernel got right is that by convention you >> write $if, $when, $lambda, etc.
> To me syntatic sugar like this is a crutch. If you know the language
> having to type extra '$' is a pain in the butt.
By convention means noone forces you to do this. You don't have to mark
globals with '*' on both sides either, yet it has been shown to be
benefitial for those who read the code...
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
On Wednesday, October 24, 2012 1:56:19 PM UTC-4, damosan wrote:
> To me syntactic sugar like this is a crutch. If you know the
> language having to type extra '$' is a pain in the butt.
That's fine in languages with fixed syntax, but you can always add new syntax to Scheme. I doubt if anyone has memorized all the syntax keywords available in Racket, for example, though there are some conventional naming patterns: "define-foo" is usually syntax, for example.
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
On Oct 24, 8:03 am, Stefan Monnier <monn...@iro.umontreal.ca> wrote:
> > btw, Lisp's prefix notation, (f x y z) is more expressive and
> > convenient for expressing currying (((f x) y) z) than f(x y z).
> With all due respect to Lisp, that's not true. Curried calls in the
> non-Lisp syntax are simply "f(x)(y)(z)" or even better "f x y z".
> Stefan
As an aside you show the notation. well and good. But I realize that
there is no executable substitute or ability to return a curried
function
in emacs. Consider these forms.
From: Pascal J. Bourguignon <p...@informatimago.com>
Date: 2 Nov 2012 21:32:56 GMT
Local: Fri, Nov 2 2012 5:32 pm
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
John Cowan <johnwco...@gmail.com> wrote:
> On Tuesday, October 23, 2012 4:15:11 AM UTC-4, Pascal J. Bourguignon wrote:
>> So when you read "when", you should know that it's a macro
> But, alas, there's no way to do that without searching the manual plus
> all your source code.
> One of the things Kernel got right is that by convention you write $if,
> $when, $lambda, etc.
But actually, it is easy to remember the small list of "fundamental" macros
and special operators, and to follow a few other conventions: we don't
prefix macro names with $ but instead with def, do, or with-.
-- __Pascal J. Bourguignon__
From: "Pascal J. Bourguignon" <p...@informatimago.com>
Date: Wed, 21 Nov 2012 22:56:55 +0100
Local: Wed, Nov 21 2012 4:56 pm
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
gnuist...@hotmail.com writes:
> On Oct 24, 8:03 am, Stefan Monnier <monn...@iro.umontreal.ca> wrote:
>> > btw, Lisp's prefix notation, (f x y z) is more expressive and
>> > convenient for expressing currying (((f x) y) z) than f(x y z).
>> With all due respect to Lisp, that's not true. Curried calls in the
>> non-Lisp syntax are simply "f(x)(y)(z)" or even better "f x y z".
>> Stefan
> As an aside you show the notation. well and good. But I realize that
> there is no executable substitute or ability to return a curried
> function
> in emacs. Consider these forms.
> Can anyone suggest an executable version of first in terms of curried
> addition?
> Since Pascal is busy, and David Kastrup is not seen for quite some
> time, I hope someone can give a reply to the question of the thread.
Well, if you want to keep the variadicity of the operation, it's hardly
possible, because you can only return either a number or a function. In
lisp, numbers are not applicable functions.
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
Pascal J. Bourguignon wrote:
> Swami Tota Ram Shankar <tota_...@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?
> > 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.