let

Q&A's, tips, howto's
Locked
eddier
Posts: 289
Joined: Mon Oct 07, 2002 2:48 pm
Location: Blue Mountain College, MS US

let

Post by eddier »

I wonder about replacing the current (let function syntax

Code: Select all

(let ((variable1 expression1) (variable2 expression2) ... (variable n expression n))
  body)
with

Code: Select all

(let variable1 expression1 variable2 expression2 ... variable n expression n
  body)
as with the (if function.

Eddie

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

how would you distingush from the body expressions (could be various)? or do you mean:

Code: Select all

(let (var1 ex1 var2 ex2 ..) 
    (body-exp1) (body-exp2) ...)
The pretty printer then would do a line break and indent after the local list:

Hans-Peter, what is AutoLisp doing?

Also while at saving ((())), what about 'dolist' and 'dotimes'

Code: Select all

(dolist x lst
   (body-exp1)
   (body-exp2) ...)
What will all the users say? (it would be fine with me)


Lutz

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

Hm, Autolisp does not have a let.

But my vote would for the current syntax or Lutz's version. It keeps the structure in larger sources. A good editor can jump to the closing paranthesis.
Hans-Peter

eddier
Posts: 289
Joined: Mon Oct 07, 2002 2:48 pm
Location: Blue Mountain College, MS US

Post by eddier »

Yes, I meant

Code: Select all

(let (var1 ex1 var2 ex2 ..)
    (body-exp1) (body-exp2) ...) 
I guess less or more parenthesis are a matter of personal taste no offense HPW. I was looking at consistency.

For example:

Code: Select all

(setq var1 exp1 var2 exp 2 ... var n exp n)
and then there is

Code: Select all

(let ((var1 exp1) (var2 exp 2) ... (var n exp n))
 ...)
Eddie

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

>Therefor my vote would for the current syntax or Lutz's version.

So no problem! :-)

It is Lutz's version.
Hans-Peter

eddier
Posts: 289
Joined: Mon Oct 07, 2002 2:48 pm
Location: Blue Mountain College, MS US

Post by eddier »

Agreed! It is definately Lutz's version! :-)

BTW the new nth, set-nth, push, and pop functions are really proving themselves useful. I have reduced a lot of complex code in my survey tabulating routines with these functions. Now the routines are much more amendable to corrections and added future functionality.

Thanks Lutz!

Eddie

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

I am glad the new multi dimensional functions prove to be useful, I think they bring a whole new dimension (pun intended) of power to newLISP.

I just finished a small modification to 'let', which lets you use both syntaxes: the classic one and the one suggested by Eddie:

(let (var1 ex1 var2 ex2 ..)
(body-exp1) (body-exp2) ...)

'dolist' and 'dotimes' will stay how they are, they are really similar to the new form of 'let' : (keyword (parameters) body) and like in 'let' their parameter symbols are local. So suddenly everything makes sense.

This will be in 7.3.8 (weekend development release). In that version you can also use both 'fn' and 'lambda', which makes for shorter anonymous functions i.e:

(map (fn (x) (< x 100)) a-list) ; filters values < 100 from a-list
(map (lambda (x) (< x 100) a-list) ; same thing, classic syntax

work both the same, but the first one is a lot more readable and 'fn' is a commonly used abbreviation for anonymous function. I got this idea from Paul Graham on his Arc language project.

Lutz

eddier
Posts: 289
Joined: Mon Oct 07, 2002 2:48 pm
Location: Blue Mountain College, MS US

Post by eddier »

Your work is much appreciated!

Eddie

Locked