Re: [fpc-pascal] case statement
Gerhard Scholz via fpc-pascal said on Sat, 16 Dec 2023 20:07:45 +0100 >I never had the problem because before the else I always inserted a ";" I know it's 50+ years too late for me to submit ideas for the Pascal language, but in my perfect world you could put a semicolon at the end of anything, and if it "doesn't belong there" it's just treated as a no-op. I know this makes it harder for the compiler designer, but it sure makes it easier for me as a user. SteveT Steve Litt Autumn 2023 featured book: Rapid Learning for the 21st Century http://www.troubleshooters.com/rl21 ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] What is webasssembly?
Michael Van Canneyt via fpc-pascal said on Wed, 11 Oct 2023 08:27:35 +0200 (CEST) >On Tue, 10 Oct 2023, Steve Litt via fpc-pascal wrote: > >> What is webasssembly? > >A bytecode format (similar to what is used in Java and C# runtimes) >which is an open standard and which runs in all major browsers or in a >host application. Does this mean I can code an application in Pascal and use webassembly to turn it into a web application? If so, could you please point me to some simple examples? Thanks, SteveT Steve Litt Autumn 2023 featured book: Rapid Learning for the 21st Century http://www.troubleshooters.com/rl21 ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] What is webasssembly?
What is webasssembly? SteveT Steve Litt Autumn 2023 featured book: Rapid Learning for the 21st Century http://www.troubleshooters.com/rl21 ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Legitimate use of for and break
Santi via fpc-pascal said on Sat, 1 Jul 2023 10:22:48 +0200 >El 16/06/2023 a las 16:09, Mattias Gaertner via fpc-pascal escribió: >> On Fri, 16 Jun 2023 20:51:42 +0700 >> Hairy Pixels via fpc-pascal wrote: >> On Jun 16, 2023, at 6:23 PM, Thomas Kurz via fpc-pascal wrote: >> 20 years ago there were some programmers, claiming a loop condition >> must only be at start or end, but not in the middle. >I mostly agree with that programmers. That's called structured >programming. "Break" and "continue" are in fact, a subset of GOTO I agree, although they're less damaging than goto, which I haven't used since 1982 using 6800 hex machine language, where I learned how much less damaging jump to subroutine and return from subroutine are than goto. >When you see a structure, a block, you know at the beginning (or end >of the block) the exit conditions. So you can skip the block and you >know the conditions after the block. It is very useful when you are >skimming the code or debugging. You don't have the investigate the >inner loop to see if there are hidden GOTOs. I agree, although there are some practical concerns, which you go on to mention... > >But, as any other golden rule, you must know when it makes sense to >ignore it. >I use the break, but only at the beginning of the loop. (or exit in >function/procedure) >And sometimes with deep nested loops, but, when I commit such crime, I >highlight it with neon lights in the comments. I tend to put continue statements at or near the top of the block, to summarily rule out some obvious irrelevant iterations without all sorts of if/then/else nesting. As a practical matter it's more readable and more maintainable. Also, when I'm in a rush, I'll do while(True) and then just put one or more breaks in the block, with the full intention of going back and doing it the right way, but then forget to. I apologize to the maintenance programmer who follows me, because this is bad practice. Sometimes I use breaks when the loop test condition would be so hairy as to be difficult to understand. This happens a lot when things get very stateful. But your post got me to thinking that maybe this is a symptom that I made a poor design. > >I really hate having the read the full code to guess whats happening. >Structured programming is your friend. Xactly! SteveT Steve Litt Autumn 2022 featured book: Thriving in Tough Times http://www.troubleshooters.com/bookstore/thrive.htm ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Microsoft SAPI on Freepascal
Steve Litt via fpc-pascal said on Mon, 26 Jun 2023 22:26:17 -0400 >Where does one get ComObj? On my box this errored out with: I went off half cocked. I'm using Linux. Is ComObj even available on Linux? Would you expect Voice := CreateOLEObject('SAPI.SpVoice') and Voice.Speak('I am speaking.', 0) to work on Linux? I know soundon and soundoff don't work with Linux. Thanks, SteveT Steve Litt Autumn 2022 featured book: Thriving in Tough Times http://www.troubleshooters.com/bookstore/thrive.htm ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Microsoft SAPI on Freepascal
Rik van Kekem via fpc-pascal said on Mon, 26 Jun 2023 16:12:06 +0200 >program Project1; >{$mode objfpc}{$H+} >uses > Classes, ComObj; >var > Voice: olevariant; >begin > Voice := CreateOLEObject('SAPI.SpVoice'); > Voice.Speak('I am speaking.', 0); > Voice.Speak('I am also speaking.', 0); >end. Where does one get ComObj? On my box this errored out with: speak.pas(4,12) Fatal: Can't find unit ComObj used by Project1 By the way, when pasting the Classes, ComObj line from your email and compiling, I got an error about a bad character. To get past it I had to re-type the command on a new line and then delete the pasted one. Thanks, SteveT Steve Litt Autumn 2022 featured book: Thriving in Tough Times http://www.troubleshooters.com/bookstore/thrive.htm ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Subscript pointers
Hairy Pixels via fpc-pascal said on Mon, 26 Jun 2023 18:52:16 +0700 >> On Jun 26, 2023, at 3:48 PM, Steve Litt via fpc-pascal >> wrote: >> >> Why do you need pointers at all? Pointers aren't *usually* an asset. >> > >Seriously? anytime you allocate something on the heap you need a >pointer. Exactly. Unless there are going to be an unknown and unlimited number of these structures, or unless they're expected to be insanely huge, I'll make them global variables. Globals suck, but so do unnecessary pointers. >Classes are pointers even. Let me get back to you on that. SteveT Steve Litt Autumn 2022 featured book: Thriving in Tough Times http://www.troubleshooters.com/bookstore/thrive.htm ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Subscript pointers
Hairy Pixels via fpc-pascal said on Sun, 25 Jun 2023 11:20:53 +0700 >> On Jun 24, 2023, at 8:00 PM, Steve Litt via fpc-pascal >> wrote: >> >> I don't do much with Pascal pointers, but it looks to me like you: >> >> * Set p to the address of i >> * Set the contents of p to 100 >> * Read the contents of p, which of course would be the value of i, >> 100 >> * Read the contents of p+1, which would be one integer width away on >> the stack, and has not been assigned to anything. > >Indeed that's what it's doing. It's strange as an array syntax though >which suggests there's a range of uniform elements, when in reality >there's just a pointer to a single location. > >I think the more correct Pascal way to do it would be define an array >type and pointer to that type and then subscript that instead of the >C-style way. Why do you need pointers at all? Pointers aren't *usually* an asset. SteveT Steve Litt Autumn 2022 featured book: Thriving in Tough Times http://www.troubleshooters.com/bookstore/thrive.htm ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Subscript pointers
Hairy Pixels via fpc-pascal said on Thu, 22 Jun 2023 20:23:13 +0700 >I've forgotten entirely, what does subscripting a pointer do in >Pascal? p[0] returns 100 but after that garbage. Seems like a c-style >array which doesn't feel right in the language. > >var > i: Integer; > p: PInteger; >begin > p := @i; > p^ := 100; > writeln(p[0]); > writeln(p[1]); > writeln(p[2]); > >Regards, > Ryan Joseph I don't do much with Pascal pointers, but it looks to me like you: * Set p to the address of i * Set the contents of p to 100 * Read the contents of p, which of course would be the value of i, 100 * Read the contents of p+1, which would be one integer width away on the stack, and has not been assigned to anything. So what you report is exactly what I'd expect to happen. If p were pointing to the first element of an array of integer that had been initialized, it would have worked the way you intended. p[1] is undefined, but if I had to guess, the way most compilers seem to work, I'd say it would be one integer width of the value of p[0], which is the address of i. If my supposition is correct, by modifying the contents of p[1] and maybe some other elements of p, you could write some pretty interesting self-modifying code. But don't do that. SteveT Steve Litt Autumn 2022 featured book: Thriving in Tough Times http://www.troubleshooters.com/bookstore/thrive.htm ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Legitimate use of for and break
wkitty42--- via fpc-pascal said on Wed, 21 Jun 2023 08:07:59 -0400 >On 6/20/23 10:54 PM, Steve Litt via fpc-pascal wrote: >> It was a long time ago, but if I remember correctly the >> Whitesmith Pascal and Turbo Pascal 2 and 3 had either break or >> continue. If I remember correctly, I first learned about those when >> learning C. > >i'm confused about your statement... first you say break/continue >existed in one of two pascal dialects but then you say you first >learned about the two keywords in C... u, wut? I meant to say "neither" instead of "either". Sorry for the confusion. SteveT Steve Litt Autumn 2022 featured book: Thriving in Tough Times http://www.troubleshooters.com/bookstore/thrive.htm ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Legitimate use of for and break
Hairy Pixels via fpc-pascal said on Tue, 20 Jun 2023 14:05:04 +0700 >> On Jun 20, 2023, at 1:10 PM, Steve Litt via fpc-pascal >> wrote: >> >> I can still make a good argument for what my professors taught me, >> but in the intervening years, I found break and especially continue >> wonderful for increasing readability. > >Educators continuously have stupid ideas that don't work out as >intended in the real world. I would love to see them make a real >program that does something difficult and not use early breaks. > >I assume them they forbid early exits in functions also or is the loop >special for them? I'd have to take a time machine back to the early 1980's to find out their opinions on early function exit, but judging from their underlying philosophies I'd guess they'd have a problem with early exits from functions. Their tude isn't completely stupid if you look at it from the viewpoint of the early 1980's. Flowchart-designed spaghetti code and the proud and stubborn spaghetti chefs creating it were still very prevalent, resulting in programs increasingly difficult to bring to completion, modify or maintain. By FAR my educators' priority was to teach us modular programming: 1 entry point, 1 exit point, no global variables, no gotos, no goto-lights (break, continue, exit). With what they taught us young turks, we went out and replaced the spaghetti chefs everywhere except the mainframe. As we young turks got some experience, we realized the orthodoxy we learned in school wasn't necessary. We realized that in 30 line loop body, putting three continue statements at the top was a heck of a lot more readable than three levels of indentation. We realized that in a 30 line loop body, with multiple things being able to stop the loop and not just a counter, sometimes a break statement was more readable than a monstrosity logic part of the while statement, and all the if statements to prevent certain parts from being executed. So yeah, we used some stupid ideas in the real world, but those stupid ideas completely eliminated spaghetti programming, so our super-productivity displaced the spaghetti guys, giving us some time to moderate the orthodoxy with common sense. One of the things I truly appreciated about Pascal was that it not only promoted modular programming, but it also made it difficult to spaghetti. It was a long time ago, but if I remember correctly the Whitesmith Pascal and Turbo Pascal 2 and 3 had either break or continue. If I remember correctly, I first learned about those when learning C. Thanks, SteveT Steve Litt Autumn 2022 featured book: Thriving in Tough Times http://www.troubleshooters.com/bookstore/thrive.htm ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Legitimate use of for and break
Hairy Pixels via fpc-pascal said on Sun, 18 Jun 2023 08:04:23 +0700 >> On Jun 18, 2023, at 1:07 AM, tsie...@softcon.com wrote: >> >> This is interesting, because it's the first time I've ever seen >> "break" as a valid command in pascal, and I've been using pascal >> since the mid/late 80s. All kinds of dialects too, and I've never >> seen break as a keyword. C, Python, Perl, sure, even shell scripts, >> but pascal? Never seen it used before. Is this a relatively new >> addition to fpc or something? > >I don't remember break NOT being in Pascal. How did you exit a loop >otherwise, goto? Break is common in basically all languages now. Can't >think of a language I've used without it. When I learned Pascal at Santa Monica Community College (SMC), the professors repeatedly hammered home that a loop should have exactly one entry point and one exit point. You don't exit until your test condition goes false, and then you go down to the bottom of the loop body and don't iterate further.. No matter how many levels of if statements you had to use, you weren't supposed to use anything like break, continue or exit in the loop. I don't remember whether those keywords actually existed then. I can still make a good argument for what my professors taught me, but in the intervening years, I found break and especially continue wonderful for increasing readability. SteveT Steve Litt Autumn 2022 featured book: Thriving in Tough Times http://www.troubleshooters.com/bookstore/thrive.htm ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Legitimate use of for and break
Hairy Pixels via fpc-pascal said on Fri, 16 Jun 2023 09:57:36 +0700 >> On Jun 16, 2023, at 6:07 AM, Steve Litt via fpc-pascal >> wrote: >> >> Is http://sprunge.us/MOJIg4 a legitimate use of a for loop with >> break? I know there are better ways to do it, but I'm just wondering >> whether it's legitimate. > >What are you trying to do exactly? Explore FPC. > It's an array with a terminator >string? Probably the length of the array should be set instead of >doing string compares every loop. I need to set it in the var declaration, right? > >program fordo; >var words: array[1..6] of string; >var ss: integer; > >begin >for ss := 1 to 6 do > words[ss] := '~'; Is it legitimate to set elements inside a for loop? > >words[1] := 'One'; >words[2] := 'Two'; >words[3] := 'Three'; > >for ss := 1 to 6 do > if words[ss] = '~' then > break ^ IS IT legitimate to use a break (or continue) inside a for loop? Thanks, SteveT Steve Litt Autumn 2022 featured book: Thriving in Tough Times http://www.troubleshooters.com/bookstore/thrive.htm ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Legitimate use of for and break
Is http://sprunge.us/MOJIg4 a legitimate use of a for loop with break? I know there are better ways to do it, but I'm just wondering whether it's legitimate. SteveT Steve Litt Autumn 2022 featured book: Thriving in Tough Times http://www.troubleshooters.com/bookstore/thrive.htm ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] fpc isn't optimised for tail recursion, is it?
Nikolay Nikolov via fpc-pascal said on Mon, 12 Jun 2023 09:15:17 +0300 >On 6/12/23 04:44, Steve Litt via fpc-pascal wrote: [snip] >> So, subject to your guidance, I'm assuming FPC isn't optimized for >> tail recursion. Is my assumption an accurate one? > >FPC supports tail recursion optimization, it is enabled at -O2 >optimization level for most CPUs, however your code isn't eligible for >that optimization, because there's extra code, after the recursive >invoke. If you change it like that: > >program recursion_hello; > >function nextt(num: int64): int64; > begin > writeln('Going deeper=> ', num); > nextt := num; > if (num > 0) then > begin > nextt(num - 1); > end; > end; > >begin > nextt(10); >end. > >And if you compile with -O2 it works, without segfaulting (tested with >FPC 3.2.2 on x86_64-linux). Thanks Nickolay, You're right about not assigning nextt below the call to nextt, and about the -O2 argument. After learning from you about -O2 and investigating further, I used {$OPTIMIZE tailrec}, which isn't quite the same thing, but it worked beautifully. {$OPTIMIZE on} also enables tail recursion and speeds things up about 10% of tailrec. Thanks for your help. SteveT Steve Litt Autumn 2022 featured book: Thriving in Tough Times http://www.troubleshooters.com/bookstore/thrive.htm ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] fpc isn't optimised for tail recursion, is it?
Marco van de Voort via fpc-pascal said on Mon, 12 Jun 2023 09:12:22 +0200 >On 12-6-2023 08:15, Nikolay Nikolov via fpc-pascal wrote: > >Shouldn't the recursive call assign the result? > >> nextt(num - 1); > > >nextt:=nextt(num - 1); > > >if you don't use the result, the whole call may be optimized away? Thanks Marco, You're right, of course. I'm not using my function return. That being said, as far as I know, FPC can't optimize for tail recursion if I do use the function return in any way. So I didn't use the function return. Of course, you bring up a point of cleanness and style. If I don't use the function return, I should have made it a procedure instead of a function. Anyway, I learned from my forays into Guile that I don't yet have a good mental model of functional programming, hence my confusion. Thanks, SteveT Steve Litt Autumn 2022 featured book: Thriving in Tough Times http://www.troubleshooters.com/bookstore/thrive.htm ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] fpc isn't optimised for tail recursion, is it?
Jean SUZINEAU via fpc-pascal said on Mon, 12 Jun 2023 18:04:07 +0200 >According to you other posts, I won't be surprised that you think in a >C/C++ way. :-) Busted! I used Pascal 1984-1993, and C 1986-present with C++ (hate it) 1990-1998. So I long ago forgot the details of pascal, and program pretty much every language with a C accent. >This doesn't change anything in your last example, but particularly : > >nextt := num; > >doesn't behave like in C : > >return num; Busted again. I was thinking that nextt := num not only defined the return value, but actually executed the return. Because that's how the return statement works in C. I now know (remember actually) that the assignment doesn't trigger the return. Thanks, SteveT ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] fpc isn't optimised for tail recursion, is it?
Hi all, Tail recursion is recursion in which absolutely nothing gets executed after the return statement. Some programming languages, including Guile, optimize for tail recursion such that tail recursive algorithms don't use additional stack space as you pile up more and more levels of recursion. I did a typical non-tail recursion hello world program, and if I set the "now-go-backward" number high enough, it segfaulted, I assume because I ran it out of stack space with so many levels of recursion. So, to see if FPC is optimized for tail recursion, I tested it with the following program, which I think is tail-recursive. === program recursion_hello; function nextt(num: int64): int64; begin writeln('Going deeper=> ', num); if (num > 0) then begin nextt(num - 1); end; nextt := num; end; begin nextt(10); end. === As you can see, the return from function occurs at the very end of function nextt(), which I believes makes my algorithm tail-recursive. Running my program, I found it segfaulted pretty much the same as the non-tail-recursive version. I tried to look up all relevant compiler directives, finding {s-} and {$stackspaces off}, which requires no local vars and no parameters to not implement a stackspace for a fuunction. So I made the "now-go-backward" number a global, and made the recursive function a procedure, and still, I got the segfaulting. So, subject to your guidance, I'm assuming FPC isn't optimized for tail recursion. Is my assumption an accurate one? Thanks, SteveT Steve Litt Autumn 2022 featured book: Thriving in Tough Times http://www.troubleshooters.com/bookstore/thrive.htm ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Non-initialized member access warning
Hairy Pixels via fpc-pascal said on Wed, 7 Jun 2023 15:44:43 +0700 >I'm curious, why doesn't the following code give a warning? Shouldn't >the compiler know you're assigning to "r" which hasn't been >initialized yet? > >type > TMyClass = class > x: integer; > end; > >procedure MyProcedure; >var > r: TMyClass; >begin > r.x := 1; >end; > > >Regards, > Ryan Joseph If I had to guess, I'd say it's because you needed to and did declare {$mode objfpc} or {$mode delphi}, which, my guess would be, don't warn against using uninitialized variables. The following program contains your code but includes r := tmyclass.create to allocate RAM to the object. If that line is commented out, you get a runtime 216, which I believe is a memory access violation. {$mode objfpc} {Needed for classes} {$rangechecks on} {Check for runtime memory tromp} {$warnings on} {List all warnings} program junk3; type TMyClass = class x: integer; end; procedure show(c: tmyclass); begin writeln(c.x); end; procedure MyProcedure; var r: TMyClass; begin {Comment out following line to produce memory error} r := tmyclass.create; {Allocate ram for object r} r.x := 1; show(r); end; begin myprocedure; writeln('Finished'); end. I explored {$warn whatever}, and none of the whatevers pertained to uninitialized varibles, and {$warnings on} didn't bring out a warning. I've seen uninitialized var warnings in other code, so by process of elimination I'd imagine this is due to {$mode delphi} and its cousins, which are necessary to recognize "class" as a reserved word. I know this isn't a very satisfying answer, but it's the best I can come up with. SteveT Steve Litt Autumn 2022 featured book: Thriving in Tough Times http://www.troubleshooters.com/bookstore/thrive.htm ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] General FOSS discussion, 6/7/2023
Hi all, Sorry for the late notice. GoLUG's mailing list is down so I couldn't get input on a topic earlier. Tonight at 7:00 Eastern Daylight time, 6/7/2023, GoLUG is having an online discussion of anything involving Free and Open Source Software (FOSS). The meeting location is https://meet.jit.si/golug . This meeting is online only. I'll speak for 5 or 10 minutes on Free Pascal. Others are welcome and encouraged to speak on anything relating to FOSS. I hope to see you at the meeting. SteveT Steve Litt Publicity Coordinator Greater Orlando Linux User Group (GOLUG) ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Function to create a record ?
Jean SUZINEAU via fpc-pascal said on Mon, 5 Jun 2023 11:56:59 +0200 >Hello, I have a hard time trying to understand what you want to test. > >In your functions, you are using a record, not a class or a pointer to >record or an object. > >The personrecord just behave in your parameters and return value as an >Integer or a String, and your fillchar doesn't write outside of the >memory allocated for you junkvar, so I don't see what can go wrong. > >If you trace the address of person.name like this: > >//begin code >begin > person := newperson(); > writeln('1, person.name address: ', > IntToHex(Int64(Pointer(@(person.name); > fillchar(junkvar, junkvar_size, 'a'); > person2 := newperson(); > fillchar(junkvar, junkvar_size, 'b'); > person := modperson(person, 'Martin'); > person := modperson(person2, 'Maria'); > writeln('2, person.name address: ', > IntToHex(Int64(Pointer(@(person.name); > {writeln(junkvar);} > writeperson(person); > writeperson(person2); >end. >//end code > >You'll see that the address doesn't change, for example: > >1, person.name address: 0050C7F0 >2, person.name address: 0050C7F0 > > >But if you declare your personrecord as a class, the things doesn't >behave the same way: > >//begin code >const > junkvar_size = 2000; > >type > personclass = class > name: string; > end; >var > person: personclass; > person2: personclass; > junkvar: array[1..junkvar_size] of char; > >function newperson(): personclass; >var newp: personclass; >begin > newp:= personclass.Create; > newp.name := ''; > newperson := newp; >end; > >function modperson(person: personclass; name: string): personclass; >begin > person.name := name; > modperson := person; >end; > >procedure writeperson(person: personclass); >begin > writeln(person.name); >end; > >begin > person := newperson(); > writeln('1, person.name address: ', > IntToHex(Int64(Pointer(@(person.name); > fillchar(junkvar, junkvar_size, 'a'); > person2 := newperson(); > fillchar(junkvar, junkvar_size, 'b'); > person := modperson(person, 'Martin'); > person := modperson(person2, 'Maria'); > writeln('2, person.name address: ', > IntToHex(Int64(Pointer(@(person.name); > {writeln(junkvar);} > writeperson(person); > writeperson(person2); >end. >//end code > > >You'll get a different address, something like: > > >1, person.name address: 77F910E8 >2, person.name address: 77F91108 Thanks Jean, The problem I was trying to fix was that I accidentally said: person := modperson(person2, 'Maria'); instead of person2 := modperson(person2, 'Maria'); ^^^ Note the 2 But wait, there's more... As Travis Siegel pointed out, my method relied on the compiler not to overwrite RAM of a variable that had gone out of scope, and that's the highway to heartache. So I was first going to implement a non-OOP solution using New and Dispose, and then implement an OOP solution. Now that you provided the OOP solution, I'll make sure I can get your solution to work, and then go back to the non-OOP solution. So **THANK YOU** ! ! ! SteveT Steve Litt Autumn 2022 featured book: Thriving in Tough Times http://www.troubleshooters.com/bookstore/thrive.htm ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Function to create a record ?
Travis Siegel via fpc-pascal said on Sun, 4 Jun 2023 19:38:44 + > >On 6/4/2023 1:37 PM, Steve Litt via fpc-pascal wrote: >> Henry Vermaak via fpc-pascal said on Fri, 2 Jun 2023 09:38:17 +0100 >> >>> On Fri, 2 Jun 2023 at 01:36, Steve Litt via fpc-pascal >>> wrote: >>>> fillchar(junkvar, junkvar_size, 'b'); >>>> person := modperson(person, 'Martin'); >>>> person := modperson(person2, 'Maria'); >>> Maybe a typo? (E.g. person2 := modperson(person2, 'Maria')) >>> >>> Henry >> Thanks Henry! >> >> You're right: Changing the second person := to person2 := did just >> what I wanted it to do. >> >> Because returning a local array or string as a function return in C >> leads to horrible intermittents due to the local going out of scope >> and relinquishing the local's stack, which can then be overwritten, >> I added a procedure, a function, and a main program statement which >> each consumed two million bytes of local variables, and the person >> and person2 didn't get overwritten. Very cool. >> >> When I increased the huge local vars to three million bytes, the >> program segfaulted. I figure I just ran it out of stack, but until I >> did, the huge local vars didn't trash the contents of person and >> person2. >> >> Thanks for your help. >> >> SteveT >Depending on the compiler *not* to overwrite local variables is most >certainly the wrong way to go with this. You really should create >either a global record/object, or use functions to pass around the >information you need. Expecting the operating system to keep local >variables after the area goes out of scope is just begging for errors >later on when the compiler/os treatment of said areas changes. Thanks Travis, This is the info I was asking for. Yeah, passing the local as a function return worked, but because of a horrible experience doing that in C, I was suspicious and leery of actually using that technique. I'll just use new and dispose. Thanks, SteveT Steve Litt Autumn 2022 featured book: Thriving in Tough Times http://www.troubleshooters.com/bookstore/thrive.htm ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Function to create a record ?
Ralf Quint via fpc-pascal said on Thu, 1 Jun 2023 17:43:58 -0700 >On 6/1/2023 5:36 PM, Steve Litt via fpc-pascal wrote: >> >> What is the best way for me to construct newperson() so that every >> time called it would return a new variable? >W.T.F.? > >Sorry, but for how long are you programming, in general, and for how >long in Pascal? > >Seriously, you should take some very basic Pascal tutorials, work >through them, and in particular, pay close attention to the "scope" of >variables as well as parameter passing. You seem to be completely >oblivious to those very basics here... :( > >Ralf Feeling better after getting that off your chest Ralf? My post reveals the outcome of my investigation. SteveT Steve Litt Autumn 2022 featured book: Thriving in Tough Times http://www.troubleshooters.com/bookstore/thrive.htm ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Function to create a record ?
Henry Vermaak via fpc-pascal said on Fri, 2 Jun 2023 09:38:17 +0100 >On Fri, 2 Jun 2023 at 01:36, Steve Litt via fpc-pascal > wrote: >> fillchar(junkvar, junkvar_size, 'b'); >> person := modperson(person, 'Martin'); >> person := modperson(person2, 'Maria'); > >Maybe a typo? (E.g. person2 := modperson(person2, 'Maria')) > >Henry Thanks Henry! You're right: Changing the second person := to person2 := did just what I wanted it to do. Because returning a local array or string as a function return in C leads to horrible intermittents due to the local going out of scope and relinquishing the local's stack, which can then be overwritten, I added a procedure, a function, and a main program statement which each consumed two million bytes of local variables, and the person and person2 didn't get overwritten. Very cool. When I increased the huge local vars to three million bytes, the program segfaulted. I figure I just ran it out of stack, but until I did, the huge local vars didn't trash the contents of person and person2. Thanks for your help. SteveT Steve Litt Autumn 2022 featured book: Thriving in Tough Times http://www.troubleshooters.com/bookstore/thrive.htm ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Function to create a record ?
Hi all, I'm trying to create a function (called newperson()) that creates a new instance of a record. The following compiles with no errors or warnings in FPC, but multiple calls to newperson() produce exactly the same variable, so in the preceding changing person changes person2, and vice versa: === program test2; const junkvar_size = 2000; type personrecord = record name: string; end; var person: personrecord; person2: personrecord; junkvar: array[1..junkvar_size] of char; function newperson(): personrecord; var newp: personrecord; begin newp.name := ''; newperson := newp; end; function modperson(person: personrecord; name: string): personrecord; begin person.name := name; modperson := person; end; procedure writeperson(person: personrecord); begin writeln(person.name); end; begin person := newperson(); fillchar(junkvar, junkvar_size, 'a'); person2 := newperson(); fillchar(junkvar, junkvar_size, 'b'); person := modperson(person, 'Martin'); person := modperson(person2, 'Maria'); {writeln(junkvar);} writeperson(person); writeperson(person2); end. === What is the best way for me to construct newperson() so that every time called it would return a new variable? Thanks, SteveT Steve Litt Autumn 2022 featured book: Thriving in Tough Times http://www.troubleshooters.com/bookstore/thrive.htm ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Freeing memory with exceptions
Michael Van Canneyt via fpc-pascal said on Tue, 30 May 2023 16:55:16 +0200 (CEST) >On Tue, 30 May 2023, Hairy Pixels via fpc-pascal wrote: > >> >> >>> On May 25, 2023, at 1:10 PM, Michael Van Canneyt via fpc-pascal >>> wrote: >>> >>> >>> In C you need to do something like this: >>> >>> Function MyFunction(out theresult : TResultType) : Integer; >>> >>> begin >>> Allocate A >>> ... >>> error condition 1: >>>Free A, exit (1); >>> ... >>> Allocate B >>> error condition 2: >>>Free A, Free B, exit(2) >>> >>> Allocate C >>> error condition 3: >>> Free A, Free B, free C, exit(3); >>> ... >>> // etc >>> // All went well, report 0 >>> theresult:=X; >>> Free A, Free B, free C exit(0); >>> end. >> >> Indeed this is an ideal example of why they were invented and it >> makes sense here. Honestly most of this mess could be cleaned up >> with smart pointers also and not upset control flow like exceptions >> do. >> >> I'm doing work with Swift right now and in particular a web >> framework that makes lots of database calls, all of which can fail >> so we use exceptions everywhere. The thing that Swift does well and >> FPC does not, is that it labels the functions as "throws" and calls >> have a "try" keyword before them so you know how the control flow is >> actually working. >> >> Because FPC doesn't do this any function could throw errors and thus >> those stack frames are inserted everywhere and add needless overhead >> when exceptions aren't used. It's also nice to not have hidden >> control flow potential on any function call > >The rule is simple in FPC: You should always assume exceptions >everywhere. > >Simply because system errors are also transformed to exceptions, and >thus any function can indeed throw errors: > >an "Access Violation" error can happen on any level of the code, >or an "out of memory" or some other signal by the system or even CPU >(think overflow). > >If sysutils is used, these are transformed to an exception, regardless >of whether the code itself uses exceptions to report errors or not. > >The only way to know for sure there will not be an exception is not to >use sysutils anywhere in your code or anyone elses code. > >Delphi introduced a coupling between sysutils and exceptions, and now >we're stuck with that. > >Today, you'd need to write your RTL to get rid of them. > >Michael. Would this work?... Have a global self-kill object containing a list of every object that's been allocated. After every successful allocation, call the self-kill object method to add the object onto the list. On every successful free, call self-kill method to remove that object from the list. On programmer-defined exceptions, call self-kill's method to free everything on the list and then free itself, after which the program can terminate. I don't know about other operating systems, but on Linux a crashed program gives up all its memory, even leaked memory, upon termination, so I'm not sure why this attention to memory leak on abnormal termination is even necessary. SteveT Steve Litt Autumn 2022 featured book: Thriving in Tough Times http://www.troubleshooters.com/bookstore/thrive.htm ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Freeing memory with exceptions
Benito van der Zander via fpc-pascal said on Wed, 24 May 2023 13:00:04 +0200 >I regret installing Linux. Everything worked better with Windows 98 >and Delphi 4 Why not just take your Win98 install disk, install win98, then take your Delphi 4 install disk, install Delphi 4, and you're all set. And you can recover the 39 bytes you lost to Linux. SteveT Steve Litt Autumn 2022 featured book: Thriving in Tough Times http://www.troubleshooters.com/bookstore/thrive.htm ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Freeing memory with exceptions
Michael Van Canneyt via fpc-pascal said on Sun, 21 May 2023 09:47:15 +0200 (CEST) >Assuming the result of A is not used outside of Test, the following is >the only solution: > >procedure Test; > >var > A : TObject; >begin > A:=TObject.Create; > Try > // call some code in other unit which raise an exception > DoThis; > finally > A.Free > end; >end; Perhaps there could be one procedure that frees and unwinds everything, since there will probably be more objects that need to be freed, and this procedure could be called by every finally. SteveT Steve Litt Autumn 2022 featured book: Thriving in Tough Times http://www.troubleshooters.com/bookstore/thrive.htm ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Freeing memory with exceptions
Michael Van Canneyt via fpc-pascal said on Sun, 21 May 2023 09:47:15 +0200 (CEST) >On Sun, 21 May 2023, Hairy Pixels via fpc-pascal wrote: > >> I've never really used exceptions myself in Pascal (with the >> exception of breaking out of deeply recursive function calls) so I >> don't know all the rules. >> >> In this example lets say you call Test() which allocates some memory >> and then calls out to another function in another unit which raises >> (the programmer doesn't know this because FPC doesn't mark the >> function as throwing exceptions). Now the Test() function will exit >> early before freeing the memory. >> >> What are you supposed to do here? The only thing I can think of is >> to wrap every function in try..finally which COULD raise an >> exception but that's a huge mess because literally any function >> could raise. >> >> >> >> procedure DoThis; >> begin >> raise Exception.Create('dead'); >> end; >> >> procedure Test; >> begin >> TObject.Create; >> // call some code in other unit which raise an exception >> DoThis; >> end; > >Your example will leak memory in any case, even if there is no >exception, since you're not freeing the object anywhere.. > >Assuming the result of A is not used outside of Test, the following is >the only solution: > >procedure Test; > >var > A : TObject; >begin > A:=TObject.Create; > Try > // call some code in other unit which raise an exception > DoThis; > finally > A.Free > end; >end; > >You can try to use interfaces, they will be managed by the compiler. > >Alternatively, using generics and management operators you can >create a record that will automatically free the object at the >end of the procedure. > >Michael. Am I correctly understanding you that Pascal objects come off the heap and not the stack by default? Ouch! This is one of the C-isms I'd like to get away from. Is there a way to create objects from stack memory so there's no need to free? NOTE: I've only rarely used OOP in Pascal. Thanks, SteveT Steve Litt Autumn 2022 featured book: Thriving in Tough Times http://www.troubleshooters.com/bookstore/thrive.htm ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] override and virtual: was SetFileTime
Giuliano Colla via fpc-pascal said on Wed, 3 May 2023 19:33:25 +0200 > >Override: When you're dealing with objects, you have the >inheritance, that is you may derive a new class (the template of an >object) from an existing class and the newly created class inherits >all the methods and properties of the parent class. In this case >TTouchJunction is declared as a descendant of TCustomApplication, >therefore it inherits all the methods and properties. If you need >that your object does something different from the methods of its >parent, but keep the same name, you must declare that your >declaration overrides the ancestors one. If in the body of your new >method if you want to execute also the ancestor method you may call >it with the keyword "inherited". > > * > >Virtual: means that this method can be overridden by a descendant >class. The same does the keyword Dynamic. The difference has to do >with the way the code is allocated in memory. Virtual is optimized >for speed, Dynamic for memory. > >Hope that it helps. Thanks Giuliano, it helps a lot. I'm familiar with the concepts you mentioned from work with Perl, Python and C++, and it's good to know how they're implemented in FPC. Thanks, SteveT Steve Litt Autumn 2022 featured book: Thriving in Tough Times http://www.troubleshooters.com/bookstore/thrive.htm ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] override and virtual: was SetFileTime
José Mejuto via fpc-pascal said on Wed, 3 May 2023 11:35:50 +0200 >Hello, > >Attached is a dirty implementation of "touch" for junctions == TTouchJunction = class(TCustomApplication) protected procedure DoRun; override; function DateTimeToFileTime(DateTime: TDateTime): TFileTime; public constructor Create(TheOwner: TComponent); override; destructor Destroy; override; procedure WriteHelp; virtual; end; == I'm an old Turbo Pascal (mainly 3.x, a little 5.5) guy and don't remember or never saw override and virtual. What do they do? SteveT Steve Litt Autumn 2022 featured book: Thriving in Tough Times http://www.troubleshooters.com/bookstore/thrive.htm ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] sound(FREQUENCY) on Linux ?
Hi all, On DOS and Windows programs using Turbo Pascal, I did the following to make a sound of frequency FREQUENCY play through the speakers: sound(FREQUENCY); The following command stopped the tone: nosound; These two commands don't work on Linux, according to my experience and FPC documentation. How do all of you on Linux play tones from FPC? I tried forking command: speaker-test -t sine -f 880 The preceding plays the tone, but depending on duration and delays, it also produces either unpleasant clicks or nasty interference frequencies between notes and so isn't adequate to play little tunes. How are all of you playing tones through speakers in Linux? Thanks, SteveT Steve Litt Autumn 2022 featured book: Thriving in Tough Times http://www.troubleshooters.com/bookstore/thrive.htm ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] As I predicted
Hi all, As I predicted, here's what happened to me on #fpc: == Joanna sets ban on $a:stevelitt * You have been kicked from #fpc by Joanna (sorry i cant share a channel with you after what you said in mailing list) == And here's what happens when I try to join #irc: == Cannot join #fpc (You are banned). == I'll be using #fpc-alt and ##fpc-alt from now on. SteveT Steve Litt Autumn 2022 featured book: Thriving in Tough Times http://www.troubleshooters.com/bookstore/thrive.htm ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] I registered #fpc-alt and ##fpc-alt
For those of you who can't get onto Libera.Chat channel #fpc, or would prefer a less stressful enforcement of the rules, I just created community channel #fpc-alt for ontopic and informal channel ##fpc-alt for offtopic. I haven't yet created the topic for these channels, but basically no personal insults or accusations, no demeaning of groups of people, and call people what they want to be called with the pronouns they prefer. That's it. By the way, as of 4/14/2023 at 02:07 UTC, Joanna is still an operator on #fpc. SteveT Steve Litt Autumn 2022 featured book: Thriving in Tough Times http://www.troubleshooters.com/bookstore/thrive.htm ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] IRC channel for FreePascal support ?
Karoly Balogh via fpc-pascal said on Thu, 13 Apr 2023 16:00:46 +0200 (CEST) >Can we keep this discussion civil? Personal attacks and ridiculing >someone is not the way to deal with disagreements. > >Charlie Sorry. From now on I'll conform with the preceding. SteveT Steve Litt Autumn 2022 featured book: Thriving in Tough Times http://www.troubleshooters.com/bookstore/thrive.htm ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] IRC channel for FreePascal support ?
I bet this Joanna character is an active member of her Homeowners Association. I verified that there is an operator named Joanna on #fpc on Libera.Chat. The power-hungry kind of behavior exhibited by Joanna is bad for the channel and therefore bad for the project. In another post Jacob mentioned that Joanna had kicked him from several other channels on which he had done nothing. This is inexcusable. I assume now that I've written this I'll meet the same fate. I'm rethinking my use of FPC and Lazarus. What good is software if you can't get support? SteveT Jacob Kroon via fpc-pascal said on Thu, 13 Apr 2023 12:53:31 +0200 >Hi Tomas, > >On 4/13/23 11:39, Tomas Hajny via fpc-pascal wrote: > > > >> Just FYI - I don't see anybody having name "Joanna" among people >> subscribed to this mailing list, and nobody like that has been >> considerably active here in the last years as far as my memory >> serves correctly. Obviously, the address and/or name may be >> completely different from the IRC nickname, thus it doesn't mean >> that you wouldn't get the response here for sure. I can't check the >> list of people subscribed to FPC forum, the person may be active >> there. > >Thanks for checking, but well, I just got contacted by "Joanna" >privately on IRC, this is the chatlog: > >> *** BEGIN LOGGING AT Thu Apr 13 12:35:45 2023 >> >> [Joanna has address uid57...@id-57472.lymington.irccloud.com] >> Apr 13 12:35:45 I advised you to go to forums where >> you could get some help. Did you ask your question in forums yet? >> Apr 13 12:37:36 Your question in fpc was already >> answered. Please Ask your next question in forums and provide a link >> Apr 13 12:39:26 Hi. No, I prefer mailinglist and IRC, not >> forums. Apr 13 12:39:59 Why do you dislike the >> forums? Apr 13 12:40:33 I already have 2 ways of >> communication, I don't need a third, where I have to register etc. >> Apr 13 12:40:45 Now why the hell do you ban people for >> asking questions ??? Apr 13 12:41:01 How long have >> you used irc ? I’ve never seen you before Apr 13 12:41:23 >> And why do you kick people because they are being silent ??? Apr 13 >> 12:41:34 I don't know, more than 10 years Apr 13 12:41:44 >> If you refuse to ask your questions in forums we >> have nothing more to discuss Apr 13 12:41:48 And I have >> never been kicked out of a channel for being silent Apr 13 12:42:06 >> Not my problem Apr 13 12:42:26 Fine, I'll >> try to contact the IRC admins in the mailing list and get your admin >> rights revoked then Apr 13 12:42:47 I know who you >> are ENDING LOGGING AT Thu Apr 13 12:42:56 2023 > >Now I'm also banned from #lazarus, the reason is "harrassment by pm". > >I ask the #fpc Libera.Chat IRC administrators (if they are listening >here) to revoke channel operator status for user "Joanna". > >Regards, >Jacob >___ >fpc-pascal maillist - fpc-pascal@lists.freepascal.org >https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Working on a new way to educate people about pascal
Wols Lists via fpc-pascal said on Sat, 31 Dec 2022 15:07:41 + >On 31/12/2022 08:37, Steve Litt via fpc-pascal wrote: >> Anthony Walter via fpc-pascal said on Thu, 29 Dec 2022 07:31:57 -0500 >> >>> @youngman >>> >>> "I'm a database guy with maybe 30 years experience, I'm new to SQL >>> and oh my god is it an over-complicated monster ..." >> >> I'll say this: It certainly doesn't help that there are different >> variations of SQL. >> >:-) > >Well, there are plenty different variations of English. And the real >English (that is, what we speak in England) isn't even one language! >It's several different languages that (for the most part) share >similar grammar and vocabulary. > >If that's not a problem, why should the dialects of SQL be a problem. Because unless AI is involved, unlike human interaction, there's no such thing as "you know what I mean." >After all, we have a decent dictionary. It's called the Internet :-) Oh great. So we all need separate cheat sheets for Postgres, MariaDB, Oracle, and SQLite. And let's keep in mind that although the line count on SQL programs is tiny, the debugging can get quite complicated. Heaven help you if you use single quotes instead of doublequotes or vice versa. Hey, if different versions aren't a problem, I have a great idea. Let's go back to exclusively using assembler language, with a different set of op-codes and grammar for each processor. After all, we have a decent dictionary. It's called the Internet :-) SteveT Steve Litt Autumn 2022 featured book: Thriving in Tough Times http://www.troubleshooters.com/bookstore/thrive.htm ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Working on a new way to educate people about pascal
Anthony Walter via fpc-pascal said on Thu, 29 Dec 2022 07:31:57 -0500 >@youngman > >"I'm a database guy with maybe 30 years experience, I'm new to SQL and >oh my god is it an over-complicated monster ..." I'll say this: It certainly doesn't help that there are different variations of SQL. SteveT Steve Litt Autumn 2022 featured book: Thriving in Tough Times http://www.troubleshooters.com/bookstore/thrive.htm ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Be careful of too many features
Brian via fpc-pascal said on Mon, 30 May 2022 22:36:00 -0400 >On 5/30/22 14:59, Steve Litt via fpc-pascal wrote: >> Hi all, >> >> In 1984 I started my programming career with Whitesmith Pascal, > >Sorry for the off-topic post, folks, but this just opened a wound from >my distant past... :( > >I was a couple of years ahead of you, Steve, but at least in 1982 on >the PDP-11, Whitesmith Pascal was a truly *awful* thing - a >translation engine, not a compiler. It was a front end to Whitesmith >C, which in turn translated to Macro-11 and then compiled and linked >that (we watched these steps via RMD). The code produced was horribly >inefficient (we looked at the Macro-11 listings), and using RSX-11M >rather than M+, with no library space, code space was at a premium. > >We quickly switched to Oregon Pascal (which DEC later bought as the >foundation of RSX Pascal) and it was a *far* superior compiler. Apart >from the debugger, that is, which took up so much space that you could >just about debug 'Hello, world' and that was it. > >Hopefully Whitesmiths improved in the couple of years before you >started with it, or there was a better implementation if you used it >on a machine other than a PDP-11. It didn't get better. It got worse. By 1985, the same piece of code would successfully compile about 6 times out of 10. When you had all sorts of modules to compile, that meant SOMETHING would fail, and whatever make facility we had as I remember made us do the whole mass compile over again. Through trial and error I observed that once it compiles successfully, it would compile several more times. So I created whatever you called shellscripts on RT-11, called PMA, which stood for "Positive Mental Attitude". It would compile a trivial program about 7 times, and only after that would it do the real compile. PMA increased our success a little. I called Whitesmith in 1986 asking if this would be fixed and offering to help, and they told me they weren't doing any more work on their Pascal because only three companies worldwide still used it. At that point I reported that we'd need to rewrite in another language. By the way, during the day I'd program in Whitesmith Pascal with its 10 minute compiles. By night I'd use Turbo Pascal 2, on a floppy driven Kaypro 2x running CPM, and compiles would take less than 10 seconds. And I could hit any memory location I wanted to, which later became essential for MS-DOS (remember B800?). I also wrote high level Turbo Pascal file readers that read the input file in huge and doled them out by the character or line, and that worked better than any of Turbo C's high or low level reads, or the Whitesmith C at work. When I became a hired gun programmer and took my show on the road, for years I traveled with a Turbo Pascal 3 floppy in my pocket to work around whatever my customer's chosen language couldn't do. If you remember the Borland copyright (use like a book), this was perfectly within the license as long as I didn't actually install Turbo Pascal on the customer machine. A year or so ago I took a Turbo Pascal program originally written in 1985, modified it slightly, ran it under Freepascal, and got the whole thing running except for the chiptunes music. The soundon() and soundoff() don't work on Linux. I'd love to find a way to get those working. SteveT Steve Litt Spring 2022 featured book: Making Mental Models: Advanced Edition http://www.troubleshooters.com/mmm ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Be careful of too many features
Hairy Pixels via fpc-pascal said on Tue, 31 May 2022 08:39:20 +0700 >> On May 31, 2022, at 1:59 AM, Steve Litt via fpc-pascal >> wrote: >> >> The example code I've seen in the "Feature Announcement: Function >> References and Anonymous Functions" not only doesn't look like any >> Pascal I've ever seen, but it resembles Perl (the "one language on a >> desert island" language before Python) in the huge number of syntax >> choices and the "many ways to do it" philosophy. > >Which part, the anonymous functions? I think function references and to a lesser extent anonymous functions are necessities. Things I consider Perlization are things like inferring context of the receiving function, "Sort( @(left, right) begin", and other feature requests which basically are there to reproduce other languages. And especially syntactic sugar. > FPC is very good about keeping >new features behind mode switches you can disable all the cruft if you >ever want to create plain procedural Pascal like in the 80s. :) A truly great language would be Turbo Pascal 5.5 (with OOP) plus function/procedure references. That being said, I'm obviously not advocating removing features already there; I'm just saying if a feature isn't needed by Delphi/Lazarus, think long and hard about including it. SteveT Steve Litt March 2022 featured book: Making Mental Models: Advanced Edition http://www.troubleshooters.com/mmm ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Be careful of too many features
Sven Barth via fpc-pascal said on Mon, 30 May 2022 23:25:52 +0200 >Steve Litt via fpc-pascal schrieb am >Mo., 30. Mai 2022, 21:25: > >> With the addition of callback functions, and the closures and events >> they bring to the table, you can go procedural, OOP, or to a degree >> functional. I think adding yet more features obfuscates and Perlizes >> Pascal. >> > >We are adding those features we deem useful or are sorely needed for >Delphi compatibility especially when said feature allows something >that isn't easily possible with existing functionality. As a Lazarus user, I thank you for that! SteveT Steve Litt Spring 2022 featured book: Making Mental Models: Advanced Edition http://www.troubleshooters.com/mmm ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Be careful of too many features
Rainer Stratmann via fpc-pascal said on Mon, 30 May 2022 21:22:48 +0200 >Am Montag, 30. Mai 2022, 20:59:56 CEST schrieb Steve Litt via >fpc-pascal: >> I think adding yet more features obfuscates and Perlizes >> Pascal. > >What does Perlize mean? Perlize means to outfit a language with many different syntaxes (not algorithms, syntaxes) to do each task. Perlization works great until you work on somebody else's code, then it becomes a nightmare. SteveT Steve Litt March 2022 featured book: Making Mental Models: Advanced Edition http://www.troubleshooters.com/mmm ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Be careful of too many features
Hi all, In 1984 I started my programming career with Whitesmith Pascal, and soon after Turbo Pascal 3, then C. C had the advantage of pointers to functions, Pascal had the advantages of better readability and less likelihood of errant pointers and buffer overruns. I did a little work with Object Oriented Turbo 5.5. I'm totally pleased that FPC now has function references making callback routines possible. Closures are also nice. And I suppose under certain conditions anonymous functions are an asset, although my experience with Lua tells me it's easier and more readable to name a function temp243() and use it, rather than having a anonymous function sitting there in the middle of other code. The example code I've seen in the "Feature Announcement: Function References and Anonymous Functions" not only doesn't look like any Pascal I've ever seen, but it resembles Perl (the "one language on a desert island" language before Python) in the huge number of syntax choices and the "many ways to do it" philosophy. I programmed professionally in Perl for 4 years, until I ran across a shopping cart application written in a Perl so bizarre that I didn't recognize it as the language I'd used for four years. The "many ways to do it" philosophy had guaranteed that anyone good enough to do maintenance programming in Perl would have to learn not only the language, but every single little shortcut and longcut possible. I switched to Python. So did everyone else. Perl 6 never really made it because most people don't want a "many ways to do it" language, they want a simple language that can do anything. So people chose Python, and to a lesser extent Ruby and Lua, and Perl withered on the vine. With the addition of callback functions, and the closures and events they bring to the table, you can go procedural, OOP, or to a degree functional. I think adding yet more features obfuscates and Perlizes Pascal. SteveT Steve Litt March 2022 featured book: Making Mental Models: Advanced Edition http://www.troubleshooters.com/mmm ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] alloca
Hairy Pixels via fpc-pascal said on Fri, 13 May 2022 22:43:15 +0700 >Is there an “alloca" like function in the RTL which allocates memory >from the stack? For example >https://man7.org/linux/man-pages/man3/alloca.3.html Why not just allocate from the heap? Everything I've seen tells me that if you want a variable with memory from the stack, you just declare it and it's valid throughout the procedure or function in which it's declared, and gets reused when you go out of scope (no need to free). SteveT Steve Litt March 2022 featured book: Making Mental Models: Advanced Edition http://www.troubleshooters.com/mmm ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal