Re: [fpc-pascal] Does FPC has consts of portable OS error codes?
On Wed, May 12, 2010 07:37, Bihar Anwar wrote: > Something like this one: > https://libxpl.arsoft.homeip.net/browser/trunk/errormap/xplErrorMap.cpp?rev=70 I don't think we have platform independent (named) constants defined, but as you probably know, common error code _values_ are defined for our RTL as documented in chapter "Run time errors" in our Users' Guide. Tomas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Does FPC has consts of portable OS error codes?
On 12 May 2010, at 05:53, Bihar Anwar wrote: As the title says. :-) No, it doesn't. Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Does FPC has consts of portable OS error codes?
Jonas Maebe on May 12, 2010 2:32:18 PM On 12 May 2010, at 05:53, Bihar Anwar wrote: >> As the title says. :-) > No, it doesn't. Any reason for that? or it is not implemented yet? ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Does FPC has consts of portable OS error codes?
In our previous episode, Bihar Anwar said: > On 12 May 2010, at 05:53, Bihar Anwar wrote: > > >> As the title says. :-) > > > No, it doesn't. > > Any reason for that? or it is not implemented yet? FPC does not support abstraction of operating system errorcodes, and doesn't plan to. The experiences in this regard (e.g. with the DOS unit) were not exactly positive. Note that the fact that some header tries to hapzardly try to implement this for just two platforms doesn't prove this is universally possible. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Does FPC has consts of portable OS error codes?
> Any reason for that? or it is not implemented yet? For me: it's not required. The purpose of error code is to provide information so we can handle it correctly, or at the simplest case, to display to user what has happened. For the first one, usually errors in FPC generate exception, you can handle that instead. For the second, a combination of GetLastOSError and SysErrorMessage provides what's needed. -- View this message in context: http://old.nabble.com/Does-FPC-has-consts-of-portable-OS-error-codes--tp28531773p28533509.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Does FPC has consts of portable OS error codes?
leledumbo onMay 12, 2010 3:58:09 PM > Any reason for that? or it is not implemented yet? > For the first one, usually errors in FPCgenerate exception, you can handle > that instead. Yes, as you said "usually", it is not "always". For example, FindFirst() and FindNext return OS dependent error code. > For the second, acombination of GetLastOSError and SysErrorMessage provides > what's needed. In my case, this is not something I want. I want to handle "trivial errors" (e.g. ERROR_ACCESS_DENIED, ERROR_NOT_READY, etc.) differ from "fatal errors". Trivial errors will allow users to retry the failed operation. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] a few trivial questions
Hello, * TFPList Is there another way to traverse a list than for i :=0 to (list.count - 1) do ... What about list.high? Also, is it possible to set a list's base index to 1 (so that last_index=count)? There is a super handy forEachCall method (calling a proc for each item), but I cannot find a matching map method (calling a func and storing results). * string <-> number I could not find _functions_ to operate such conversions, only _procedures_ str and val. So that I always end up with superfluous statements and temps variables: str(n,text); writeln(text); vs writeln(NumbetToString(n)); Ok, I can write these funcs (I did ;-). But how comes there are no builtin functions for that? * string section Is there another way to slice a string than using copy. In particuliar, the count argument is not always practical to indicate the end_of_section position. (count = last-first+1) * array value notation I can set a static array's value on declaration line, but could not find a way to do it later (even less to change it). And I cannot find a way to set the value of a dynamic array --when it's not fed from a loop. End up with series of arr[i]:=v statements (code from the http://en.wikipedia.org/wiki/Middle_ages ;-). Same for lists, indeed. var arr : array [1..2] of Integer; ... i:=1 ; j:=2; arr := (i,j); ==> Syntax error, ")" expected, but "," found Finally: is there a wiki version of the official docs, to collectively enhance them (with notes, examples, explanations...). (I'm dreaming, but after all fpc is free software, and it's the #1 reason why I chose it.) (*) Denis (*) This gives me an idea: a converse doc system that takes properly formatted doc and inserts proper parts of it as comment into the code at their proper place -- not the contrary ;-) [class TFoo] ... [method Do] ... ) ... > inserted just before/after TFoo.Do's header in code ... ) [/method] ... [/class] vit esse estrany ☣ spir.wikidot.com ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] a few trivial questions
On Wed, 12 May 2010, spir ☣ wrote: Hello, * TFPList Is there another way to traverse a list than for i :=0 to (list.count - 1) do ... You can use an enumerator with the latest SVN: foreach P in List do What about list.high? Count=High. Also, is it possible to set a list's base index to 1 (so that last_index=count)? No. That would break all other existing code. There is a super handy forEachCall method (calling a proc for each item), but I cannot find a matching map method (calling a func and storing results). What do you mean with 'Map' ? * string <-> number I could not find _functions_ to operate such conversions, only _procedures_ str and val. So that I always end up with superfluous statements and temps variables: str(n,text); writeln(text); In SysUtils: StrToInt() and IntToStr() vs writeln(NumbetToString(n)); Ok, I can write these funcs (I did ;-). But how comes there are no builtin functions for that? They exist; you simply don't know them. * string section Is there another way to slice a string than using copy. In particuliar, the count argument is not always practical to indicate the end_of_section position. (count = last-first+1) I think that LeftStr and RightStr exist in strutils. * array value notation I can set a static array's value on declaration line, but could not find a way to do it later (even less to change it). And I cannot find a way to set the value of a dynamic array --when it's not fed from a loop. End up with series of arr[i]:=v statements (code from the http://en.wikipedia.org/wiki/Middle_ages ;-). Same for lists, indeed. var arr : array [1..2] of Integer; ... i:=1 ; j:=2; arr := (i,j); ==> Syntax error, ")" expected, but "," found This is only possible with dynamic arrays (no declared length), and there you should use setlength. Finally: is there a wiki version of the official docs, to collectively enhance them (with notes, examples, explanations...). (I'm dreaming, but after all fpc is free software, and it's the #1 reason why I chose it.) (*) No, there is no wiki version, and there never will be. Michael.___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] a few trivial questions
2010/5/12 spir ☣: > > * TFPList > Is there another way to traverse a list than > for i :=0 to (list.count - 1) do ... > What about list.high? Yes, I use the Iterator design pattern. This allows me to write code as follows: --- var itr: ITBStringIterator; begin ... itr := gIteratorFactory.StringIterator(sl); while itr.HasNext do writeln(itr.Next); ... end; --- I have created Iterators for all existing list types and the code (and accompanied article explaining Iterators) are freely available at: http://opensoft.homeip.net/articles/ Iterators have the added flexibility that I can even combine them with regular expressions to creating a filtered list. --- fitr := gIteratorFactory.FilteredStringIterator(MyStringsCollection, 'foob.*r'); while fitr.HasNext do begin DoSomethingWithItem(fitr.Next); ... end; --- I can also move backwards, forwards, peak back or forward, reverse the iterating, reset the iteration etc. Iterators are very flexible. > Ok, I can write these funcs (I did ;-). But how comes there are no builtin > functions for that? IntToStr(), Format(), FormatFloat() etc...? > Is there another way to slice a string than using copy. In particuliar, the > count argument is not always practical to indicate the end_of_section > position. (count = last-first+1) > Again here you can use iterators to iterator character by character if you want. No need to know about Count or Count-1 etc. For all types of lists you now have the same interface iterator.HasNext ...Michael answered the rest of the questions. -- Regards, - Graeme - ___ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/ ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] a few trivial questions
Michael Van Canneyt wrote: On Wed, 12 May 2010, spir ☣ wrote: Hello, * TFPList Is there another way to traverse a list than for i :=0 to (list.count - 1) do ... You can use an enumerator with the latest SVN: foreach P in List do That's good news. I wasn't aware that that had been implemented. -- Warm Regards, Lee ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] a few trivial questions
On Wed, 12 May 2010 17:19:57 +0200 Graeme Geldenhuys wrote: > 2010/5/12 spir ☣: > > > > * TFPList > > Is there another way to traverse a list than > > for i :=0 to (list.count - 1) do ... > > What about list.high? > > Yes, I use the Iterator design pattern. This allows me to write code as > follows: > > --- > var > itr: ITBStringIterator; > begin > ... > itr := gIteratorFactory.StringIterator(sl); > while itr.HasNext do > writeln(itr.Next); >... > end; > --- > > I have created Iterators for all existing list types and the code (and > accompanied article explaining Iterators) are freely available at: > http://opensoft.homeip.net/articles/ > > Iterators have the added flexibility that I can even combine them with > regular expressions to creating a filtered list. > --- > fitr := gIteratorFactory.FilteredStringIterator(MyStringsCollection, > 'foob.*r'); > while fitr.HasNext do > begin > DoSomethingWithItem(fitr.Next); > ... > end; > --- > > I can also move backwards, forwards, peak back or forward, reverse the > iterating, reset the iteration etc. Iterators are very flexible. Oh, thank you for this pattern. This is a really nice feature, esp. in that it integrates so well with while loops? I'll have a look at your code as soon as I can. Denis vit esse estrany ☣ spir.wikidot.com ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] a few trivial questions
On Wed, 12 May 2010 16:45:47 +0200 (CEST) Michael Van Canneyt wrote: > > > On Wed, 12 May 2010, spir ☣ wrote: > > > Hello, > > > > * TFPList > > Is there another way to traverse a list than > >for i :=0 to (list.count - 1) do ... > > You can use an enumerator with the latest SVN: > > foreach P in List do Great! > > What about list.high? > > Count=High. ? In my code count=high+1. I mean list[list.count] does not exist. > > Also, is it possible to set a list's base index to 1 (so that > > last_index=count)? > > No. That would break all other existing code. I don't understand. If I set myList.baseIndex := 1, how can it affect other people's code? It's a new feature that does not touch existing codebase. > > There is a super handy forEachCall method (calling a proc for each item), > > but I cannot find a matching map method (calling a func and storing > > results). > > What do you mean with 'Map' ? It's the conventional name in most PLs of a higher-order function that creates a new sequence from an original one and a mapping func: cubes := map(numbers, cube) or in OO style: cubes := numbers.map(cube) But you certainly know that better than me... > > * string <-> number > > I could not find _functions_ to operate such conversions, only _procedures_ > > str and val. So that I always end up with superfluous statements and temps > > variables: > >str(n,text); > >writeln(text); > > In SysUtils: StrToInt() and IntToStr() Thank you. Hadn't found them. [...] > > * array value notation > > I can set a static array's value on declaration line, but could not find a > > way to do it later (even less to change it). And I cannot find a way to set > > the value of a dynamic array --when it's not fed from a loop. End up with > > series of arr[i]:=v statements (code from the > > http://en.wikipedia.org/wiki/Middle_ages ;-). Same for lists, indeed. > >var > >arr : array [1..2] of Integer; > >... > >i:=1 ; j:=2; > >arr := (i,j); > >==> Syntax error, ")" expected, but "," found > > This is only possible with dynamic arrays (no declared length), and there you > should use setlength. I haven't managed to do that with dynamic arrays, even after setting length. var a : array of Integer; begin setLength(a, 3); a := (1,2,3); writeln(a[1]); end. ==> same error message as above > > Finally: is there a wiki version of the official docs, to collectively > > enhance them (with notes, examples, explanations...). > > (I'm dreaming, but after all fpc is free software, and it's the #1 reason > > why I chose it.) (*) > > No, there is no wiki version, and there never will be. ... Denis vit esse estrany ☣ spir.wikidot.com ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal