lexical declare function

Started by ssqq, January 06, 2015, 12:14:25 AM

Previous topic - Next topic

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?


(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

#1
Quote from: "ssqq"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.


Quote from: "ssqq"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.


Quote from: "ssqq"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

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