News for hackers. Stuff that matters.
Re:Why Use Pascal? by zabzonk on Saturday July 08, 2023 @05:37PM (#36649019)
> Begin End vs { } doesn't really bother me.

but they don't really mean the same thing - {} defines a local scope, begin...end doesn't.

Re:Why Use Pascal? by oaiey on Saturday July 08, 2023 @06:11PM (#36649299)
Depends a lot on the language does not it?
Re:Why Use Pascal? by zabzonk on Saturday July 08, 2023 @06:16PM (#36649332)
we are talking about pascal
Re:Why Use Pascal? by johannes1234321 on Saturday July 08, 2023 @08:05PM (#36650013)
About pas Al in comparison to languages using {} for blocks, where some have block scoping and some don't.
Re:Why Use Pascal? by zabzonk on Saturday July 08, 2023 @09:02PM (#36650369)
no idea what you are talking about here - what is "pas Al" - post an example of what you mean.
Re:Why Use Pascal? by saladdressing on Saturday July 08, 2023 @11:34PM (#36651253)
Pascal. It’s a typo.
Re:Why Use Pascal? by nurettin on Saturday July 08, 2023 @09:05PM (#36650395)
you are probably talking about C++ vs pascal. But you should be talking C.
Re:Why Use Pascal? by zabzonk on Saturday July 08, 2023 @09:08PM (#36650416)
no, c and c++ have basically similar rules for the scope of variables, with the regard to braces
Re:Why Use Pascal? by nurettin on Sunday July 09, 2023 @06:12AM (#36653187)
I don't think you know much about pascal, C or C++
Re:Why Use Pascal? by hnlmorg on Saturday July 08, 2023 @07:25PM (#36649779)
They are both used to define blocks. Eg Begin … End in for loops https://wiki.freepascal.org/For

From what I recall, Pascal doesn’t support variables scoped within a specific block. But then neither do some languages with C-style curly braces too.

So {} and Begin…End are pretty much the same thing.

BASIC (and Visual Basic especially) often get a lot of criticism for their syntax but the End Thing style block terminator was very clear.

It’s a pity that the only popular alternative to C-style braces is Python because I do think ALGOL-style syntax has a lot more going for it than people give it credit.

Re:Why Use Pascal? by zabzonk on Saturday July 08, 2023 @08:57PM (#36650336)
i do not think you understand the concept of scope.
Re:Why Use Pascal? by ipcress_file on Saturday July 08, 2023 @10:11PM (#36650835)
Would you explain it? I'm self taught, have programmed in Python, C, and am looking at Pascal, and I don't understand the difference.
Re:Why Use Pascal? by xupybd on Saturday July 08, 2023 @10:52PM (#36651045)
Perhaps you're being a little short here? Explaining what you mean would go a long way to fostering good will.
Re:Why Use Pascal? by countrymile on Sunday July 09, 2023 @02:07AM (#36652014)
More of these replies on HN please!
Re:Why Use Pascal? by hnlmorg on Sunday July 09, 2023 @02:21AM (#36652091)
I’ve written a few compilers in my time so I have some idea about scoping rules ;)

As I and other have already said, it depends on the specific language. Some languages scope local variables at the function level (irrespective of {} or Begin End), and other languages scope local variables inside the containing {} or Begin and End block.

In that regard {} and Begin End serve identical purposes of defining a local execution block and then it’s up to the language or dialect, or sometimes even the compiler authors, to decide upon the rules of variable scoping.

What you’re doing here is conflating syntax grammar with deeper rules about a languages compiler or specification.

To come back to your original point, Delphi does support variable scoping inside Begin End blocks. I don’t know if FreePascal also does but older dialects of Pascal didn’t because of the original intent of Pascal being a single pass compiler. Equally, not all languages that have C-like curly braces support variable scoping in the way you’re trying to describe. JavaScript originally didn’t and had to create a whole new keyword to add it (a little like what Delphi did, funny enough). My own shell scripting language very intentionally doesn’t support scoping despite having curly braces.

As for inlining other contexts like functions, classes, etc, it has been a while since I’ve written any Pascal so I can’t recall the nesting rules here. But like with our discussion about variables, it’s more a question of whether the specification and/or compiler has support rather than a quirk of the Begin End grammar that forbids it — just as is the case with {} too.

Re:Why Use Pascal? by zabzonk on Sunday July 09, 2023 @04:55AM (#36652849)
this post is specifically about pascal - my comment about {} vs begin...end was intended for that context. pascal has no way of defining variables within a local scope - it was added to delphi as a kludge much later. i admit i should have said something like "... {} in C and C++".
Re:Why Use Pascal? by hnlmorg on Sunday July 09, 2023 @05:43AM (#36653056)
> this post is specifically about pascal - my comment about {} vs begin...end was intended for that context

That link was Pascal. It was just one of many dialects of Pascal.

> pascal has no way of defining variables within a local scope

I just did a quick search and turns out Pascal does support nesting variable scopes too.

> it was added to delphi as a kludge much later

Is it a kludge though? Or are you just calling it that because it disproves your point? The syntax is pretty similar to a lot of C-like languages. So you’d be calling their variable declarations a kludge too.

It feels like you’re being overly dismissive.

> i admit i should have said something like "... {} in C and C++".

it certainly would have helped your case to have opened with a little more context rather than assuming other people don’t understand how scoping works ;)

But even that aside, Pascal does support scoping inside compound statements.

Begin End and {} are just tokens to denote the start and end of a compound statement. Just like how Python uses indentation to group compounds.

Everything else you put is missing the point about how language grammar is parsed.

Re:Why Use Pascal? by Lerc on Sunday July 09, 2023 @07:37AM (#36653643)
Well the good thing about this thread is that I found out that Pascal has grown inline vars since I last used it. With type inference too by the looks of it.

Maybe I will make my way back after all.

Re:Why Use Pascal? by olavfosse on Sunday July 09, 2023 @06:04PM (#36659425)
> As I and other have already said, it depends on the specific language. Some languages scope local variables at the function level (irrespective of {} or Begin End), and other languages scope local variables inside the containing {} or Begin and End block.

And some languages do either, depending on the keyword used to declare a variable. Looking at you JavaScript(var vs let).

Re:Why Use Pascal? by noobermin on Sunday July 09, 2023 @03:07AM (#36652310)
The most C-style language is C and it does have variables scoped to a block, I believe. The same for C++.
Re:Why Use Pascal? by hnlmorg on Sunday July 09, 2023 @04:19AM (#36652661)
I was using “C-style” with respect to {} syntax for compound statements rather than language specification because the GP is discussing language grammar.
Re:Why Use Pascal? by clouddrover on Saturday July 08, 2023 @10:49PM (#36651029)
Re:Why Use Pascal? by beached_whale on Saturday July 08, 2023 @11:30PM (#36651230)
without that, one can use a repeat until loop to simulate I think