lexical declare function

For the Compleat Fan
Locked
ssqq
Posts: 88
Joined: Sun May 04, 2014 12:49 pm

lexical declare function

Post by ssqq »

In newLISP, lexical symbol is declare with *let*, *letn*, *letex* and *args expression*.

If it is possible that add *Perl-lish* style lexical declare function like *my*(expr scope) in newLISP?

Code: Select all

(define (sub-name arg) 
    (expression-list)
    (my lexical-symbol 1)
    (+ 1 lexical-symbol))

(= lexical-symbol nil) 
Although this style declaration could implement with *let*, but when transfer perl (or other language) code to newlisp line by line, too much nest *let expression* would be write that would greatly reduce readable of code.

If add this style declaration syntax, newLISP code would less more parenthesis.

rickyboy
Posts: 607
Joined: Fri Apr 08, 2005 7:13 pm
Location: Front Royal, Virginia

Re: lexical declare function

Post by rickyboy »

ssqq wrote:In newLISP, lexical symbol is declare with *let*, *letn*, *letex* and *args expression*.
No. You are misusing the term "lexical". In Perl parlance, it means "static(ally) scope(d)." This also means "lexically scoped." Now, the problem is that you are comparing apples to oranges, as newLISP "variables" are all dynamically scoped.
ssqq wrote:If it is possible that add *Perl-lish* style lexical declare function like *my*(expr scope) in newLISP?
No, not short of re-writing variable scoping rules in newLISP or writing your own interpreter in newLISP. Why? Because to implement lexical scoping, you have to have the evaluator carry around (keep track of) the current lexical environment (which also means that you have to implement closures). Thus, a mere set of macros is not going to accomplish it.
ssqq wrote:Although this style declaration could implement with *let*, but when transfer perl (or other language) code to newlisp line by line, too much nest *let expression* would be write that would greatly reduce readable of code.
That's only your opinion. I'm of the opposite opinion: that newLISP code in general is MUCH easier to read than Perl code.

However, I believe that, beyond even variable scoping rules, the bottom line is that Perl and newLISP (or, Perl and ANY Lisp, for that matter) are so far away from each other, with regard to many concepts of programming languages, that it is unreasonable to hold that either should be made to easily "transfer ... code ... line by line" from one to the other. Again, apples and oranges. My two cents.
(λx. x x) (λx. x x)

ssqq
Posts: 88
Joined: Sun May 04, 2014 12:49 pm

Re: lexical declare function

Post by ssqq »

yes, Perl have too much difference from newLISP.

All of us want write stable, clear, easy to maintain code, also want use for reference from other language have learned.

Locked