One optimiziation more:
thank to newLisp and its flexibility, we can do this simple operation. Let's take this original code:
Code: Select all
(define (do-sum val1 val2)
(println (string "Somma valori: " (+ val1 val2)))
(+ val1 val2)
);define
(println (string "10+20=" (do-sum 10 20)))
In order to modify it to avoid context problems we can simply do this:
1) add the new function:
Code: Select all
(define (do-sum val1 val2)(_do-sum val1 val2))
2) modify the original function by adding an "_" in front of the function name. It will become:
Code: Select all
(define (_do-sum val1 val2)
(println (string "Somma valori: " (+ val1 val2)))
(+ val1 val2)
);define
Then the new full code will be:
Code: Select all
(define (_do-sum val1 val2)
(println (string "Somma valori: " (+ val1 val2)))
(+ val1 val2)
);define
(define (do-sum val1 val2)(_do-sum val1 val2))
(println (string "10+20=" (do-sum 10 20)))
Very easy.
Maybe some of you made a question: why should I have to assign a context to a variable (like an alias)? Well, there are at least two good reasons:
1) I can use a single alias to refer to different contexts (if we talk about OOP programming, we could think to "polymorphisms")
2) When I create big programs, I could find more contexts with the same name. So it means I could have some naming conflicts. In order to avoid it, I could call the contexts with a domain-specific name. For example (talking about a theorical context module to perform database access).
Basically I have "odbc.lsp" -> ODBC context.
But what happen if I will find another useful module to access to ODBC too? So I could rename original context (ODBC) as: ale870.database.odbc
(ale870 is obviously my name!).
The other module could be called:
mister.database.odbc
Well, in order to avoid to type these long context names, I need to create an alias. So:
Code: Select all
(ale870.database.odbc:connect ... )
(ale870.database.odbc:query ... )
or is better...
Code: Select all
(setq ctxODBC ale870.database.odbc)
(ctxODBC:connect ... )
(ctxODBC:query ... )
;-)