Recent

Author Topic: how to break out early of a case ?  (Read 44085 times)

MarkMLl

  • Hero Member
  • *****
  • Posts: 3670
Re: how to break out early of a case ?
« Reply #165 on: December 07, 2021, 11:50:16 am »
Why? ALGOL-60 was an important development at the time and the language was of major influence to later languages. But it also stems from a time when system resources were very limited. So that the then developers chose to allow the IF-statement in expressions came from necessity rather than elegance. Later language developers were wise to drop the construct. Why that would be embarrassing is beyond me.

Because the immediate parent of Pascal was ALGOL W, which was a refinement by Wirth of ALGOL-60 incorporating ideas by Hoare. There is no rational reason why the if-then-else expression format was omitted, but as I've said before I suspect it was a casualty of the fact that Pascal was basically a "rush job".

The omission is embarrassing since it makes C etc. look like a more comprehensive implementation of the ALGOL concepts, and inconvenient since it makes semi-mechanical conversion of code snippets in the majority of popular languages to Pascal more difficult.

It is definitely not accurate to characterise ALGOL as a language for resource-constrained systems, since some of them had virtual memory etc. that later architectures lacked for decades. If anything, the comparatively rapid implementation of Pascal on the UCSD p-system and on CP/M systems argues the opposite. In any case, I fail to see how implementation of the if-then-else expression form favours one particular scale of system over some other.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

PascalDragon

  • Hero Member
  • *****
  • Posts: 3646
  • Compiler Developer
Re: how to break out early of a case ?
« Reply #166 on: December 07, 2021, 01:23:04 pm »
However after refactoring a bit of code today where the number of bits needed to represent something was an issue, I find myself wondering whether some other potential cases could be avoided by having something like Log2SizeOf() as an operation which could be resolved at compilation time.

Once we have support for compile time functions (the current term for them is “pure functions”) you can add that yourself ;)

MarkMLl

  • Hero Member
  • *****
  • Posts: 3670
Re: how to break out early of a case ?
« Reply #167 on: December 07, 2021, 01:53:23 pm »
Once we have support for compile time functions (the current term for them is “pure functions”) you can add that yourself ;)

:-) OTOH I'd suggest that that specific case might be worth examining whenever anybody complains that his desired initialisation can't be coded... I'm not suggesting that some implementation be added prematurely, only that it might turn out to be a common "pattern".

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

PascalDragon

  • Hero Member
  • *****
  • Posts: 3646
  • Compiler Developer
Re: how to break out early of a case ?
« Reply #168 on: December 07, 2021, 02:05:45 pm »
Once we have support for compile time functions (the current term for them is “pure functions”) you can add that yourself ;)

:-) OTOH I'd suggest that that specific case might be worth examining whenever anybody complains that his desired initialisation can't be coded... I'm not suggesting that some implementation be added prematurely, only that it might turn out to be a common "pattern".

No, it's not worth examining, because then the next one will come with the next function and so on. Better focus this into a more general approach.

Also if all you need is the size in bits then you can always use BitSizeOf.

MarkMLl

  • Hero Member
  • *****
  • Posts: 3670
Re: how to break out early of a case ?
« Reply #169 on: December 07, 2021, 02:07:48 pm »
No, it's not worth examining, because then the next one will come with the next function and so on. Better focus this into a more general approach.

Also if all you need is the size in bits then you can always use BitSizeOf.

I didn't mean examining as in "we'll add a function" but as in "if you did it like this you wouldn't be asking us to add a function" :-)

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018