Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
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
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  12 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Swami Tota Ram Shankar  
View profile  
 More options Oct 22 2012, 9:17 pm
Newsgroups: gnu.emacs.help, comp.emacs, comp.lang.lisp, comp.lang.scheme
From: Swami Tota Ram Shankar <tota_...@india.com>
Date: Mon, 22 Oct 2012 18:16:58 -0700 (PDT)
Local: Mon, Oct 22 2012 9:16 pm
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
On Oct 21, 1:22 pm, "Pascal J. Bourguignon" <p...@informatimago.com>
wrote:

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Swami Tota Ram Shankar  
View profile  
 More options Oct 22 2012, 11:02 pm
Newsgroups: gnu.emacs.help, comp.emacs, comp.lang.lisp, comp.lang.scheme
From: Swami Tota Ram Shankar <tota_...@india.com>
Date: Mon, 22 Oct 2012 20:02:00 -0700 (PDT)
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 22, 7:36 pm, PJ Weisberg <p...@irregularexpressions.net> wrote:

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.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pascal J. Bourguignon  
View profile  
 More options Oct 23 2012, 4:15 am
Newsgroups: gnu.emacs.help, comp.emacs, comp.lang.lisp, comp.lang.scheme
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?

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stefan Monnier  
View profile  
 More options Oct 24 2012, 11:03 am
Newsgroups: gnu.emacs.help, comp.emacs, comp.lang.lisp, comp.lang.scheme
From: Stefan Monnier <monn...@iro.umontreal.ca>
Date: Wed, 24 Oct 2012 11:03:28 -0400
Local: Wed, Oct 24 2012 11:03 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

> 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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Cowan  
View profile  
 More options Oct 24 2012, 11:47 am
Newsgroups: comp.lang.scheme
From: John Cowan <johnwco...@gmail.com>
Date: Wed, 24 Oct 2012 08:47:31 -0700 (PDT)
Local: Wed, Oct 24 2012 11:47 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

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.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
damosan  
View profile  
 More options Oct 24 2012, 1:56 pm
Newsgroups: comp.lang.scheme
From: damosan <damo...@gmail.com>
Date: Wed, 24 Oct 2012 10:56:19 -0700 (PDT)
Local: Wed, Oct 24 2012 1: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

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.

D.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Christian Kellermann  
View profile  
 More options Oct 24 2012, 1:59 pm
Newsgroups: comp.lang.scheme
From: Christian Kellermann <ck...@pestilenz.org>
Date: Wed, 24 Oct 2012 19:59:55 +0200
Local: Wed, Oct 24 2012 1:59 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

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

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Cowan  
View profile  
 More options Oct 24 2012, 5:01 pm
Newsgroups: comp.lang.scheme
From: John Cowan <johnwco...@gmail.com>
Date: Wed, 24 Oct 2012 14:01:30 -0700 (PDT)
Local: Wed, Oct 24 2012 5:01 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

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.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
gnuist...@hotmail.com  
View profile  
 More options Oct 24 2012, 11:20 pm
Newsgroups: gnu.emacs.help, comp.emacs, comp.lang.lisp, comp.lang.scheme
From: gnuist...@hotmail.com
Date: Wed, 24 Oct 2012 20:20:32 -0700 (PDT)
Local: Wed, Oct 24 2012 11:20 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
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.

(+ 2 3 4) ;; executable
(((+ 2) 3) 4)  ;; not executable
(cons '+ (cons 2 (cons 3 (cons 4 nil))))  ;; ditto
(eval  '(+ (cons 2 (cons 3 (cons 4 nil)))))  ;; ditto

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.

G


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pascal J. Bourguignon  
View profile  
 More options Nov 2 2012, 5:32 pm
Newsgroups: comp.lang.scheme
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__

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pascal J. Bourguignon  
View profile  
 More options Nov 21 2012, 4:56 pm
Newsgroups: gnu.emacs.help, comp.emacs, comp.lang.lisp, comp.lang.scheme
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

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.

Otherwise the following should work, in emacs-24:

;; in emacs-24:
(setq lexical-binding t)
(defun plus/2 (arg) (lambda (x) (+ arg x)))
(defun plus/3 (arg) (lambda (y) (plus/2 (funcall (plus/2 arg) y))))

(funcall (plus/2  2) 3)                --> 5
(funcall (plus/3  2) 3)                --> #<some closure>
(funcall (funcall (plus/3  2) 3) 4)    --> 9

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
WJ  
View profile  
 More options Nov 22 2012, 9:41 pm
Newsgroups: comp.lang.lisp, comp.lang.scheme
From: "WJ" <w_a_x_...@yahoo.com>
Date: 23 Nov 2012 02:40:51 GMT
Local: Thurs, Nov 22 2012 9:40 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

Racket:

(dict-map '((a . 3) (b . 2) (c . 1)) list)
--> '((a 3) (b 2) (c 1))

Clojure:

Right to left:

user=> (Math/exp (Math/sqrt (Math/abs -8)))
16.9188286785579

Left to right:

user=> (-> -8 Math/abs Math/sqrt Math/exp)
16.9188286785579


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »