?
"IF.. THEN ..;" & "IF ..THEN BEGIN .. END;" => "IF .. THEN .. END;"
Модератор: Модераторы
?
"IF.. THEN ..;" & "IF ..THEN BEGIN .. END;" => "IF .. THEN .. END;"
debi12345 писал(а):?
"IF.. THEN ..;" & "IF ..THEN BEGIN .. END;" => "IF .. THEN .. END;"
procedure test;
begin
end;
mse писал(а):or everywhere where one likes to group statements.
Вообще, зачем кого-то переубеждать? Можно же свой язык сделать!
Hi,
'()' for procedure header and procedure calling is mandatory.
"
procedure noparams();
begin
end;
procedure test();
begin
noparams();
end;
"
Parameter separator is ','.
"
procedure params(a: int32, b: int32);
begin
end;
procedure test();
begin
params(123,456);
end;
"
There will be no extra reserved name for functions, functions are defined
by ':' TYPE. Return values are supplied by 'return' statement. A 'return'
statement before 'end;' is mandatory.
"
procedure func(a: bool8): int32;
begin
if a then
return 123;
end;
return 458;
end;
"
Opinions?
------------------------------------------------------------------------------
Ivanko B
<ivankob4mse2@gmail.com> 20 ноября 2013 г., 21:02
The "result" auto-variable will also be available ?
Martin Schreiber
<mse00000@gmail.com> 20 ноября 2013 г., 21:06
> The "result" auto-variable will also be available ?
>
No.
Ivanko B
<ivankob4mse2@gmail.com> 20 ноября 2013 г., 21:53
Why ?! It's one of best advantages of ObjPascal allowing not to bother
about allocating/freeing memory for non-atomic function result types.
Martin Schreiber
<mse00000@gmail.com> 20 ноября 2013 г., 22:19
> Why ?! It's one of best advantages of ObjPascal allowing not to bother
> about allocating/freeing memory for non-atomic function result types.
>
Please explain, I don't understand.
Delphi 'result' is not well defined, especially with reference counted types.
Ivanko B
<ivankob4mse2@gmail.com> 20 ноября 2013 г., 23:38
Returning NEW strings, dynarrays etc refcounted (automatically
destroyable) types from function.
Marcos Douglas
<md@delfire.net> 21 ноября 2013 г., 3:01
> Hi,
>
> '()' for procedure header and procedure calling is mandatory.
> "
> procedure noparams();
> begin
> end;
>
> procedure test();
> begin
> noparams();
> end;
> "
No, no, no...please!
I know that you want to make a language more ortogonal but exceptions
could exist! If you do not have parameters, why I need use this '()'?
> Parameter separator is ','.
> "
> procedure params(a: int32, b: int32);
> begin
> end;
>
> procedure test();
> begin
> params(123,456);
> end;
> "
That's Ok for me.
> There will be no extra reserved name for functions, functions are defined
> by ':' TYPE. Return values are supplied by 'return' statement. A 'return'
> statement before 'end;' is mandatory.
> "
> procedure func(a: bool8): int32;
> begin
> if a then
> return 123;
> end;
> return 458;
> end;
> "
>
> Opinions?
I agree that not needs to exist procedure and function keywords, but
if one them will be excluded then "procedure" keyword is the best
choice.
The most languages uses "function" so why MSElang can't uses that keyword too?
> There will be no extra reserved name for functions, functions are defined
> by ':' TYPE. Return values are supplied by 'return' statement. A 'return'
> statement before 'end;' is mandatory.
> "
> procedure func(a: bool8): int32;
> begin
> if a then
> return 123;
> end;
> return 458;
> end;
> "
>
> Opinions?
I agree that not needs to exist procedure and function keywords, but
if one them will be excluded then "procedure" keyword is the best
choice.
The most languages uses "function" so why MSElang can't uses that keyword too?
Sieghard
<s_c_h_s@arcor.de> 21 ноября 2013 г., 4:55
Hallo Martin,
> '()' for procedure header and procedure calling is mandatory.
...
> There will be no extra reserved name for functions, functions are defined
...
> Opinions?
Just a question: could you give some symbolic syntax representation?
E.g. Backus-Naur representation, "railroad diagram" or such?
This would make it easier to spot inconsistencies and collisions and such.
Martin Schreiber
<mse00000@gmail.com> 21 ноября 2013 г., 11:21
> > Hi,
> >
> > '()' for procedure header and procedure calling is mandatory.
> > "
> > procedure noparams();
> > begin
> > end;
> >
> > procedure test();
> > begin
> > noparams();
> > end;
> > "
>
> No, no, no...please!
> I know that you want to make a language more ortogonal but exceptions
> could exist! If you do not have parameters, why I need use this '()'?
>
In order to show that it is a subroutine call. In FPC it is sometimes
necessary anyway to distinguish address, value and call of procedure
variables. Can you elaborate in more detail why you don't want to write '()'?
>
> > There will be no extra reserved name for functions, functions are defined
> > by ':' TYPE. Return values are supplied by 'return' statement. A 'return'
> > statement before 'end;' is mandatory.
> > "
> > procedure func(a: bool8): int32;
> > begin
> > if a then
> > return 123;
> > end;
> > return 458;
> > end;
> > "
> >
> > Opinions?
>
> I agree that not needs to exist procedure and function keywords, but
> if one them will be excluded then "procedure" keyword is the best
> choice.
> The most languages uses "function" so why MSElang can't uses that keyword
> too?
>
Because a 'function' always returns a value. C resolves the problem by
the 'void' type, I don't like that approach. Oberon uses 'procedure' too.
Martin Schreiber
<mse00000@gmail.com> 21 ноября 2013 г., 11:25
>
> Just a question: could you give some symbolic syntax representation?
> E.g. Backus-Naur representation, "railroad diagram" or such?
> This would make it easier to spot inconsistencies and collisions and such.
>
Later when it has been settled down. I don't like to be pinned down or
impeached in this early stage.
Martin Schreiber
<mse00000@gmail.com> 21 ноября 2013 г., 11:31
> Returning NEW strings, dynarrays etc refcounted (automatically
> destroyable) types from function.
>
As usual I still don't understand.
"
procedure strfunc(): msestring;
begin
return 'The string result';
end;
procedure test;
var
s1: msestring;
begin
s1:= '"' + strfunc() + '"';
end;
Ivanko B
<ivankob4mse2@gmail.com> 21 ноября 2013 г., 11:41
If you do not have parameters, why I need use this '()'
=======================
So that visually not to mess them with variables, me guess
Ivanko B
<ivankob4mse2@gmail.com> 21 ноября 2013 г., 11:46
Oberon uses 'procedure' too.
=======================
Then better "sub[routine]" which means both "function" & "procedure"
Ivanko B
<ivankob4mse2@gmail.com> 21 ноября 2013 г., 11:56
Unneeded extra variables incl stack ones & stuff lines, smth like :
------------------------
procedure strfunc(): msestring;
begin
result:= 'The string result:'
if 1 <> 2 then
result:= result + 'mumu';
else
result:= result + 'koko';
end;
end;
We have 6 non-stuff lines & 7 body lines.
------------------
procedure strfunc(): msestring;
var
s: msestring;
begin
if 1 <> 2 then
st:= 'mumu';
else
s:= 'koko';
end;
return 'The string result:' + s;
end;
We have 7 non-stuff lines (+16%) & 9 body lines (+28%).
Martin Schreiber
<mse00000@gmail.com> Приложение 21 ноября 2013 г., 12:19
'sub' or 'subroutine' (see attachments)?
Ivanko B
<ivankob4mse2@gmail.com> 21 ноября 2013 г., 12:31
"Sub" since it's shorter
And how about removing "var" & "begin" in subroutibe defenitions ? Smth like :
---------------
sub test1(cosnt arg1: integer): bolean
v1: integer;
v1:= 1;
return arg1 = v1;
end;
--------------
but then how to be with nested "const", "type"etc ? Hmm...
Martin Schreiber
<mse00000@gmail.com> 21 ноября 2013 г., 12:32
> Unneeded extra variables incl stack ones & stuff lines, smth like :
> ------------------------
> procedure strfunc(): msestring;
> begin
> result:= 'The string result:'
> if 1 <> 2 then
> result:= result + 'mumu';
> else
> result:= result + 'koko';
> end;
> end;
>
I do not like the not clear definition of 'result', is it a 'var' or 'out'
variable? What happens here:
"
procedure strfunc(): msestring;
begin
if 1 <> 2 then
result:= result + 'mumu';
else
result:= result + 'koko';
end;
end;
"?
I think it is worth the additional two lines for the variable declaration. I
do not like much the terminating 'return' statement, but
"
sub strfunc(): msestring;
var
result: msestring;
begin
result:= 'The string result:'
if 1 <> 2 then
result:= result + 'mumu';
else
result:= result + 'koko';
end;
end:= result;
"
probably is too exotic.
Martin
Martin Schreiber
<mse00000@gmail.com> 21 ноября 2013 г., 12:43
I think a clear distinction between the different sections is good.
Ivanko B
<ivankob4mse2@gmail.com> 21 ноября 2013 г., 12:43
probably is too exotic.
==================
Some languages (BASH, TCL,..) return results of last assigmnent
'var' or 'out'
==================
looks like "var" with automanaged memory.
It's also possible to call setlength(result, <size>) etc dynarray-ing.
PS: pesronally me use the "result:=" approach intensilvey thus will
miss without the one.
Ivanko B
<ivankob4mse2@gmail.com> 21 ноября 2013 г., 12:49
It's also possible to define subroutines without keywords at all:
-----------------------------
type
class1 = class
f1: integer;
proc1();
fucn1(arg1: integer): bool;
end;
ipmplementation
class1.proc1();
begin
[..]
end;
class1.fucn1(arg1: integer): bool;
begin
[..]
end;
Martin Schreiber
<mse00000@gmail.com> Приложение 21 ноября 2013 г., 13:11
> It's also possible to define subroutines without keywords at all:
> -----------------------------
Has the advantage that the name is left-aligned (see attachment).
Michael Schnell
<mschnell@lumino.de> 21 ноября 2013 г., 14:03
> As usual I still don't understand.
> "
> procedure strfunc(): msestring;
> begin
> return 'The string result';
> end;
Slight Advantage of "Result":
procedure strfunc(x: Boolean): msestring;
begin
Result := 'The string result';
if x then
Result := 'Not The string result';
Result := '>>>' + Result + '<<<'
end;
Here you don't need to define a variable for the intermediate value.
Michael Schnell
<mschnell@lumino.de> 21 ноября 2013 г., 14:10
> No, no, no...please! I know that you want to make a language more
> ortogonal but exceptions could exist! If you do not have parameters,
> why I need use this '()'?
This introdices is a well known ambiguity in Delphi, that in fpc is
resolved (when certain compiler switches are set).
Using a procedure name without "()" can be either a call to this
procedure or denote the address of this procedure to be moved onto a
procedure variable.
(With fpc you need to add @ for the second, which I think is extremely
ugly.)
Martin Schreiber
<mse00000@gmail.com> 21 ноября 2013 г., 14:17
> Slight Advantage of "Result":
>
> procedure strfunc(x: Boolean): msestring;
> begin
> Result := 'The string result';
> if x then
> Result := 'Not The string result';
> Result := '>>>' + Result + '<<<'
> end;
>
> Here you don't need to define a variable for the intermediate value.
>
"
sub strfunc(x: boolean): msestring;
var
result: msestring;
begin
result:= 'The string result';
if x then
result:= 'Not The string result';
end;
result:= '>>>' + Result + '<<<';
end:= result;
"
I assume there is an implicit intermediate variable for string concatenation
or performance improvement anyway or the compiler can optimize away the
local 'result' variable.
Marcos Douglas
<md@delfire.net> 21 ноября 2013 г., 16:28
>> On Wed, Nov 20, 2013 at 1:01 PM, Martin Schreiber <mse00000@gmail.com>
>> > Hi,
>> >
>> > '()' for procedure header and procedure calling is mandatory.
>> > "
>> > procedure noparams();
>> > begin
>> > end;
>> >
>> > procedure test();
>> > begin
>> > noparams();
>> > end;
>> > "
>>
>> No, no, no...please!
>> I know that you want to make a language more ortogonal but exceptions
>> could exist! If you do not have parameters, why I need use this '()'?
>>
> In order to show that it is a subroutine call. In FPC it is sometimes
> necessary anyway to distinguish address, value and call of procedure
> variables. Can you elaborate in more detail why you don't want to write '()'?
Just style. For me is ugly to see a procedure call like Foo(). Sorry,
I don't have a logic reason to not use this.
>> > There will be no extra reserved name for functions, functions are defined
>> > by ':' TYPE. Return values are supplied by 'return' statement. A 'return'
>> > statement before 'end;' is mandatory.
>> > "
>> > procedure func(a: bool8): int32;
>> > begin
>> > if a then
>> > return 123;
>> > end;
>> > return 458;
>> > end;
>> > "
>> >
>> > Opinions?
>>
>> I agree that not needs to exist procedure and function keywords, but
>> if one them will be excluded then "procedure" keyword is the best
>> choice.
>> The most languages uses "function" so why MSElang can't uses that keyword
>> too?
>>
> Because a 'function' always returns a value. C resolves the problem by
> the 'void' type, I don't like that approach. Oberon uses 'procedure' too.
Maybe:
a) New sintaxe for "procedure":
function func(a: bool8);
begin
// do not need the return keyword
end;
b) New sintaxe for "function":
function func(a: bool8): int32;
begin
// do need the return keyword
return 123;
end;
PS: Do you will continue using "begin" for procedures/functions/methods?
Maybe you need to cut in these cases too.
Eg:
function func(a: bool8): int32;
return 123;
end;
Marcos Douglas
<md@delfire.net> 21 ноября 2013 г., 16:31
Worse, sorry.
Marcos Douglas
<md@delfire.net> 21 ноября 2013 г., 16:36
> "Sub" since it's shorter
So, use "func" that is short too, but have better name, IMHO.
- Показать цитируемый текст -
I don't think that remove "var", "const" is a good idea. Maybe it is
worse for the compiler performance too.
Marcos Douglas
<md@delfire.net> 21 ноября 2013 г., 16:38
WOW! Exotic too much and worse then use "result" variable.
Marcos Douglas
<md@delfire.net> 21 ноября 2013 г., 16:46
>> Slight Advantage of "Result":
>>
>> procedure strfunc(x: Boolean): msestring;
>> begin
>> Result := 'The string result';
>> if x then
>> Result := 'Not The string result';
>> Result := '>>>' + Result + '<<<'
>> end;
>>
>> Here you don't need to define a variable for the intermediate value.
>>
> "
> sub strfunc(x: boolean): msestring;
> var
> result: msestring;
> begin
> result:= 'The string result';
> if x then
> result:= 'Not The string result';
> end;
> result:= '>>>' + Result + '<<<';
> end:= result;
> "
> I assume there is an implicit intermediate variable for string concatenation
> or performance improvement anyway or the compiler can optimize away the
> local 'result' variable.
Please tell me you have not chosen the keyword "sub" for
procedures/functions.
Ivanko B
<ivankob4mse2@gmail.com> 21 ноября 2013 г., 17:03
For me is ugly to see a procedure call like Foo()
=====================================
For instance, TCL solves this problem by enclosing subroutine calls in
square braces :
proc get_res {param1 param2} {
return [expr $param1 * $param2]
}
set res [get_res 3 4]
And assigning from other variable :
set res 12345
set res_1 $res
PS:
BTW, accessing values of variables via a special sign ("$" mainly') is
excellent feature:
set res_var $input_var
Ivanko B
<ivankob4mse2@gmail.com> 21 ноября 2013 г., 17:05
Has the advantage that the name is left-aligned (see attachment).
========================
But seems unapproppriate for defining netsted subroutines ( looks like
calling them ).
Ivanko B
<ivankob4mse2@gmail.com> 21 ноября 2013 г., 17:12
PERL goes even furher - all variables are prefixed by "$" on both
sides of assigment, so "$" sign distinguishes variables and
subroutines so the latter don't need additional marking anymore
Marcos Douglas
<md@delfire.net> 21 ноября 2013 г., 17:23
We need to think why people will use MSElang instead of other language.
If we will use specifically things of others languages, is better to
use the real language, don't you think?
IMHO Martin need to think (MUCH) about it. If this project is just a
hobby that's Ok (for him) but if the propose of this project is to
catch much more programmers then he need to think a thousand times
before cut or add some features.
Martin Schreiber
<mse00000@gmail.com> 21 ноября 2013 г., 17:29
> a) New sintaxe for "procedure":
> function func(a: bool8);
> begin
> // do not need the return keyword
> end;
>
> b) New sintaxe for "function":
> function func(a: bool8): int32;
> begin
> // do need the return keyword
> return 123;
> end;
>
That was the proposal. Or
"
sub proc(a: bool8);
begin
end;
sub func(a: bool8): int32;
begin
end:= 123;
"
>
> PS: Do you will continue using "begin" for procedures/functions/methods?
> Maybe you need to cut in these cases too.
> Eg:
> function func(a: bool8): int32;
> return 123;
> end;
>
No, because it starts statements after 'type' 'const', 'var'.
"
sub test();
const
maxrange = 5;
type
subty = 0 to maxrange;
var
sr1: subty;
begin
sr1:= 1;
end;
"
Martin Schreiber
<mse00000@gmail.com> 21 ноября 2013 г., 17:29
> > sub strfunc(): msestring;
> > var
> > result: msestring;
> > begin
> > result:= 'The string result:'
> > if 1 <> 2 then
> > result:= result + 'mumu';
> > else
> > result:= result + 'koko';
> > end;
> > end:= result;
> > "
> > probably is too exotic.
>
> WOW! Exotic too much and worse then use "result" variable.
>
Why? It shows clearly that it is a write only variable which can not be read
and can't be forgotten to set.
Martin Schreiber
<mse00000@gmail.com> 21 ноября 2013 г., 17:32
> Please tell me you have not chosen the keyword "sub" for
> procedures/functions.
>
Why not? 'func' -> function which is the wrong term in case of a procedure
without result.
Martin Schreiber
<mse00000@gmail.com> 21 ноября 2013 г., 17:34
> PS:
> BTW, accessing values of variables via a special sign ("$" mainly') is
> excellent feature:
>
> set res_var $input_var
>
Why is this an excellent feature?
Martin Schreiber
<mse00000@gmail.com> 21 ноября 2013 г., 17:37
For me '$' *is* the additional marking. Grouping the parameter signature
by '(' ')' is better IMO.
Ivanko B
<ivankob4mse2@gmail.com> 21 ноября 2013 г., 17:44
No, because it starts statements after 'type' 'const', 'var'.
============================
But they (stack consts & types & subroutines) can be disabled in teh language.
Marcos Douglas
<md@delfire.net> 21 ноября 2013 г., 17:44
>> a) New sintaxe for "procedure":
>> function func(a: bool8);
>> begin
>> // do not need the return keyword
>> end;
>>
>> b) New sintaxe for "function":
>> function func(a: bool8): int32;
>> begin
>> // do need the return keyword
>> return 123;
>> end;
>>
> That was the proposal. Or
> "
> sub proc(a: bool8);
> begin
> end;
>
> sub func(a: bool8): int32;
> begin
> end:= 123;
> "
Yep. The only difference is I wrote "function" instead "sub".
>> Marcos Douglas
>>
>> PS: Do you will continue using "begin" for procedures/functions/methods?
>> Maybe you need to cut in these cases too.
>> Eg:
>> function func(a: bool8): int32;
>> return 123;
>> end;
>>
> No, because it starts statements after 'type' 'const', 'var'.
> "
> sub test();
> const
> maxrange = 5;
> type
> subty = 0 to maxrange;
> var
> sr1: subty;
> begin
> sr1:= 1;
> end;
> "
>
Yes, I saw this problem after.
Ivanko B
<ivankob4mse2@gmail.com> 21 ноября 2013 г., 17:47
>> set res_var $input_var
> Why is this an excellent feature?
Distinguishing between placeholders & L-values. Also well highlit in
syntax thus well readable.
Marcos Douglas
<md@delfire.net> 21 ноября 2013 г., 17:48
>> > sub strfunc(): msestring;
>> > var
>> > result: msestring;
>> > begin
>> > result:= 'The string result:'
>> > if 1 <> 2 then
>> > result:= result + 'mumu';
>> > else
>> > result:= result + 'koko';
>> > end;
>> > end:= result;
>> > "
>> > probably is too exotic.
>>
>> WOW! Exotic too much and worse then use "result" variable.
>>
> Why? It shows clearly that it is a write only variable which can not be read
> and can't be forgotten to set.
"end" is a reserved word, not a variable so it can't receive a value!
Better to use "return" or continue using "result", IMO.
Ivanko B
<ivankob4mse2@gmail.com> 21 ноября 2013 г., 17:49
Grouping the parameter signature by '(' ')' is better IMO.
=======
But it makes "()" for no params mandatory which looks a bit ugly for
PASCAL folk
Marcos Douglas
<md@delfire.net> 21 ноября 2013 г., 17:49
>> Please tell me you have not chosen the keyword "sub" for
>> procedures/functions.
>>
> Why not? 'func' -> function which is the wrong term in case of a procedure
> without result.
Who defined that a function HAVE to return a value ALWAYS? Where is
this rule?
Ivanko B
<ivankob4mse2@gmail.com> 21 ноября 2013 г., 18:22
And a procedere HAVE to NOT return a value ALWAYS
Marcos Douglas
<md@delfire.net> 21 ноября 2013 г., 18:38
> And a procedere HAVE to NOT return a value ALWAYS
>
Yes! Let's go create a new world! hehehe
Ivanko B
<ivankob4mse2@gmail.com> 21 ноября 2013 г., 18:55
This new world seems to be a forgotten old one - sub[routine]
Ivanko B
<ivankob4mse2@gmail.com> 21 ноября 2013 г., 18:58
As to "()" for no params... Why not to make them arbitrary ?
Me'd rather use them, though.
Marcos Douglas
<md@delfire.net> 21 ноября 2013 г., 19:14
> This new world seems to be a forgotten old one - sub[routine]
A forgotten old world called MS VisualBasic... =P
Martin Schreiber
<mse00000@gmail.com> 21 ноября 2013 г., 19:43
> >> WOW! Exotic too much and worse then use "result" variable.
> >
> > Why? It shows clearly that it is a write only variable which can not be
> > read and can't be forgotten to set.
>
> "end" is a reserved word, not a variable so it can't receive a value!
> Better to use "return" or continue using "result", IMO.
>
'end' here is the end of the procedure block with starts with a result type
definition:
"
sub func1(): int32;
begin
end:= 123;
"
which means assign the sub block with a value. Not that bad when the shock is
over.
Martin Schreiber
<mse00000@gmail.com> 21 ноября 2013 г., 19:49
It is necessary because of orthogonality anyway, clearly denotes the calling
of a subroutine and removes the mixup of address and call of procedure
variable values.
Martin Schreiber
<mse00000@gmail.com> 21 ноября 2013 г., 19:54
> > On Thursday 21 November 2013 12:46:55 Marcos Douglas wrote:
> >> Please tell me you have not chosen the keyword "sub" for
> >> procedures/functions.
> >
> > Why not? 'func' -> function which is the wrong term in case of a
> > procedure without result.
>
> Who defined that a function HAVE to return a value ALWAYS? Where is
> this rule?
>
http://en.wikipedia.org/wiki/Function_(mathematics)
Pupils probably learn about mathematical functions before or at the same time
as they learn programming.
Martin Schreiber
<mse00000@gmail.com> 21 ноября 2013 г., 19:58
> As to "()" for no params... Why not to make them arbitrary ?
> Me'd rather use them, though.
>
Because of the MSElang design goals
"
1. Simple.
Reduce the language concepts one has to learn to the minimum, make them as
orthogonal as possible.
Martin Schreiber
<mse00000@gmail.com> 21 ноября 2013 г., 20:09
> > This new world seems to be a forgotten old one - sub[routine]
>
> A forgotten old world called MS VisualBasic... =P
>
Older, my first commercial programming tool was a basic compiler for OS9 named
BASIC09
http://en.wikipedia.org/wiki/BASIC09
running on a MC6809 based very expensive euro card rack. Later I used
Omegasoft Pascal
http://www.pascal-central.com/omega.html
on MC6809 and MC68000.
Ivanko B
<ivankob4mse2@gmail.com> 21 ноября 2013 г., 20:12
>end:= 123;
>"
>which means assign the sub block with a value. Not that bad when the shock is
>over.
But it may be weird to prepare function code to this final asiigmnent
Martin Schreiber
<mse00000@gmail.com> 21 ноября 2013 г., 20:24
Example?
Marcos Douglas
<md@delfire.net> 21 ноября 2013 г., 20:22
>> >> WOW! Exotic too much and worse then use "result" variable.
>> >
>> > Why? It shows clearly that it is a write only variable which can not be
>> > read and can't be forgotten to set.
>>
>> "end" is a reserved word, not a variable so it can't receive a value!
>> Better to use "return" or continue using "result", IMO.
>>
> 'end' here is the end of the procedure block with starts with a result type
> definition:
> "
> sub func1(): int32;
> begin
> end:= 123;
> "
I did understand and I continue disagreeing.
> which means assign the sub block with a value. Not that bad when the shock is
> over.
I don't think so. :/
Marcos Douglas
<md@delfire.net> 21 ноября 2013 г., 20:26
+1
Very very weird.
Marcos Douglas
<md@delfire.net> 21 ноября 2013 г., 20:32
>> >> Please tell me you have not chosen the keyword "sub" for
>> >> procedures/functions.
>> >
>> > Why not? 'func' -> function which is the wrong term in case of a
>> > procedure without result.
>>
>> Who defined that a function HAVE to return a value ALWAYS? Where is
>> this rule?
>>
> http://en.wikipedia.org/wiki/Function_(mathematics)
> Pupils probably learn about mathematical functions before or at the same time
> as they learn programming.
Ok, this is a good point but I think doesn't matter in a language. If
is this so important then the most languages are wrong (Lua,
JavaScript, C, etc).
Ivanko B
<ivankob4mse2@gmail.com> 21 ноября 2013 г., 20:36
>Example?
Examle of successful realization of a regular (not 2*2) function with
such return ? Me can't event imagine how
Martin Schreiber
<mse00000@gmail.com> 21 ноября 2013 г., 20:51
> >> Who defined that a function HAVE to return a value ALWAYS? Where is
> >> this rule?
> >
> > http://en.wikipedia.org/wiki/Function_(mathematics)
> > Pupils probably learn about mathematical functions before or at the same
> > time as they learn programming.
>
> Ok, this is a good point but I think doesn't matter in a language. If
> is this so important then the most languages are wrong (Lua,
> JavaScript, C, etc).
>
MSElang is always right (the point 7. in design goals).
Martin Schreiber
<mse00000@gmail.com> 21 ноября 2013 г., 20:54
???
Write
"
sub SUBNAME(): RESULTTYPE;
var
result: RESULTTYPE;
begin
...
end:= result;
"
and work as before?
Ivanko B
<ivankob4mse2@gmail.com> 21 ноября 2013 г., 20:55
A working example of using RESULT varaiable :
------------------
function monthsstate(aperiodity: msestring): booleanarty;
begin
setlength(result,12);
if system.pos('Ja',aperiodity) > 0 then result[0]:=true else result[0]:=false;
if system.pos('F',aperiodity) > 0 then result[1]:=true else result[1]:=false;
if system.pos('Mr',aperiodity) > 0 then result[2]:=true else result[2]:=false;
if system.pos('Ap',aperiodity) > 0 then result[3]:=true else result[3]:=false;
if system.pos('My',aperiodity) > 0 then result[4]:=true else result[4]:=false;
if system.pos('Ju',aperiodity) > 0 then result[5]:=true else result[5]:=false;
if system.pos('Jl',aperiodity) > 0 then result[6]:=true else result[6]:=false;
if system.pos('Au',aperiodity) > 0 then result[7]:=true else result[7]:=false;
if system.pos('S',aperiodity) > 0 then result[8]:=true else
result[8]:=false;
if system.pos('O',aperiodity) > 0 then result[9]:=true else result[9]:=false;
if system.pos('N',aperiodity) > 0 then result[10]:=true else
result[10]:=false;
if system.pos('D',aperiodity) > 0 then result[11]:=true else
result[11]:=false;
end;
----------------
Defining a dunarray variable within a fucntion and then returning it
from the fuction looks strange since it's assumed that all (but
directly allocated in heap) internal variables in function are local
(stacked, destroyed on returning from fuction).
Ivanko B
<ivankob4mse2@gmail.com> 21 ноября 2013 г., 20:57
and work as before?
==================
[..]
"end:= sqrt(result*100000)%i1+pow(3,j)" too ?
Marcos Douglas
<md@delfire.net> 21 ноября 2013 г., 21:02
>> >> Who defined that a function HAVE to return a value ALWAYS? Where is
>> >> this rule?
>> >
>> > http://en.wikipedia.org/wiki/Function_(mathematics)
>> > Pupils probably learn about mathematical functions before or at the same
>> > time as they learn programming.
>>
>> Ok, this is a good point but I think doesn't matter in a language. If
>> is this so important then the most languages are wrong (Lua,
>> JavaScript, C, etc).
>>
> MSElang is always right (the point 7. in design goals).
HAHAHAHAHA... touché! =)
Marcos Douglas
<md@delfire.net> 21 ноября 2013 г., 21:03
>> >> But it may be weird to prepare function code to this final asiigmnent
>> >
>> >Example?
>>
>> Examle of successful realization of a regular (not 2*2) function with
>> such return ? Me can't event imagine how
>>
> ???
> Write
> "
> sub SUBNAME(): RESULTTYPE;
> var
> result: RESULTTYPE;
> begin
> ...
> end:= result;
> "
>
> and work as before?
Please, don't do that... the sintaxe "end:= result;" is very ugly!
Ivanko B
<ivankob4mse2@gmail.com> 21 ноября 2013 г., 21:11
>>But they (stack consts & types & subroutines) can be disabled in teh
> >language.
>>
>What do you want to say with this?
As in C/C++ which force all (but cycle vars) type & const & subroutine
declarations to be top-level.
Ivanko B
<ivankob4mse2@gmail.com> 21 ноября 2013 г., 21:16
the sintaxe "end:= result;" is very ugly!
=======================
No for everyone. It can even be expanded to pipes etc. Remember the
BASH syntax :
-----------------------
cat /tmp/fc-list.txt | egrep -v "^[ \t]*$" | awk \
-v OPT1=$SHORTPATHS \
-v OPT2=$AUTOSHORTGS \
-v OPT3=$PSF_ONLYALIASES \
-v OPT4=$TTF_ONLYALIASES 'BEGIN {
sans_n=0;
[.........]
for (i=1; i <= mono_styles_n; i++) {
MONO_TYPE=""
if ((( OPT3 != 1 ) && ((MONO_TYPES[i] == "PSF-") || (MONO_TYPES[i]
== "GSF-"))) || (( OPT4 != 1 ) && (MONO_TYPES[i] == "TTF-"))) {
MONO_TYPE=MONO_TYPES[i];
}
MONO_STYLE=MONO_STYLES[i];
if ( MONO_STYLE != "" ) {
gsub("-","",MONO_STYLE);
MONO_STYLE="-"MONO_STYLE;
}
gsub(" ","-",MONO[MONO1]);
print "/Mono"MONO_STYLE"\t/"MONO_TYPE""MONO[MONO1]""MONO_STYLES[i]"\t;"
>> "/tmp/Fontmap.GS-1";
print "/Fixed"MONO_STYLE"\t/"MONO_TYPE""MONO[MONO1]""MONO_STYLES[i]"\t;"
>> "/tmp/Fontmap.GS-1";
print "/Courier"MONO_STYLE"\t/"MONO_TYPE""MONO[MONO1]""MONO_STYLES[i]"\t;"
>> "/tmp/Fontmap.GS-1";
}
}' | sort -u > ./Fontmap.GS.xft
----------------------
))
Martin Schreiber
<mse00000@gmail.com> 21 ноября 2013 г., 21:18
sub monthsstate(aperiodity: msestring): booleanarty;
var
result: booleanarty;
begin
setlength(result,12);
result[0]:= system.pos('Ja',aperiodity) > 0;
result[1]:= system.pos('F',aperiodity) > 0;
result[2]:= system.pos('Mr',aperiodity) > 0;
result[3]:= system.pos('Ap',aperiodity) > 0;
result[4]:= system.pos('My',aperiodity) > 0;
result[5]:= system.pos('Ju',aperiodity) > 0;
result[6]:= system.pos('Jl',aperiodity) > 0;
result[7]:= system.pos('Au',aperiodity) > 0;
result[8]:= system.pos('S',aperiodity) > 0;
result[9]:= system.pos('O',aperiodity) > 0;
result[10]:= system.pos('N',aperiodity) > 0;
result[11]:= system.pos('D',aperiodity) > 0;
end:= result;
Martin Schreiber
<mse00000@gmail.com> 21 ноября 2013 г., 21:20
Yes. Don't forget the ';':
"
end:= sqrt(result*100000)%i1+pow(3,j);
Martin Schreiber
<mse00000@gmail.com> 21 ноября 2013 г., 21:27
> Please, don't do that... the sintaxe "end:= result;" is very ugly!
>
Alternatives?
Using implicit 'result' variable or 'FUNCTIONNAME' variable is bad because of
the unclear input/output state, a mandatory 'return' statement before 'end;'
is ugly too.
Ivanko B
<ivankob4mse2@gmail.com> 21 ноября 2013 г., 21:41
end:= result;
==================================
It means one more memory copying opetation which can be quite
expensive in case of large data (dynarrays,..).
Martin Schreiber
<mse00000@gmail.com> 21 ноября 2013 г., 22:16
Dynarrays are reference counted -> no problem, there will only a pointer be
copied. The compiler probably can optimize away the terminating assignment
and work with the var pointer directly. Or use a var or out parameter then
all is clear.
Marcos Douglas
<md@delfire.net> 21 ноября 2013 г., 22:39
>> Please, don't do that... the sintaxe "end:= result;" is very ugly!
>>
> Alternatives?
> Using implicit 'result' variable or 'FUNCTIONNAME' variable is bad because of
> the unclear input/output state, a mandatory 'return' statement before 'end;'
> is ugly too.
Why needs a 'return' statement only before 'end'?
Using 'return' this will be valid?
sub sum(a: int, b: int): int;
begin
if (a = 0) or (b = 0)
return 0
end;
return a+b;
end;
Why 'return' statement before 'end;' is ugly too?
Martin Schreiber
<mse00000@gmail.com> 21 ноября 2013 г., 23:05
wrote:
>
> Why needs a 'return' statement only before 'end'?
Not only, before end must be a return statement otherwise the return value is
undefined.
> Using 'return' this will be valid?
> sub sum(a: int, b: int): int;
> begin
> if (a = 0) or (b = 0)
> return 0
> end;
>
> return a+b;
> end;
>
Yes.
> Why 'return' statement before 'end;' is ugly too?
>
Your example shows it, the first 'return' is an independent statement, the
second is glued to 'end'. The thought is, if it is glued to end, why not make
it right and show the glue by the ':=' operator?
Marcos Douglas
<md@delfire.net> 22 ноября 2013 г., 0:02
> wrote:
>>
>> Why needs a 'return' statement only before 'end'?
>
> Not only, before end must be a return statement otherwise the return value is
> undefined.
>
>> Using 'return' this will be valid?
>> sub sum(a: int, b: int): int;
>> begin
>> if (a = 0) or (b = 0)
>> return 0
>> end;
>>
>> return a+b;
>> end;
>>
> Yes.
>
>> Why 'return' statement before 'end;' is ugly too?
>>
>
> Your example shows it, the first 'return' is an independent statement, the
> second is glued to 'end'. The thought is, if it is glued to end, why not make
> it right and show the glue by the ':=' operator?
Show the glue by the ':=' operator assigning a value to the 'end'
keyword? It doesn't make any sense for me, sorry.
IMHO, this is the only error that you are making until now. The 'sub'
keyword is just ugly, not an error.
Ivanko B
<ivankob4mse2@gmail.com> 22 ноября 2013 г., 0:24
The 'sub' keyword is just ugly, not an error.
=====================
Feels less ugly than "function" for non-returning & "procedure" for returning
Show the glue by the ':=' operator assigning a value to the 'end'
keyword? It doesn't make any sense for me, sorry.
=====================
To put assigned ["result"] variable to refcounting ?
Sieghard
<s_c_h_s@arcor.de> 22 ноября 2013 г., 2:50
> Using a procedure name without "()" can be either a call to this
> procedure or denote the address of this procedure to be moved onto a
> procedure variable.
It will be what was defined for it to be.
> (With fpc you need to add @ for the second, which I think is extremely
> ugly.)
But it is thoroughly consistent with the use of "@" with variables, where
it returns their address as well.
This makes the C approach (above) look inconsistent.
Sieghard
<s_c_h_s@arcor.de> 22 ноября 2013 г., 2:34
> We need to think why people will use MSElang instead of other language.
> If we will use specifically things of others languages, is better to
> use the real language, don't you think?
If this will go on some further, no further thinking might be neccessary,
as the improbable result will not be usable anyway.
There's not been a single instant of a systematic definition of any of the
"planned" syntax elements yet, so it's impossible to judge the viability of
the proposals.
Sieghard
<s_c_h_s@arcor.de> 22 ноября 2013 г., 2:51
> > Just a question: could you give some symbolic syntax representation?
..
> Later when it has been settled down. I don't like to be pinned down or
> impeached in this early stage.
You'll probabely regret it. Ok, your choice.
Sieghard
<s_c_h_s@arcor.de> 22 ноября 2013 г., 2:36
> Who defined that a function HAVE to return a value ALWAYS? Where is
> this rule?
Mathematics.
Sieghard
<s_c_h_s@arcor.de> 22 ноября 2013 г., 2:23
> > procedure strfunc(): msestring;
...
> > result:= result + 'koko';
> I do not like the not clear definition of 'result', is it a 'var' or
> 'out' variable? What happens here:
It could be considered an "automatic" local variable of the function return
type used to hold the function result.
> I think it is worth the additional two lines for the variable
> declaration. I do not like much the terminating 'return' statement, but
...
> end:= result;
> "
> probably is too exotic.
THen, what about using the function name as a pseudo variable to pass out
the resukt value?
(Oops - that's exactly what original Pascal did...)
Ivanko B
<ivankob4mse2@gmail.com> 22 ноября 2013 г., 10:03
end:= sqrt(result*100000)%i1+pow(3,j);
=====================
Since 3 local variables are engaged here thus just rewritting data
pointer of a single variable etc tricks are not enough then it's
definetely impossible w/o memory copying at final.
Ivanko B
<ivankob4mse2@gmail.com> 22 ноября 2013 г., 10:07
Also, we don't know what ( "var" or "out" ) is current state "result".
What will locally defined "result" variable (to assign from in
"end:=") be ? What's the difference between these "result"-s ?
debi12345 писал(а):"IF.. THEN ..;" & "IF ..THEN BEGIN .. END;" => "IF .. THEN .. END;"
На мой взгляд всякие там удобства, типа исключение begin и т.п. лучше вообще не делать, а если и делать, то опционально,
Сейчас уклон обсуждения ушел в какие-то дебри в области мелких якобы вкусностей
а по типу переменной
alexey38 писал(а): Пусть переходят на нормальные редакторы кода, или пишут свои, где можно автоматом скрывать begin-ы и т.п.
alexey38 писал(а): Если любой код будет несовместим, то у языка не будет будущего.
Лекс Айрин писал(а):Mikhail, Не всегда соблюдается принцип KISS.
Лекс Айрин писал(а):Mikhail, да взять ту же ";". Где ее надо ставить, где не надо... Причем, даже редактор подставляет ошибочный вариант. Постоянно приходится стирать.
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 2