Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : MicroMite Beta 15
Page 4 of 4 | |||||
Author | Message | ||||
robert.rozee Guru Joined: 31/12/2012 Location: New ZealandPosts: 2350 |
that implies that it is legal for a function and a variable to have the same name. yet within the function, the variable can then not be assigned to. it would seem that shared names like this should generate an error. and if allowed, surely the function declaration should require the () be explicitly there. pascal is so much more logical!! rob :-) |
||||
paceman Guru Joined: 07/10/2011 Location: AustraliaPosts: 1329 |
The manual specifically states that variables and function names can't be the same: "A variable name or a label must not be the same as a function or one of the following keywords:...." It also notes this in another area: "The rules for the argument list in a function are similar to subroutines. The only difference is that brackets are required around the argument list when you are calling a function (they are optional when calling a subroutine). To return a value from the function you assign a value to the function's name within the function.... Within the function the function's name acts like a standard variable.... It is only when the function returns that the value assigned to MyTime$ is made available to the expression that called it. ...This example also illustrates that you can use local variables within functions just like subroutines." It took me about a minute to find that Rob. Greg :-) |
||||
robert.rozee Guru Joined: 31/12/2012 Location: New ZealandPosts: 2350 |
it is clear that variable and function names should not be the same, but that there is no mechanism enforcing this. and, to be honest, i can not see any way an interpreter could enforce this without making a pre-run pass to built up the necessary tables to compare names against. such a process is beyond what can be expected of something with the meagre resources of a maxi- or micromite. the problem occurs where someone has a function with no parameters and forgets to include the empty parameter list, (). this is very easy to do, especially when one regularly uses other languages. being BASIC, with no requirement to declare variables before using them, the interpreter just creates (all on it's own) a variable with the same name as the function. in an ideal world, BASIC would not allow the use of a variable until it had been declared with either a VAR or a DIM statement if i had my way, all variables would need to be explicitly declared before use. rob :-) |
||||
graynomad Senior Member Joined: 21/07/2010 Location: AustraliaPosts: 122 |
Yes this is a weakness in BASIC, VB had "Option Explicit" (I think it was) that forced declaration of variables before usage. Rob Gray, AKA the Graynomad, www.robgray.com |
||||
MicroBlocks Guru Joined: 12/05/2012 Location: ThailandPosts: 2209 |
Your BASIC program would be a little larger as you have to declare everything. It also takes away the ease of use. It probably does not take more firmware space to check for the existence of a variable. It does it anyway and when it does not find it it creates a new one, instead it could throw an error. This would be a runtime error and those are not always encountered. For checking that a variable is used as a function or subroutine name in the case that it is not used before can have a speed penalty. I think leaving out the () by accident is a programmers bug that is very quickly found. Microblocks. Build with logic. |
||||
plasma Guru Joined: 08/04/2012 Location: GermanyPosts: 437 |
i cant see a problem with the basic style which MMbasic provide. declare all variables in the start if you think you need it . use goto or not , its all your choice . |
||||
WhiteWizzard Guru Joined: 05/04/2013 Location: United KingdomPosts: 2817 |
Well said Plasma For a beginner it is easier to learn coding with the way things are that Geoff has provided. From an experienced coders point of view, MMBasic could/should be more 'strict' with it's syntax. Bottom line - you can't satisfy everybody. . . . For everything Micromite visit micromite.org Direct Email: whitewizzard@micromite.o |
||||
robert.rozee Guru Joined: 31/12/2012 Location: New ZealandPosts: 2350 |
change of tack. a quick question for geoff: how practical would it be (note: not a feature request) to use the internal band-gap reference with the A/D converter. this would mean that for applications run of 2x AA batteries the analog inputs would have repeatable readings without the need for an external reference hooked up to one of the analog pins. yes, i know the internal band-gap does have a wide tolerance, but it does have relatively good stability. right now, as battery voltage drops so does the read voltage. and at the 2.6v minimum operating voltage the values from the A/D will appear as being miles out. i'm guessing the switchover could be accomplished with a few POKEs, though scaling of the readings would still be required. rob :-) |
||||
Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3196 |
That's a great idea and I have had a look at implementing it. Unfortunately you cannot do it with PEEK/POKE and it would require some new functionality within MMBasic so I will have to leave it out until the major release after this one. It is a pity that the reference is so inaccurate, it would have been good to have used it as the reference for all analogue measurements. Geoff Geoff Graham - http://geoffg.net |
||||
robert.rozee Guru Joined: 31/12/2012 Location: New ZealandPosts: 2350 |
band-gap references always require some individual trimming at the factory, which would have added a significant margin onto the 32MX device cost. the trick would be to allow switching between reference sources (OPTION REF 3V3 | INT) as well as adding calibration settings (MM.CAL_3V3 and MM.CAL_INT, both defaulting to 1.0). with the values held in eeprom, a user could carry out their own calibration just once after first programming in the micromite firmware. rob :-) |
||||
Greg Fordyce Senior Member Joined: 16/09/2011 Location: United KingdomPosts: 153 |
Small typo found on page 65 (Appendix D SPI commands) near the bottom in the section I/O Pins is a sentence that reads; "Then can then be configured as per normal using SETPIN." Probably should read; "They can then be configured as per normal using SETPIN." |
||||
Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3196 |
Thanks Greg, well spotted. Geoff Geoff Graham - http://geoffg.net |
||||
Page 4 of 4 |
Print this page |