Author Topic: Unleashed Pascal (async/await, parallel for, match, string interpolation & more)  (Read 70366 times)

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 13052
  • FPC developer.
Actually, the loop variable should _always_ be "for" local. 

So design a new language and do it that way. Don't pester existing languages to become incompatible.

n7800

  • Hero Member
  • *****
  • Posts: 811
  • Lazarus IDE contributor
    • GitLab profile
The variable's value is also undefined if the loop was not executed at all: "for i := 0 to -1 do".

440bx

  • Hero Member
  • *****
  • Posts: 6628
So design a new language and do it that way. Don't pester existing languages to become incompatible.
There is no need for a new language.  A simple modeswitch that corrects existing flaws is all that is needed.

A computer language isn't supposed to be a frozen in time museum piece, it's supposed to improve with time. 

I still vaguely remember all the weird stuff that is now long gone in H&S C.  Ansi C 99 alone scrubbed away a bunch of junk in C.   There are many improvements that are long overdue in Pascal.  Not to mention that the way the "for" loop variable is treated in Pascal is a language flaw that is long overdue to be repaired.



The variable's value is also undefined if the loop was not executed at all: "for i := 0 to -1 do".
As it should be and is made clear if the loop index exists only in the "for" loop.  It couldn't possibly have a value since it does not exist outside the "for". 

OTH, if "i" is function global then it should have the initial value (0 in this case) because the statement was only _partially_ executed (one could say that the "for" was broken out of immediately after assigning 0 to "i".)  IOW, the part "i := 0" _must_ have been executed for the loop itself not to execute.

FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12820
  • Debugger - SynEdit - and more
    • wiki
A computer language isn't supposed to be a frozen in time museum piece, it's supposed to improve with time. 

True, but... much too often a feature request goes lets add "this or that", and lets add it as unrestricted and unlimited as possible. So everyone can decide to their taste how to use it.

Sounds fair at first...

But, if I had only written code in languages following that concept, I would not be half as capable as I am today.
Because a language forces me to use certain patterns, follow rules, ... because of that I have to do more thinking what I really try to do, and what I actually need to put into code.

And yes, I have used "can do all" languages. Usually when I need a throw away script, and I just want the result once, and then its gone. And I also made the mistake to use such a language for non-throw away, and I paid a bitter and hefty price.

So, get your features everyone that wants them. But if you are smart, don't implement them for the most impact in 5 minutes of using them (its just 5 minutes of fame). Consider how they will in the overall mix of all features impact the quality of the code.


marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 13052
  • FPC developer.
So design a new language and do it that way. Don't pester existing languages to become incompatible.
There is no need for a new language.  A simple modeswitch that corrects existing flaws is all that is needed.

A computer language isn't supposed to be a frozen in time museum piece, it's supposed to improve with time. 

That values subjective "improve" over objective "compatibility".

440bx

  • Hero Member
  • *****
  • Posts: 6628
Consider how they will in the overall mix of all features impact the quality of the code.
That's exactly what I have been emphasizing all along.

For instance,

There are solid, logical reasons why the "for" loop index should exist only in the context/scope of the "for" itself and never use a variable that is function global (see explanation in a previous post above.)

I am not proposing anything that remotely resembles a "do all" language.  What I "propose" is a language that, whatever it does, it does it RIGHT, instead of half *ssed, e.g, inline variables that are not scope bound,  allowing inline variables to be defined just about anywhere, allowing only scope bound variables instead of allowing scope bound variables, constants and types.  Those are the elements that enable the creation of highly localized and modular code.   

I propose a language that doesn't use the most obtuse (and illogical) way ever of defining bit fields ever hallucinated and, in addition to that, is full of bugs.

A language that allows the programmer to align records and record fields as necessary (good luck if you're using FPC and need an alignment that is not on a 2, 4 or 8 byte boundary.)

Even COBOL has unnamed unions... COBOL of all things... late 1950s technology.  Pascal ?... nope... do we want that in FPC.. definitely not, how dare you suggest including that in Pascal... terrible!!  and on and on and on, ad nauseam.

In addition to the above, if a scope exists then there should be a way to exit the scope.  That's why "exit" and "break" exist.  It's not like this is new.   Why should the inline variables be scoped ???  simple!!!! N. Wirth figured it out roughly 50 years ago, that's why he separated the type, const and var declarations from the code.  That's the reason there should be individually defined scopes (instead of inline variables everywhere) so they are grouped at the top of the scope along with other things such as consts and types that only apply to a few statements.   

What I am proposing is nothing new, it's just CONSISTENT, symmetrical, predictable and rule based.  Oh no... we can't have that.   Let's complain and make stuff up that what I want is a "do all" language.  No, it's a _do it right_ language and, have the features a language needs to successfully compete with C and C++.

It's amazing that deficient constructions are replicated time and again because since that's how they've been done before, they must be right.   



That values subjective "improve" over objective "compatibility".
Should cars be compatible with the Model T ?  I don't think so. 

I don't have anything against reasonable compatibility but there are limits.

An obvious and simple improvement is allowing the initialization of groups of variables. It's simple, it's trivial, it's obvious, it's convenient, it makes sense but... oh no!!!! design your own language... etc, etc instead of welcoming an obvious and simple improvement.

add a "static" (or some other _logical_, reasonable, semantically sensible) keyword to define persistent local variables... no, we can't do that because we already have "writable constants"... "writable constants", I don't think I've seen anything in any other programming language that is as ridiculous and embarrassing as Pascal's "writable constants".   Let's not create a better way of defining such variables because of "backward compatibility", "micromanagement", "we already have something that does it" (no matter ridiculous it is.) 

I would call that an improvement.  The above isn't subjective, it's a fully described situation with it's problem(s) and possible solution along with why it isn't yet done but, go ahead claim that my use of the word "improvement" is subjective.



oh well...
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12820
  • Debugger - SynEdit - and more
    • wiki
There are solid, logical reasons why the "for" loop index should exist only in the context/scope of the "for" itself and never use a variable that is function global (see explanation in a previous post above.)

But there existing is code that actually uses the counter variable outside the scope of the loop.

There is the documented "break" behaviour.

And there is
Code: Pascal  [Select][+][-]
  1. procedure foo;
  2. var loop_counter;
  3.   procedure bar;
  4.   begin
  5.     if loop_counter > 10 then whatever;
  6.   end;
  7. begin
  8.   for loop_counter := 1 to 100 do begin
  9.     bar;
  10.   end;
  11. end;


Also, from you "above" post
Code: Pascal  [Select][+][-]
  1. loses its value

value and scope are not the same, never been.

Very often the scope starts long before there is a value.

And loop counters are not the only values lost before the end of scope iirc. Wasn't there the ever lasting complaint that unlike Delphi an interface used as ref counter could be released before the end of scope? At least it had a diff life time (for the value) than in Delphi, and that did cause issues for some people.
(Yes I am aware depending on viewpoint, that can be answered with 2 wrongs don't make a right... depending on view point)

But if it is an issue, why is it chosen that the issue should be the scope being to wide? It could also be made the issue being that the value is not kept. There are plenty of other cases where a variable is only used in part of its scope (and that applies also in languages that have finer scoping abilities, so that isn't solved by adding finer scoping)




But all be as it is. inline vars are unlikely to hurt someone. So I am happy for everyone who can now enjoy them.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 13052
  • FPC developer.
There are solid, logical reasons why the "for" loop index should exist only in the context/scope of the "for" itself and never use a variable that is function global (see explanation in a previous post above.)

Not really. You can e.g. omit a warning after DFA. There is no need to solve it in syntax.

Quote
I propose a language that doesn't use the most obtuse (and illogical) way ever of defining bit fields ever hallucinated and, in addition to that, is full of bugs.

Not every compiler bug warrants new syntax. New syntax is the bureaucrat's solution: define it as illegal, and the problem will go away.

Unfortunately the world doesn't work that way.

Quote
Even COBOL has unnamed unions... COBOL of all things... late 1950s technology.  Pascal ?... nope... do we want that in FPC.. definitely not, how dare you suggest including that in Pascal... terrible!!  and on and on and on, ad nauseam.

Pascal in this sense was a precursor to "safe" languages. Turbo Pascal and derivatives less so.    As in many of these cases, I agree with you. For a new language.

But for an existing language that would mean splitting union in a higher level "safe" type, and lower level type that allows to map to memory. But as so often, having umpteen versions of each possible imaginary feature only makes the language unwieldy and unmaintainable.

Quote
In addition to the above, if a scope exists then there should be a way to exit the scope.  That's why "exit" and "break" exist.  It's not like this is new. Why should the inline variables be scoped ??? 

Totally false analogy, as evident that one decision is runtime, and the other compiletime.

Quote
What I am proposing is nothing new, it's just CONSISTENT, symmetrical, predictable and rule based.  Oh no... we can't have that.   Let's complain and make stuff up that what I want is a "do all" language.  No, it's a _do it right_ language and, have the features a language needs to successfully compete with C and C++.

No it is not. It is flinging random arguments in the hope that something sticks. Even C and C++ don't guarantee that the scope of a variable (and its removal from the stack) is equal to its declaration.

So if they don't, why would we have to go backwards and implement that 1970s concept to keep the compiler save some memory ?

Quote
That values subjective "improve" over objective "compatibility".
Should cars be compatible with the Model T ?  I don't think so. 

That's the whole point. If you feel strongly, go out and define a new model, call it "Tesla" if you want to imply some pedigree with Model T  >:D

Don't try to confuse models by a Model T mark II, III till MCMLVXII. That only confuses what Model T means.

Quote
I don't have anything against reasonable compatibility but there are limits.

That's because you have decided to revolve the whole universe around a few minor bugs and imaginary features. Probably nobody feels as strong about them as you do.

Quote
An obvious and simple improvement is allowing the initialization of groups of variables. It's simple, it's trivial, it's obvious, it's convenient, it makes sense but... oh no!!!! design your own language... etc, etc instead of welcoming an obvious and simple improvement.

I could write something here, but it happens that I already wrote down my opinion about minor syntax "features" long ago: https://www.freepascal.org/faq.html#extensionselect

LemonParty

  • Hero Member
  • *****
  • Posts: 708
I know that "writable constants" is kind of absurd. But I think this is a feature that we can reuse space allocated for constants.

When program requests the memory pages it gives an restriction if this pages can be readable, writable or executable. So writable constants are marked as writable, so we can reuse this space after. If we do a fully unwritable constants it means that there will be "dead" chunks of program that will bloat the space until program dies.
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

440bx

  • Hero Member
  • *****
  • Posts: 6628
The point is very simple: the fact that some deficient and ill conceived construct may be coerced into getting something done correctly is not a valid reason to implement the correct solution.

That goes for the 3 posts above this one.
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

creaothceann

  • Sr. Member
  • ****
  • Posts: 481
As for inline variables they violate the fundamental rules of pascal programming. Things should be declared and arranged in an orderly manner not declared haphazardly at random spots in the code
That's exactly why throw-away variables like loop counters, whose values can't be used after the loop anyway, should be declared in the loop.


Maybe the problem Fibonacci is trying to solve (variables being declared too far away from where they are used) could be mitigated by having smaller procedures or using nested procedures and having fewer variables in the main part of procedure
More work for no benefit. And screens have a limited number of lines anyway, no need to take up more of them with function headers, footers, and blank lines.


Also before you delve into that routine lame argument about oh it’s only because early computers ONLY had UPPERCASE keys. Why didn’t early computers have lowercase keys if they are so amazing?
Because early computing was extremely memory-constrained, every single bit counted. Memory was stored in expensive core memory, slow punched tape and magnetic tape, on cathode-ray tubes, magnetic drums, delay lines, dynamic RAM. In 1970, 1MB of core memory would've cost $734,003.
Computer manufacturers developed their own 6-bit character codes, until ASCII came along as a 7-bit code. Storing the first two digits of a year often wasn't important enough to justify the cost. Compilers were running in separate passes simply because that's what fit into the available memory.
« Last Edit: March 20, 2026, 07:49:46 am by creaothceann »

440bx

  • Hero Member
  • *****
  • Posts: 6628
As for inline variables they violate the fundamental rules of pascal programming. Things should be declared and arranged in an orderly manner not declared haphazardly at random spots in the code
That's exactly why throw-away variables like loop counters, whose values can't be used after the loop anyway, should be declared in the loop.
It is so nice to see that at least one person understands the obvious. :)
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

Zvoni

  • Hero Member
  • *****
  • Posts: 3603
Do you mean this, @Zvoni and @Martin_fr?

Code: Pascal  [Select][+][-]
  1. var i := 2;
  2.  
  3. case true of
  4.   (i = 1): writeln('i eq 1');
  5.   (i = 2): writeln('i eq 2'); // execute
  6.   (i > 0): writeln('i gt 0'); // should NOT execute
  7.   (i = 3): writeln('i eq 3');
  8.   (i = 4): writeln('i eq 4');
  9.   else writeln('bar');
  10. end;

EDIT: I forgot: in Visual Basic it's possible to use multiple Boolean-Expressions inside a Case-label
Code: [Select]
Dim i As Long
    Select Case True
        Case i = 0
            Debug.Print "i equals zero"
        Case i > 100 And User="Zvoni"  //<-- THIS ONE
            Debug.Print "i is greater than 100 and the User=Zvoni"
        Case i < -50 Or User="Laura"   //<-- THIS ONE
            Debug.Print "i is smaller than -5 or the User=Laura"
        Case Else
            Debug.Print "Doh!"
    End Select
Now imagine the usecase of this feature

Like this?

Code: Pascal  [Select][+][-]
  1. var i := 2;
  2. var s := 'hi';
  3.  
  4. case true of
  5.   (i = 1): writeln('i eq 1');
  6.   (i = 2) and (s = 'hi'): writeln('i eq 2 and s eq "hi"'); // execute
  7.   (i = 123) or (s = 'hi'): writeln('i eq "123" or s eq "hi"'); // should NOT execute
  8.   (i = 3): writeln('i eq 3');
  9. else
  10.   writeln('no match');
  11. end;

Is this okay for the "case" keyword?
Correct.
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Zvoni

  • Hero Member
  • *****
  • Posts: 3603
As Aircode in Pascal it would look like this
Code: Pascal  [Select][+][-]
  1. Var i:Integer; //or whatever other Datatype
  2. //......
  3.   Case True Of
  4.     i=0    : Writeln('i equals zero');
  5.     i>100 : Writeln('i is greater than 100');
  6.     i<-50 : Writeln('i is smaller than -50');
  7.     Else Writeln('Doh!');
  8.   End;

Free Pascal already allows some things:

Code: Pascal  [Select][+][-]
  1. case i of
  2.   0..5      : writeln('0-5');
  3.   7         : writeln('7');;
  4.   6, 8..9   : writeln('6, 8, 9');
  5.   10..MaxInt: writeln('greater than 9');
  6.   else        writeln('negative');
  7. end;

Your example doesn't look very good, but still:

Code: Pascal  [Select][+][-]
  1. case i of
  2.   0              : Writeln('i equals zero');
  3.   101..MaxInt    : Writeln('i is greater than 100');
  4.   -MaxInt-1..-51 : Writeln('i is smaller than -50');
  5.   else             Writeln('Doh!');
  6. end;
  7. end;

To obtain boundary values, you can use certain constants ("MaxInt"), the functions ("high(i)" or "high(integer)"), type helpers ("i.MaxValue"), and so on.
Yes. I know about Ranges and the comma (which equates to an "Or")

It's more to do with, that with a "Case True Of" you are setting the Result the expressions in the labels have to meet, instead of providing a value, then checking if any comparison returns True

in vb/vba you can even mix DataTypes within a Case-block
Code: Pascal  [Select][+][-]
  1. Case True Of
  2.    (i=5) : Writeln('i=5');
  3.    (s='Zvoni') : Writeln('User=Zvoni');
  4. //....
  5. End;
So basically, you can throw any Datatype at the same Case..Of at it

The "mechanism" stays the same: First "Hit" is executed, rest is ignored (since no Fallthrough).
And with a FallThrough-Mechanism you could even execute both branches, provided you are looking for that (e.g. passing both variables i and s to the Case.of
« Last Edit: March 20, 2026, 08:28:40 am by Zvoni »
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Fibonacci

  • Hero Member
  • *****
  • Posts: 1125
  • Behold, I bring salvation - Unleashed Pascal
    • fibo.gg
Correct.

Can do. IMO "case true/false of" already signals that labels are expressions, not constants - the user consciously writes a boolean literal instead of a variable, so there's no semantic trap. I'd rather not introduce a new keyword for this. Each label would be a full boolean expression, e.g.

Code: Pascal  [Select][+][-]
  1. case true of
  2.   ((i = 4) and (s = 'whatever')) or (s = 'something else'): ...
  3.  

As for fallthrough - I want to get this right before implementing, so I'd rather gather opinions and reasoning upfront than change it later. One option: fallthrough is the default (all matching labels execute), and "break" stops it early. Should it work this way, or should it match only the first hit?

Code: Pascal  [Select][+][-]
  1. var i := 4;
  2. var s := 'whatever';
  3.  
  4. case true of
  5.   ((i = 4) and (s = 'whatever')) or (s = 'something else'):       writeln('match 1');
  6.   ((i = 4) and (s = 'whatever')) or (s = 'something else'): begin writeln('match 2'); break; end;
  7.   ((i = 4) and (s = 'whatever')) or (s = 'something else'):       writeln('match 3');
  8.   else writeln('no match');
  9. end;

Would ouput:

Code: Text  [Select][+][-]
  1. match 1
  2. match 2
Unleashed Pascal: async/await, parallel for, match, tuples, string interpolation, inline vars, autofree, no-RTTI & tons more. Star on GitHub ⭐

 

TinyPortal © 2005-2018