Is this feature caused by CPLua or Lua itself? I cannot find the answer in the manual... If it's caused by CPLua, it will be nice to remove such a restriction in variable scope.You are right, any function is supposed to become global when it is loaded. It's a bit primitive, but I don't think this is a real problem for now
Project: Cplua
#81
Posted 10 September 2005 - 01:02 PM
#82
Posted 10 September 2005 - 01:20 PM
If it is really annoying i could create a freefunc() function
#83
Posted 10 September 2005 - 01:42 PM
This is absolutely normal, and it is exactly what I want. But there is a side-effect: if one of these functions (local to the chunk or not) is calling anoher chunk, then the functions in this second chunk should be global and accessible from everywhere. This breaks the "data hashing" aspect.Well if you load an external chunk with functions that are declared local inside of it, those functions are local to that chunk and it is normal that you cannot use it from outside...
Maybe you can easily add a function loader that loads a function which is by default local to the calling chunk, and not visible from any other chunk. Thus, a chunk who needs a "utility" function, will load it, but every other chunk will not have access to that function. That's what "data hashing" means: every part of the code knows only what it needs and nothing else. If you can add such a feature, I will really appreciate it...
#84
Posted 10 September 2005 - 02:30 PM
choose the category ., then write the script ,function , command ,.. then save it !
I have provided some Image , please explain how I can add them to my post !!
#85
Posted 10 September 2005 - 03:22 PM
My Romberg integration sub-project has been finished. I needed more time than I was expected, due to the poor matrix support, but it's finally done. The code is fully modularized, and flexible enough: you can optionally set the desired accuracy (either absolute or fractional), and the order of the method (that is, the method does not necessarily use the trapezoidal rule to do an iteration step) . I have tried several integrals, and it works quite well. For example, the integral x sin(1/x) sqrt(abs(1-x)) from x=1e-6 to x=3 is very difficult (see my post about this in the "Difficult CAS problems in ClassPad" topic). Asking for a result accurate to 4 decimal digits, my Lua program returns 1.9819260333, which is indeed accurate to the desired accuracy. The computation time is about one minute, which is not bad at all, considering that it is a difficult integral, and the code is running on an interpreter. This integral needs 15 subdivisions to achieve an accuracy of 4 decimal digits, which means that here N=2^15. As you can see, a fixed N=32 is not a good choice...I completed Romberg Integration
one Example :
How about your algorithm ?
please give an Example with the time it takes to test it.thanks.
Btw, ClassPad's built-in numerical integration is powerful, but is actually slower than my Lua program.
#86
Posted 10 September 2005 - 03:40 PM
My Romberg integration sub-project has been finished. I needed more time than I was expected, due to the poor matrix support, but it's finally done. The code is fully modularized, and flexible enough: you can optionally set the desired accuracy (either absolute or fractional), and the order of the method (that is, the method does not necessarily use the trapezoidal rule to do an iteration step) . I have tried several integrals, and it works quite well. For example, the integral x sin(1/x) sqrt(abs(1-x)) from x=1e-6 to x=3 is very difficult (see my post about this in the "Difficult CAS problems in ClassPad" topic). Asking for a result accurate to 4 decimal digits, my Lua program returns 1.9819260333, which is indeed accurate to the desired accuracy. The computation time is about one minute, which is not bad at all, considering that it is a difficult integral, and the code is running on an interpreter. This integral needs 15 subdivisions to achieve an accuracy of 4 decimal digits, which means that here N=2^15. As you can see, a fixed N=32 is not a good choice...
Btw, ClassPad's built-in numerical integration is powerful, but is actually slower than my Lua program.
very nice ,
can I have your code ?
I have a suggestion :
you can write your programs (Numerical methods) (differentiation , Integration , Differential Eguations)
then put it in the lua library as insertable scripts to lua , like the cat tab in standard keyboard ( for functions just the function names and for scripts the whole)
I think if we have (add , edit , insert) options in the Lua keyboard cat tab then we can have a powerfull library which is able to support insertable scripts , functions ,...
what,s your Idea?
I have some Images for this , how I can add them to my post ?
#87
Posted 10 September 2005 - 04:34 PM
Having it done automatically is nice because if you add new scripts then the commands just automatically appear.
#88
Posted 10 September 2005 - 04:43 PM
I agree that a "Lua catalog" with all existing (and/or loaded) functions or scripts would be great. We could try to make it (I said 'we' because someone other than me could work on it since it's not really specific to the Lua Language)...
unique33, to share your images you have to load them on a server (you could use your website's server for example, the use the 'img' tags to display it here
#89
Posted 10 September 2005 - 07:21 PM
,...
we can have a Lua catalog, something like this , which is : editable , addable , Inserting support ,....
#90
Posted 10 September 2005 - 10:38 PM
Of course you can. I love Open Source, and I'm happy that someone is interested . I don't know if I can export a folder containing "MEM" variables to my computer. I'll try, and, if succeded, I'll upload the image to the "File Sharing" session. The code is rather long to rewrite it here.very nice ,
can I have your code ?
A Lua library was exactly what I had in mind from the beginning. Adding Lua functions to the "cat" tab is useful, but not very. You can simply load library functions by using loadfunc in your program (my "Brent" and "Romberg" projects do that). The implementation of a "robust" Lua function library, however, has a small problem: As I said in a previous post, a library function should be able to load other library functions (I already needed that in the "Romberg" project). Currently you can do that, but a loadable library function may load other functions only if they are global. This is a problem, since the code is not as clear as possible, and it is known as a common source of errors, because the "data hashing" is broken. Orwell said that he can add another function loader, similar to loadfunc, that will make the functions to be load local to the calling Lua chunk. If so, the problem will be fixed, and, indeed, we can create a Lua library of numerical methods in a very neat and modular way. Your "imaginary" loader can be a very good solution, provided that the user will have the option to choose if the library function will be local to the calling Lua chunk or not. For example, the "Open" window may have 2 radio boxes: "Local" and "Global".I have a suggestion :
you can write your programs (Numerical methods) (differentiation , Integration , Differential Eguations)
then put it in the lua library as insertable scripts to lua , like the cat tab in standard keyboard ( for functions just the function names and for scripts the whole)
I think if we have (add , edit , insert) options in the Lua keyboard cat tab then we can have a powerfull library which is able to support insertable scripts , functions ,...
what,s your Idea?
#91
Posted 10 September 2005 - 10:51 PM
That's right, but don't you think it's a bit exagerated though?a loadable library function may load other functions only if they are global. This is a problem, since the code is not as clear as possible, and it is known as a common source of errors, because the "data hashing" is broken
If we are working on a script "s1", and we load a global function "f1", and this function needs to load another global function "f2", then okay, you will be able to call "f2" from "s1" without asking it explicitely. But you are not aware of that! since you are not supposed to know what "f1" exactly does, how could you know that there is now the "f2" functions that has became callable too?
And even if you saw it with a catalog or something else, should it be a real problem? Lua loads many basis functions that you don't need, and you didn't say (yet) that it bothered you...
#92
Posted 11 September 2005 - 12:04 AM
No, I'm not exagerating at all. No offense, but why all C++ programmers I have ever met think like that?That's right, but don't you think it's a bit exagerated though?
If we are working on a script "s1", and we load a global function "f1", and this function needs to load another global function "f2", then okay, you will be able to call "f2" from "s1" without asking it explicitely. But you are not aware of that! since you are not supposed to know what "f1" exactly does, how could you know that there is now the "f2" functions that has became callable too?
And even if you saw it with a catalog or something else, should it be a real problem? Lua loads many basis functions that you don't need, and you didn't say (yet) that it bothered you...
Data hashing is not a new idea nor something exotic. It is extensively used in languages that require structural programming. Even in Fortran 77 (released 27 years ago) there was some mechanism to do that. In Fortran 95 data hashing is strongly suggested, and in F is imperative. I'm not sure about C++ (but I don't think that C++ is a language that enforces structural programming anyway). Suffice to say that languages such as Matlab, Scilab and Octave are considered as ideal for easy, but not structural programming, just because the data hashing can be easily broken. This is known as a common "bag of potential bugs". I don't want such a bag in CPLua.
Now, let's look at your example: I may don't know that f2 has become callable via s1, but I know that f2 is a library function. Suppose that I need to call it in the future, for example during an upgrade of the code. Since I'm not aware that it is already loaded from f1, I'll add a loadfunc("LuaUtils/f2") in the Lua chunk that needs that function. In other words, I will try to load a global function which is already loaded! If the interpreter is smart enough, it will report that the f2 is already loaded, so I will start to search from which Lua chunk f2 has been loaded as global. If the interpreter is stupid, it will let me to reload the function f2. You like that? Is it structural programming? My answer is no, definitely no. It reminds me Window$, where everything is loaded into your computer during installation without asking . You said that Lua loads many basis functions that I don't need, and I'm not complaining. Every language has a vocabulary, and the user knows that built-in functions are already there. But these are built-in functions, not user functions. How can I know which functions of a library are loaded and where, without using module-oriented programming with data hashing?
It is very common to load functions (especially "library" functions) from a loadable function. I needed such a thing in my second project in Lua, not after years of programming in Lua. The Lua library of numerical methods, proposed by unique33, will definitely need it. I personally refuse to start such a big project with global functions loaded by a loadable function.
Now, a last try to convince you: Suppose that I am the only CPLua user in the planet that wishes to use data hashing. Is it difficult to implement a function loader that will imperatively load a function as local to the calling chunk? Suppose that I'm the only one that finds it useful. Could you please implement it in Lua, since you said you can do that?
#93
Posted 11 September 2005 - 01:14 AM
when user insert functions , just the name will be inserted
but when he Insert the script ( by script I mean the function code )
the whole script will be inserted within the current editing program.
but what is my reason :
suppose that we have a Library function
as you know the library functions are shared between all programs ,
If the user change it for a specific program then all other programs which are using this library function will be affected ,
and I think it is not good
when the function code can be insertable within the program , the user can change it for his specific purposes ,
in this case there will be no change in the library functions .
----------------------------------------------------------------------
A suggestion : ( help button on functions )
adding a help button in the catalog will be so usefull ( like the help - add in)
on each function If the user press the help button , he will see the help about the function in a separated window
for example
help={func.functionname=" function help ",...}
in the help window :
print(help.func.functionname)
or something like this.
the help about the user functions can be added by themselves when they add the function to the library !
what is your Idea ?
-----------------------------------------------------------------------
as PAP mentioned if the user can have the choice of calling functions locally or globally is a good Idea ,
the user can call functions locally or globally by another loadfunction and also maybe by adding the Inserting mode to the catalog .
#94
Posted 11 September 2005 - 06:52 AM
for example :
functionname.cll (Cp Lua Library)
if we have a function f2( )
now the similar in the library have a name f2.cll( )
does it help ?
#95
Posted 11 September 2005 - 07:53 AM
... So why do you think I said that loadfunc and doscript are similar, but don't do exactly the same things? They both execute the chunk, but loadfunc does it only once, the first time you try to load the chunk! If you call it again for the same chunk, it will do nothing because there is nothing to do. I created this function exactly in this purpose, because I know quite well that this problem often happens.Suppose that I need to call it in the future, for example during an upgrade of the code. Since I'm not aware that it is already loaded from f1, I'll add a loadfunc("LuaUtils/f2") in the Lua chunk that needs that function. In other words, I will try to load a global function which is already loaded! If the interpreter is smart enough, it will report that the f2 is already loaded, so I will start to search from which Lua chunk f2 has been loaded as global. If the interpreter is stupid, it will let me to reload the function f2. You like that? Is it structural programming?
Plus, saying this: "so I will start to search from which Lua chunk f2 has been loaded as global" is nonsense! f2 has became global, so you certainly do not need to know from which chunk it was called: it is absolutely not dependent on it! For a global function, "where" means "everywhere"!! "How can I know which functions of a library are loaded and where?" You don't have to know that! If you need a function you use loadfunc for it, and it will do the necessary. (and there wouldn't be any problem even if you knew it though)
I don't think I am that stupid. I know how things are, I know many detestable habits that many programmers have, and I would like to avoid it as much as I can.
But now, I would like you to tell me why this "broken datahashing" (to take your own words) is a so serious problem in this case. Does it brings bugs? errors? headaches? and please don't answer me something like "it brokes the datahashing, so it's evil"; if you do that I won't even move a finger to change anything. Give me a concrete example of a problematic situation.
There is also a proverb in my native language: "What you don't know does not make you ill"... I other words, if the data hashing is effectively broken, you have no way of knowing it, and there are no consequences. Or at least I can't find any, even if you were aware of it, so please could you take an example.
It is, and perhaps more than you can think. That's why I would like to know if it's really needed.Is it difficult to implement a function loader that will imperatively load a function as local to the calling chunk?
I agreed with you concerning the global variables, I know it is a real source of bugs. But about functions, I really don't know
Edited by Orwell, 11 September 2005 - 08:34 AM.
#96
Posted 11 September 2005 - 09:26 AM
but I just discovered some other information, that you could find interesting: http://www.lua.org/pil/5.3.html
I suggest you to read the chapter 6 of this book, by the way.
#97
Posted 11 September 2005 - 02:27 PM
Good to know that loadfunc loads a Lua chunk only if it is necessary. But this is only to prevent reloading, the restriction in functions scope remains unaffected.... So why do you think I said that loadfunc and doscript are similar, but don't do exactly the same things? They both execute the chunk, but loadfunc does it only once, the first time you try to load the chunk! If you call it again for the same chunk, it will do nothing because there is nothing to do. I created this function exactly in this purpose, because I know quite well that this problem often happens.
Nonsense? I want to have complete control over my own programs, is that nonsense? If I suddently discover that the main program has access to a function that it is not loaded explicitly into it, what am I supposed to do? Must I say "nevermind, it is loaded by some other chunk, I don't know where, but who cares, it's a global function anyway"? No, definitely no. I should say "why this functions is global? it shouldn't. I should be accessible from the chunks that need it, not from everywhere."Plus, saying this: "so I will start to search from which Lua chunk f2 has been loaded as global" is nonsense! f2 has became global, so you certainly do not need to know from which chunk it was called: it is absolutely not dependent on it! For a global function, "where" means "everywhere"!! "How can I know which functions of a library are loaded and where?" You don't have to know that! If you need a function you use loadfunc for it, and it will do the necessary. (and there wouldn't be any problem even if you knew it though)
I feel a little bit offended by this statement, but I'll try to answer in a proper way. First, nobody said that you are stupid, or that you don't know "how things are". It's obvious that you are an experienced programmer, but that does not mean that you know everything. You know things that I don't, and the opposite is certainly true as well (data hashing seems to be an example). Second, data hashing is not a "habit". It's good programming style (read below to see why). If you don't think so, at least don't call it "detestable". I also don't like the programming style that many C++ programmers have, but I never called it "detestable".I don't think I am that stupid. I know how things are, I know many detestable habits that many programmers have, and I would like to avoid it as much as I can.
Yes, it is a potential source of bugs. You want a variable to be known at a chunk that does not need it? No, you certainly don't want such a thing. Then why you don't care if something similar happens with functions? If c1 loads c2, and c2 loads c3, then c3 should be global, due to the current restriction in CPLua. You say that this is not important? Then make all functions global, it's not important too.But now, I would like you to tell me why this "broken datahashing" (to take your own words) is a so serious problem in this case. Does it brings bugs? errors? headaches?
Maybe you are still suspicious, maybe you think that I insist on data hashing because I have (detestable) habits. Ok. Forget everything I said, and read what some authors of excellent books about programming say:
"The principle of data hiding, or, more generally, of only allowing access to a resticted set of the entities in a module is extremely important for secure programming."
(T. Ellis & I. Philips, Programming in F, Addison-Wesley 1998, page 221).
"The concept of data hiding extends not only to variables, but also to the names of procedures that manipulate the variables ... data hiding prevents unintended side effects from producing hard-to-find errors"
(W. Press, S. Teukolsky, W. Vetterling, B. Flannery, Numerical Recipes in Fortran 90 - The art of Scientific Computing, Cambridge University Press, 2002, vol 2, page 957)
This version of Numerical Recipes (the all-time best seller in numerical analysis) is for Fortran 90, but there is a similar book for C. I don't have it (and I don't need it), but I bet that you will see the same notes in that book. You can also download it from the Internet here. The book is full of remarks, concerning how important it is to prevent access to variables and functions that are not needed in the current chunk. I won't rewite all these remarks here.
Don't search for a book that says that data hashing (often called "data hiding", but the meaning is the same) is unecessary or it is just a habit (detestable or not). You won't find any book that says that.
Again, this statement is offensive, and I cannot understand why. Don't "move a finger", if you don't want to do so. Is it not necessary to use that statement as a threat, because it is not a threat. If you don't "move a finger", it will not be the end of the world. I don't like to be offensive, but I also don't like to be offended by anyone.and please don't answer me something like "it brokes the datahashing, so it's evil"; if you do that I won't even move a finger to change anything.
There is also a proverb in my native language: "I'm getting older and older, and I always learn things". A programmer has always things to learn, no matter how experienced he is. In our case, you don't use data hashing, but that does not mean that it is not useful.There is also a proverb in my native language: "What you don't know does not make you ill"... I other words, if the data hashing is effectively broken, you have no way of knowing it, and there are no consequences. Or at least I can't find any, even if you were aware of it, so please could you take an example.
You want a variable to be global only if it absolutely necessary, and you do well. Why you don't want such a thing for functions? As it is now, CPLua permits side-effects: A function may be accessible from a chunk implicitly (not explicitly, as it should). You really think that there is no problem?I agreed with you concerning the global variables, I know it is a real source of bugs. But about functions, I really don't know
#98
Posted 11 September 2005 - 03:03 PM
Anyways, I naturally admit that you are right about certain points; from what I said you must think that I even never thought about data hashing, about restricted access on internal data etc. Don't believe that, take a look on Battleship's source code and you will see that everything was made as rigorous as possible concerning the access to data's and functions - yes, it is possible to do that with C++.
But well, I was currently reading the chapter about environments from Roberto Ierusalimschy's "Programming in Lua" book, and there are really interesting things there. So don't worry, I will install restricted access to the global environment by external chunks. Please, don't try anything on your own about that in your Lua programs (like modifying the global environment's metatable etc), I will find a general, unavoidable (and invisible) way to make it.
I'm reacting like that because you seem to consider this "data hashing" rule as an absolute order, but you were unable to explain why it is important: your lone arguments were sentences like "every programmer should respect it", "it is important for secure programming", "data hiding prevents unintended side effects from producing hard-to-find errors" (which ones??) Blindy follow a rule that is repeated everywhere, without knowing exactly why this rule must be applicated, often brings to disasters. I asked you many times how the break of this rule could lead to bugs or errors in CPLua... I 'm still waiting for some concrete examples.
However I must admit that doscript and loadfunc have a very basic behaviour about it. In fact at this time I was thinking about really modest Lua projects, where those kind of "problems" were not supposed to appear. One day or another I would have had to change it anyways
But,
I still can't see any problem (still concerning CPLua, not concerning the general case)...As it is now, CPLua permits side-effects: A function may be accessible from a chunk implicitly (not explicitly, as it should). You really think that there is no problem?
No offense, and don't answer if you don't want to (or PM me): I'm curious to know how old you are, and what are your experience and job. Just wondering.
Edited by Orwell, 11 September 2005 - 05:55 PM.
#99
Posted 11 September 2005 - 07:06 PM
Numerical Recipes Routines and Examples in BASIC (First Edition)
Julien C. Sprott
University of Wisconsin, Madison
Is there any shared one on the web ?
I do not like the google print version ,it is really slow !
#100
Posted 11 September 2005 - 08:11 PM
I must say that what offended me the most was the sentence "I won't even move a finger to change anything". But ok, it's finished.Okay, okay. I'd like to say that I was not even thinking about you when I wrote "detestable habits" (I was thinking about programs using goto's etc), believe we if you want, sorry if you feeled offended.
I' m not thinking that you know nothing aboud data hiding. As I said before, you are obviously an experienced programmer. The fact that you decided to start this excellent project is enough proof for me. That's why I was surprised by your initial position on data hiding. You certainly know that unecessary data should be hidden, and by the term "data" we mean everything, variables and functions (it also applies to types, objects, everything, absolutely everything).Anyways, I naturally admit that you are right about certain points; from what I said you must think that I even never thought about data hashing, about restricted access on internal data etc. Don't believe that, take a look on Battleship's source code and you will see that everything was made as rigorous as possible concerning the access to data's and functions - yes, it is possible to do that with C++.
I thought that it is not possible to hide data effectively in C++, you say that it can be done, good for C++ programmers, but I still don't like that language at all, due to its primitive mathematical capabilities. Whatever.
Thanks! Imperative explicit loading of functions that are by default local to the chunk that loads them is the goal! Of course, if the loadable chunk c2 contains a function declared as "local" then this function should not be accessible to the chunk c1 that loads c2.So don't worry, I will install restricted access to the global environment by external chunks. Please, don't try anything on your own about that in your Lua programs (like modifying the global environment's metatable etc), I will find a general, unavoidable (and invisible) way to make it.
Yes I consider data hashing (or hiding, call it as you wish) as an absolute order in every good programming language. And I'm not the only one.I'm reacting like that because you seem to consider this "data hashing" rule as an absolute order
First of all, the sentences you mention are not my arguments, they are not even my words. They are copied from excellent (I repeat, excellent) books on scientific programming, written by great scientists, such as S. Teukolsky. I didn't changed a iota, and I even added the exact page where you can find these sentences.but you were unable to explain why it is important: your lone arguments were sentences like "every programmer should respect it", "it is important for secure programming", "data hiding prevents unintended side effects from producing hard-to-find errors" (which ones??) Blindy follow a rule that is repeated everywhere, without knowing exactly why this rule must be applicated, often brings to disasters. I asked you many times how the break of this rule could lead to bugs or errors in CPLua... I 'm still waiting for some concrete examples.
I agree with you, I also don't like to blindly follow a rule without arguments. But I was not unable to give arguments. I said it many times: You don't want a function to be accessible from a program chunk for the same reasons that you don't want a variable to be accessible everywhere. Exactly the same reasons. Each program entity (variable, function, object etc) must be hidden, unless it is really neccessary to be accessible; even then, the entity should be explicitly loaded in the chunk that needs it. Implict loading is very dangerous: As it is now, If c1 loads c2, and c2 loads c3 then c3 is global. You like that? Have you ever seen something similar in any good programming language? What if you call c3 from c1 by mistake (say, a spelling error)? The interpreter won't complain, since c3 is implicitly accessible from c1; of course, this spelling error will give wrong results. Now, there are two cases: If you are lucky, you will notice that something is wrong, then you will start to search where is the source of the error, and because it is just a small spelling error (say, c3 insted of c2), you will spend hours, maybe days, to find out that c2 was written as c3 by mistake. The second case is even worst: you will not notice that something is wrong, and you will have a buggy program; if that program is a library function, then all programs that use that function will give wrong results, and it will be much more difficult to figure out where is the error.
Lua is powerful enough for developing a program which is more than "modest": the project I'm working now is not modest, even for a computer, not a calculator (see previous posts). It involves "heavy" Calculus and programming, and, yes, it can be implemented in ClassPad because of Lua, despite the fact that matrix support is very primitive.However I must admit that doscript and loadfunc have a very basic behaviour about it. In fact at this time I was thinking about really modest Lua projects, where those kind of "problems" were not supposed to appear. One day or another I would have had to change it anyways
The fact that we discuss things like data hash here simply means that the project is going very well. You should be happy with that. I'm personally very satisfied with this project, and I don't think that I'm the only one. Look at the "views" in this topic: they are already more that 1000, and the project is very young. But a good project also means hard work for the developer and the testers.
#101
Posted 11 September 2005 - 08:37 PM
Numerical Recipes in Basic is a little bit old book. They don't update the recipes anymore, as they do with Numerical Recipes in Fortran or C. It's a good start, anyway. You can download it by right clicking on the link, then selecting "Save Target As..."I think I should start with this one !
Numerical Recipes Routines and Examples in BASIC (First Edition)
Julien C. Sprott
University of Wisconsin, Madison
Is there any shared one on the web ?
I do not like the google print version ,it is really slow !
#102
Posted 11 September 2005 - 09:06 PM
Here is my suggestion:
Each loaded chunck (with loadfunc as with doscript) will be executed in a separated environment. When the execution ends, the environment of the calling chunck is restored exactly like it was before the call. Thus the called chunk has the possibility to change anything if it wants to, since he is playing in a "sandbox" that will change absolutely nothing for the calling chunk; except if it explicitely calls a function export() (that I didn't write yet) with as arguments the new variables/functions that it wants to pass to its 'parent' (the calling chunk). So inside an external chunk we can declare new local/global variables/functions, nothing will get out of there without the "export()" exit
When the parent restores its environment it also looks if some elements were specified with export(), it tries to find them in the "sandbox", and if there is something to export it copy those references inside its own environment, so he will got access to it.
Consequences:
- even if you forget to declare some variables as local etc, nothing can go out of a chunk implicitely. You must use export() for that.
- if chunk A loads chunk B which loads chunk C, A will get access to the exported symbols from chunk C only if B exports it too.
One question now: how must be the initial environment of each loaded chunk? Same as the very beginning of the program, or same as the parent chunk's one when it performs the call? I suppose you will prefer the first proposition
#103
Posted 11 September 2005 - 09:07 PM
Numerical Recipes in Basic is a little bit old book. They don't update the recipes anymore, as they do with Numerical Recipes in Fortran or C. It's a good start, anyway. You can download it by right clicking on the link, then selecting "Save Target As..."
there is no downloadable Link in the site
just the c , fortran book chapters are downloadable .
#104
Posted 11 September 2005 - 09:56 PM
Yes! the idea of a separate, independent environment is exactly what happens in several programming languages. Mathematica calls it "environment", exactly as you call it.Here is my suggestion:
Each loaded chunck (with loadfunc as with doscript) will be executed in a separated environment.
Perfect! The only thing I can say is that the hypothetical function export is not really needed. If a variable or function is declared as "local", it is unknown to the calling program. If it's not declared as local, the calling program has access to it. If you think that the idea can be more easily implemented with an export function then ok, the result is the same. But what if a function is local and you export it? It will be confusing. So I think that the declaration of a variable/function as local (or global) is enough to declare its scope.When the execution ends, the environment of the calling chunck is restored exactly like it was before the call. Thus the called chunk has the possibility to change anything if it wants to, since he is playing in a "sandbox" that will change absolutely nothing for the calling chunk; except if it explicitely calls a function export() (that I didn't write yet) with as arguments the new variables/functions that it wants to pass to its 'parent' (the calling chunk). So inside an external chunk we can declare new local/global variables/functions, nothing will get out of there without the "export()" exit
When the parent restores its environment it also looks if some elements were specified with export(), it tries to find them in the "sandbox", and if there is something to export it copy those references inside its own environment, so he will got access to it.
Consequences:
- even if you forget to declare some variables as local etc, nothing can go out of a chunk implicitely. You must use export() for that.
- if chunk A loads chunk B which loads chunk C, A will get access to the exported symbols from chunk C only if B exports it too.
One small remark: if chunk B is called by chunk A then chunk B should not be able to have access to variables or functions of chunk A, unless they are global, or the are passed to a function of chunk B as arguments.
Btw, Fortran 95 goes further: Every argument of a function should have the intent property: intent(in) means that the argument is passed as is, and the function cannot change it; intent(out) means that the argument is exported to the calling program; intent(inout) means that the argument is passed to the function, it can be changed, and the new value is returned to the calling chunk. As it is now, Lua has all arguments of a function declared as intent(inout). This can be confusing sometimes, but I can live with that.
Hmm, good question. Here is what happens in Fortran 95, maybe you will find it useful: the initial environment of each loaded chunk is "null". When a function returns control to the calling program, nothing is remembered. In fact, the temporary environment is destroyed. But if you want a local variable to retain its value, you can use the save command, which keeps the value of that variable so that it will be known in the next call. In other words, if a local variable is saved by the save command, the temporary environment is not destroyed, but keeps the value of that variable; even then, however, the calling chunk does not "know" this variable. Saving local variables is sometimes useful, but in practice it is rarely used, so skip it, if it cannot be implemented in CPLua easily.One question now: how must be the initial environment of each loaded chunk? Same as the very beginning of the program, or same as the parent chunk's one when it performs the call? I suppose you will prefer the first proposition
#105
Posted 11 September 2005 - 10:05 PM
I'm sorry I forgot that. As I said, Numerical Recipes in Basic is an old book, and it is not supported anymore . However, If you know french, I can suggest you some excellent books, which explain each numerical method, and give a very useful algorithm in pseudo-language (not in Fortran or C, but in sentences, something like a detailed flow chart). These books, however, are not downloadable.there is no downloadable Link in the site
just the c , fortran book chapters are downloadable .
#106
Posted 11 September 2005 - 10:13 PM
Indeed I think I will need this function to find the concerned variables; I didn't see any way to differentiate local or global variables in CThe only thing I can say is that the hypothetical function export is not really needed. If a variable or function is declared as "local", it is unknown to the calling program. If it's not declared as local, the calling program has access to it. If you think that the idea can be more easily implemented with an export function then ok, the result is the same.
I don't know what will happen... Wait and seeBut what if a function is local and you export it? It will be confusing.
The problem is that all the variables are global by default. So what if you forget to write "local" before a variable that you don't want to be exported? It could get problematic (from your point of view at least )So I think that the declaration of a variable/function as local (or global) is enough to declare its scope.
I think this can answer to my question concerning the initial environment: the new chunk receives a standard environment with only built-in libraries, but also the extra arguments given to loadfunc and doscript: by writing loadfunc("main/extern", foo), "extern" will only receive access to "foo" from the calling chunk:)One small remark: if chunk B is called by chunk A then chunk B should not be able to have access to variables or functions of chunk A, unless they are global, or the are passed to a function of chunk B as arguments.
About the intent property: since Lua functions can return several values at once, maybe you should try to ever use arguments as "in", and return values as "out"
Edit: concerning the "save" functionality: did you read the chapters about closures?
#107
Posted 11 September 2005 - 11:25 PM
I can forsee what will happen, as Nostradamus: Paranormal phenomena (unexpected results, bugs; maybe ClassPad will explode )I don't know what will happen... Wait and see
It will be nice if Lua had an imperative declaration (local or global), but it is not that serious. If you forget to write "local" before a variable that you don't want to be exported, then the variable will be global, and it will be your fault. No compiler or interpreter can predict human errors to happen.The problem is that all the variables are global by default. So what if you forget to write "local" before a variable that you don't want to be exported? It could get problematic (from your point of view at least )
I don't think that extra arguments in loadfunc are really needed. You want the function "foo" to be callable from chunk "extent"? make a separate chunk, place the function "foo" there, then load it to the main program and to the chunk "extent". But your idea is not bad at all, although I think that I will use the extra arguments rarely...I think this can answer to my question concerning the initial environment: the new chunk receives a standard environment with only built-in libraries, but also the extra arguments given to loadfunc and doscript: by writing loadfunc("main/extern", foo), "extern" will only receive access to "foo" from the calling chunk:)
Not yet. I have a real job, family, my dog wants to go out and I have to go with him, plus the weekend is over . But seriously, I'm planning to print it tomorrow, since I hate reading from a computer screen, even a flat one.Edit: concerning the "save" functionality: did you read the chapters about closures?
#108
Posted 12 September 2005 - 01:29 AM
I'm planning to print it tomorrow, since I hate reading from a computer screen, even a flat one.
If you are using Windows XP, make sure you are using clear type fonts:
1- Right click on desktop
2- Choose 'Properties'
3- Choose 'Appearance'
4- Click 'Effects' button in bottom right corner
5- Under 'Use the following method to smooth edges of screen fonts', choose 'Clear Type'
I'm using it since a few days and it's really better and easier to read...
#109
Posted 12 September 2005 - 07:47 AM
Blah, I really don't like it, it's too smoothI'm using it since a few days and it's really better and easier to read...
#110
Posted 12 September 2005 - 10:48 AM
Thanks for the hint, but I'm only use Windows to run the CP manager, and that because there is no <{GNULINUX}> version for this program.If you are using Windows XP, make sure you are using clear type fonts:
1- Right click on desktop
2- Choose 'Properties'
3- Choose 'Appearance'
4- Click 'Effects' button in bottom right corner
5- Under 'Use the following method to smooth edges of screen fonts', choose 'Clear Type'
I'm using it since a few days and it's really better and easier to read...
#111
Posted 12 September 2005 - 01:09 PM
This book is much better than the manual. I have many things to say about chapter 6, but I need it printed. Is there any downloadable pdf version?but I just discovered some other information, that you could find interesting: http://www.lua.org/pil/5.3.html
I suggest you to read the chapter 6 of this book, by the way.
#112
Posted 12 September 2005 - 01:10 PM
#113
Posted 12 September 2005 - 01:20 PM
Hmmm. I will convert html to pdf then. Mozilla permits that, but it should be done in separate files for each section, then you can merge the resulting pdfs. It's a little headache, though.I also find that this book is better. Unfortunately there is only an html version, and I think that finding the book in a library shouldn't be easy
#114
Posted 12 September 2005 - 10:27 PM
error:
g++.exe G:\0LUA\lua-5.0.2\g++.exe cannot specify -o with -c or -S and multiple compilations
I use Dev c++
what is the problem ?
#115
Posted 12 September 2005 - 10:31 PM
# Lua uses double for numbers. To change this, uncomment and edit the following
# line, changing USE_XXX to one of USE_DOUBLE, USE_FLOAT, USE_LONG, USE_INT.
#
#NUMBER= -DLUA_USER_H='"../etc/luser_number.h"' -DUSE_XXX
-----------------------------------------------------------------------------------
can be switch mode between them , for example by adding a switch function ?
#116
Posted 12 September 2005 - 10:39 PM
I think that it's time to start publish CPLua programs. I tried to do so, but it seems that I cannot, as a forum member, create a new "category" in ClassPad files. There are currently only 2 categories; "Add-Ins" and "Basic programs". Obviously, CPLua programs don't fit to any existing category. I would like to create a new category, "CPLua programs", preferrably with subcategories, such as "Numerical Analysis Lua programs" (this is where I want to upload files), "Lua Games", or whatever. Does anyone know if it is possible to create new categories in the "File sharing" section for ClassPad? If it's not possible, how can I contact a moderator, in order to ask him/her to add such a category in File sharing?
#117
Posted 12 September 2005 - 10:52 PM
Good point. Right now CPLua isn't even on ClassPad.org. Orwell, do you mind if it's uploaded? I'm assuming you wanted to do must of the debugging and get it to be more stable first. If you feel comfortable with it what do you think about a category for CPLua?I think that it's time to start publish CPLua programs. I tried to do so, but it seems that I cannot, as a forum member, create a new "category" in ClassPad files. There are currently only 2 categories; "Add-Ins" and "Basic programs". Obviously, CPLua programs don't fit to any existing category. I would like to create a new category, "CPLua programs", preferrably with subcategories, such as "Numerical Analysis Lua programs" (this is where I want to upload files), "Lua Games", or whatever. Does anyone know if it is possible to create new categories in the "File sharing" section for ClassPad? If it's not possible, how can I contact a moderator, in order to ask him/her to add such a category in File sharing?
#118
Posted 12 September 2005 - 10:57 PM
In case of misunderstanding, I never said that I want to upload CPLua itself, only CPLua programs that I think they might be useful to others. I'm not the developer, I'm only a tester.Good point. Right now CPLua isn't even on ClassPad.org. Orwell, do you mind if it's uploaded? I'm assuming you wanted to do must of the debugging and get it to be more stable first. If you feel comfortable with it what do you think about a category for CPLua?
#119
Posted 12 September 2005 - 10:59 PM
I don't know... You should be able to add the Lua core files to dev-cpp's project, you don't have to compile manually.when I want to Install the Lua interpreter on my computer :
error:
g++.exe G:\0LUA\lua-5.0.2\g++.exe cannot specify -o with -c or -S and multiple compilations
I use Dev c++
what is the problem ?
No. The specified type is used during compilation, and nothing can be changed about that during the execution of the compiled program.-----------------------------------------------------------------------------------
# Lua uses double for numbers. To change this, uncomment and edit the following
# line, changing USE_XXX to one of USE_DOUBLE, USE_FLOAT, USE_LONG, USE_INT.
#
#NUMBER= -DLUA_USER_H='"../etc/luser_number.h"' -DUSE_XXX
-----------------------------------------------------------------------------------
can be switch mode between them , for example by adding a switch function ?
Good to know that you're still improving your projectsMy Romberg integration project has been upgraded, after extensive tests. The Lua program is now more flexible, it has more features, and it is much faster than CP's built-in numerical integration. Furthermore, the "Brent" project has been slightly upgraded. I'm currently working on a much more difficult project: making a Lua program able to compute all the roots of a given function withiin a given interval with certainty. The most difficult part of this project seems to be completed, and I hope that I will be able to finish the project within the next 5 days... Of course, when new Lua functions for chunk loading will be available, I will make small modifications to the above programs in order to change the variable/function scope. Orwell, any news about that?
From my side I should have finished the "isolation" of the different chunks, and the export function seems to work fine - its syntax has changed a bit, but the result is the same. I would like to add some new features before releasing a new version, this should take one or 2 days
The guy who is in charge of that has just posted a message a few posts above this one 2072 (if you read me), could you do that for us?I think that it's time to start publish CPLua programs. I tried to do so, but it seems that I cannot, as a forum member, create a new "category" in ClassPad files. There are currently only 2 categories; "Add-Ins" and "Basic programs". Obviously, CPLua programs don't fit to any existing category. I would like to create a new category, "CPLua programs", preferrably with subcategories, such as "Numerical Analysis Lua programs" (this is where I want to upload files), "Lua Games", or whatever. Does anyone know if it is possible to create new categories in the "File sharing" section for ClassPad? If it's not possible, how can I contact a moderator, in order to ask him/her to add such a category in File sharing?
By the way, did you succeed in exchanging Lua programs with the computer like a standard Basic program? Or do you plan to release it as a text file?
Edit: hey what's happening to my "quote" tags?
2072: nothing
Edited by 2072, 13 September 2005 - 03:17 AM.
#120
Posted 12 September 2005 - 11:06 PM
But well, maybe some advertising could be a good idea, after all that will certainly interest some people that do not come on this forum.
I'm okay to release a "beta" version more publicly, but I can't assume its complete stability (but it's a beta version so whatever )
I will just ask to wait the 0.7 version for that. There will be many other versions after this one...
And, SoftCalc, a Lua category on classpad.org would be great!
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users