Re: [fpc-pascal] Optional param modifier

2019-04-14 Thread Martin Frb
On 14/04/2019 22:08, Ryan Joseph wrote: Per my example, currently we know that GetThing() COULD return nil so unless we know what the function does by reading the documentation or looking at the implementation we need to test for nil. Right? I suggest the modifier simply to enforce that

[fpc-pascal] how to call .so library while using FREE Pascal JVM and Android target

2019-04-14 Thread Mgr. Janusz Chmiel
Dear specialists, Is it possible to call .so library when I have used Free Pascal compiler and I have set JVM target and option to create Android compatible Java classes? Because when ever I want to call some .so library I Am getting The following error. Failed resolution of: .so OK Sure,

Re: [fpc-pascal] Optional param modifier

2019-04-14 Thread Ryan Joseph
> On Apr 14, 2019, at 6:30 PM, Martin Frb wrote: > > I would actually argue that it is infinitely more important to check for nil > after MakeThing. (Unless I know for sure it is not needed: proof, docs) > > Assuming (taking the danger of doing so) both do what there name indicates, > then:

Re: [fpc-pascal] Can FPC optimize: if (s[i]='a') or ...

2019-04-14 Thread Bernd Oppolzer
Am 15.04.2019 um 03:35 schrieb wkitt...@windstream.net: On 4/14/19 7:28 AM, Rainer Stratmann wrote: On Samstag, 13. April 2019 22:30:55 CEST Alexey Tor. wrote: E.g. i have a loop which test each s[i] char for several cases: 'a', 'b', 'c'. for i:= 1 to length(s) do if (s[i]='a') or (s[i]='b')

Re: [fpc-pascal] Optional param modifier

2019-04-14 Thread Martin Frb
On 14/04/2019 19:53, Ryan Joseph wrote: On Apr 14, 2019, at 1:38 PM, Sven Barth via fpc-pascal wrote: As already said by Martin: the compiler *can not* determine all cases whether the parameter is Nil or not, so it *must* be done at runtime to ensure this. Otherwise the feature is just as

Re: [fpc-pascal] Optional param modifier

2019-04-14 Thread Ryan Joseph
> On Apr 14, 2019, at 3:38 PM, Martin Frb wrote: > > > One thing is what checks can be done, to help the programmer not to > accidentality de-ref nil. > The other thing is how. > > 1) The "optional" is actually the default. If anything towards a deref-warn > feature was done, then *every*

Re: [fpc-pascal] mode switch madness

2019-04-14 Thread wkitty42
On 4/14/19 9:08 AM, Anthony Walter wrote: Someone said: "You can do a {$i mysettings.inc}" I give that a +1 FWIW: all of the delphi code that i've worked with trying to port to FPC has had this... at least one had an include file that IFDEF'd its way through like 4 or 5 other pascal

Re: [fpc-pascal] Optional param modifier

2019-04-14 Thread Martin Frb
On 15/04/2019 00:53, Ryan Joseph wrote: Here’s what I imagine that would look like: procedure CreateHero (name: string; hp: integer); requires name <> ''; (hp > 0) and (hp < 100); begin // compilers parses the conditions and inserts as if statements: // if name <> ‘’ then //

Re: [fpc-pascal] Optional param modifier

2019-04-14 Thread Martin Frb
On 14/04/2019 23:48, Martin Frb wrote: I admit the contract/assert stuff may have made it seem different. But that is because this approach does not hold up (IMHO). And therefore the closest alternative was presented. In the very end it is to avoid crashing on nil de-ref. And the

Re: [fpc-pascal] Can FPC optimize: if (s[i]='a') or ...

2019-04-14 Thread wkitty42
On 4/14/19 7:28 AM, Rainer Stratmann wrote: On Samstag, 13. April 2019 22:30:55 CEST Alexey Tor. wrote: E.g. i have a loop which test each s[i] char for several cases: 'a', 'b', 'c'. for i:= 1 to length(s) do if (s[i]='a') or (s[i]='b') or (s[i]='c') then ... Can FPC optimize it so it only

Re: [fpc-pascal] Optional param modifier

2019-04-14 Thread Martin Frb
On 14/04/2019 22:08, Ryan Joseph wrote: function FindThing: TThing; optional; means you MUST check for nil. If the value is nil that’s not an error. “optional” is probably a bad name for this I know. function MakeThing: TThing; this means maybe check for nil or maybe not

Re: [fpc-pascal] Optional param modifier

2019-04-14 Thread Martin Frb
On 15/04/2019 01:19, Ryan Joseph wrote: On Apr 14, 2019, at 7:08 PM, Martin Frb wrote: Almost. assert takes the condition itself assert(condition_that_must_be_true, 'error message') so it would be assert(name<>'', 'requires "name <> " failed for CreateHero'); You can already insert

Re: [fpc-pascal] Optional param modifier

2019-04-14 Thread Ryan Joseph
> On Apr 14, 2019, at 7:08 PM, Martin Frb wrote: > > Almost. assert takes the condition itself > > assert(condition_that_must_be_true, 'error message') > > so it would be > assert(name<>'', 'requires "name <> " failed for CreateHero'); > > You can already insert such asserts yourself.

Re: [fpc-pascal] Can FPC optimize: if (s[i]='a') or ...

2019-04-14 Thread Rainer Stratmann
On Samstag, 13. April 2019 22:30:55 CEST Alexey Tor. wrote: > E.g. i have a loop which test each s[i] char for several cases: 'a', > 'b', 'c'. > > for i:= 1 to length(s) do > > if (s[i]='a') or (s[i]='b') or (s[i]='c') then ... > > Can FPC optimize it so it only reads s[i] once (to register),

Re: [fpc-pascal] mode switch madness

2019-04-14 Thread Anthony Walter
Someone said: "You can do a {$i mysettings.inc}" I give that a +1 ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Can FPC optimize: if (s[i]='a') or ...

2019-04-14 Thread Bernd Oppolzer
Am 13.04.2019 um 21:55 schrieb Ralf Quint: On 4/13/2019 12:30 PM, Alexey Tor. wrote: E.g. i have a loop which test each s[i] char for several cases: 'a', 'b', 'c'. for i:= 1 to length(s) do if (s[i]='a') or (s[i]='b') or (s[i]='c') then ... Can FPC optimize it so it only reads s[i] once (to

Re: [fpc-pascal] Optional param modifier

2019-04-14 Thread Sven Barth via fpc-pascal
Ryan Joseph schrieb am So., 14. Apr. 2019, 00:17: > > > > On Apr 13, 2019, at 6:01 PM, Sven Barth via fpc-pascal < > fpc-pascal@lists.freepascal.org> wrote: > > > > Well, there is Oxygene's concept of Class Contracts (see > > https://docs.elementscompiler.com/Concepts/ClassContracts/ ), so if >

Re: [fpc-pascal] mode switch madness

2019-04-14 Thread Florian Klämpfl
Am 14.04.2019 um 04:07 schrieb Ben Grasset: > I dunno about setting them globally, but generally I do find modeswitches > rather annoying, as the combination of > features is pretty arbitrary, and they mostly just *disallow* things that > couldn't break the code of people who weren't > using

Re: [fpc-pascal] mode switch madness

2019-04-14 Thread Ryan Joseph
> On Apr 13, 2019, at 10:07 PM, Ben Grasset wrote: > > E.G, I sincerely doubt that anybody has *ever* thought, "man, I sure am glad > that {$mode ObjFPC} does not allowed advanced records. It would be > specifically bad if it did!" because it just doesn't matter if they weren't > using

Re: [fpc-pascal] Optional param modifier

2019-04-14 Thread Ryan Joseph
> On Apr 14, 2019, at 3:15 AM, Sven Barth via fpc-pascal > wrote: > > Your idea requires exceptions as well. The compiler is not capable checking > whether valid entries are passed in at compile time except for simple, > constant cases, so runtime checks are needed and the only way to abort

Re: [fpc-pascal] mode switch madness

2019-04-14 Thread Jonas Maebe
On 14/04/2019 17:03, Ryan Joseph wrote: On Apr 13, 2019, at 10:07 PM, Ben Grasset wrote: E.G, I sincerely doubt that anybody has *ever* thought, "man, I sure am glad that {$mode ObjFPC} does not allowed advanced records. It would be specifically bad if it did!" because it just doesn't

Re: [fpc-pascal] Optional param modifier

2019-04-14 Thread Martin Frb
On 14/04/2019 16:05, Ryan Joseph wrote: On Apr 14, 2019, at 3:15 AM, Sven Barth via fpc-pascal wrote: Your idea requires exceptions as well. The compiler is not capable checking whether valid entries are passed in at compile time except for simple, constant cases, so runtime checks are

Re: [fpc-pascal] Optional param modifier

2019-04-14 Thread Martin Frb
On 14/04/2019 18:04, Martin Frb wrote: On 14/04/2019 16:05, Ryan Joseph wrote: On Apr 14, 2019, at 3:15 AM, Sven Barth via fpc-pascal wrote: Your idea requires exceptions as well. The compiler is not capable checking whether valid entries are passed in at compile time except for simple,

Re: [fpc-pascal] mode switch madness

2019-04-14 Thread Sven Barth via fpc-pascal
Am 14.04.2019 um 17:03 schrieb Ryan Joseph: On Apr 13, 2019, at 10:07 PM, Ben Grasset wrote: E.G, I sincerely doubt that anybody has *ever* thought, "man, I sure am glad that {$mode ObjFPC} does not allowed advanced records. It would be specifically bad if it did!" because it just doesn't

Re: [fpc-pascal] mode switch madness

2019-04-14 Thread Sven Barth via fpc-pascal
Am 14.04.2019 um 04:07 schrieb Ben Grasset: I dunno about setting them globally, but generally I do find modeswitches rather annoying, as the combination of features is pretty arbitrary, and they mostly just *disallow* things that couldn't break the code of people who weren't using those

Re: [fpc-pascal] Optional param modifier

2019-04-14 Thread Sven Barth via fpc-pascal
Am 14.04.2019 um 16:05 schrieb Ryan Joseph: On Apr 14, 2019, at 3:15 AM, Sven Barth via fpc-pascal wrote: Your idea requires exceptions as well. The compiler is not capable checking whether valid entries are passed in at compile time except for simple, constant cases, so runtime checks are

Re: [fpc-pascal] Optional param modifier

2019-04-14 Thread Ryan Joseph
> On Apr 14, 2019, at 1:38 PM, Sven Barth via fpc-pascal > wrote: > > As already said by Martin: the compiler *can not* determine all cases whether > the parameter is Nil or not, so it *must* be done at runtime to ensure this. > Otherwise the feature is just as useful as this: I’ve read

Re: [fpc-pascal] mode switch madness

2019-04-14 Thread Ryan Joseph
> On Apr 14, 2019, at 1:29 PM, Sven Barth via fpc-pascal > wrote: > >> I like what Jonas did for the ObjC mode switch where he named them with >> versions. Maybe a {$mode objfpc2} one day. > My idea was to maybe add a mode ObjFPCExt or ObjFPCAdv which is quite a bit > less conservative and