[fpc-pascal] a few trivial questions
Michael Van Canneyt
michael at freepascal.org
Wed May 12 16:45:47 CEST 2010
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.
More information about the fpc-pascal
mailing list