Re: Freepascal rocks!
- From: Eli Gottlieb <eligottlieb@xxxxxxxxx>
- Date: Wed, 05 Apr 2006 15:42:32 GMT
Mark Carter wrote:
Permit some wild ramblings ...
I've been experimenting with a few programming languages lately: Assembler, Lisp, Forth, Smalltalk. I have a background in C, VB, FORTRAN and some Python.
I have to say that, trying to make head or tail of things, Pascal Just Works (TM). Maybe it's my imperative background, I dunno. Whatever FreePascal lacks in meta-, functional- or <insert fave paradigm here>- programming seems to be adequately made up with simplicity and a respectable stack of libraries.
Let's put it this way: I'm writing a customized Lisp interpreter in FreePascal. A language powerful enough to simply implement another language is damn powerful.
Another confession: I'm sick of graphical user interfaces; long live the console. GUI toolkits are mindcrushingly complex. I've twiddled about with a few - and I couldn't even get VB's Grid OCX to exhibit reasonable behaviour. So, as an experiment, I tried to see what I could come up with in a text-only environment. I must say that, using nothing much more than the units crt and keyboard, I was able to knock up something in a fairly short time. For a laff, I append my code below.
GUI toolkits are like that, but the command line just isn't suited to say... Photoshopping.
I hope, next, to incorporate some ODBC stuff. I've looked at a couple of odbcsql examples - and well, I guess I could have hoped for less complexity, but I guess you can't have everything.
The other day I joked to my colleagues that we should be writing more stuff in FORTRAN; my contention being that FORTRAN doesn't really do much, so you *have* to keep things simple. You know really, I sometimes think that FORTRAN (or Pascal, if you like) is the Rapid Application Design language of the future.
The Rapid Design language of always is Lisp. Once you've designed in Lisp, you either implement in Lisp (if you're willing to depend on a Lisp system and everything that comes with it) or Pascal (if you want less dependencies and more portability). Those, of course, are just my opinions.
program timegrid;
uses crt, keyboard, math, sysutils;
var
r, c : Integer;
CurRow, CurCol : Integer;
values : Array[1..10,1..7] of Real;
Procedure InitGrid;
begin
CurRow := 1;
CurCol := 1;
end; { InitGrid }
Procedure ShowGrid;
var
s : String;
v : Real;
begin
ClrScr;
for r := 1 to 10 do
begin
for c:= 1 to 7 do
begin
TextBackground(Black);
if (r = CurRow) and (c = CurCol) then TextBackground(Brown);
v := values[r,c];
s := FormatFloat('##0.0',v);
if(v=0) then write(' ') else write(s:5);
end;
writeln('');
end;
Writeln('Hit a key to perform some action');
writeln('i - insert value');
Writeln('q - quit');
end;
Function StrEq(s1, s2 : string) : boolean;
begin
if( 0 = AnsiCompareText(s1,s2)) then StrEq := true else StrEq := false ;
end; { StrEq }
You do realize the = operator is implemented for strings to do exactly this?
Function restrain(v, lo, hi: integer) : integer;
begin
restrain := max( min(v, hi), lo);
end; { restrain }
Procedure ChangeRowCol(dr, dc: integer );
begin
CurRow := CurRow + dr;
if (CurRow > 10) then CurRow := 1;
if (CurRow < 1) then CurRow := 10;
CurCol := CurCol + dc;
if (CurCol > 7) then
begin
CurRow := CurRow +1;
CurCol := 1;
end;
if(CurCol <1) then
begin
CurRow := CurRow -1;
CurCol := 7;
end;
CurRow := restrain(CurRow, 1, 10);
CurCol := restrain(CurCol, 1, 7);
end; { ChangeRowCol }
Procedure InsertValue;
var
inp : string;
v : real;
code : integer ;
begin
DoneKeyboard;
write('New value: '); readln(inp);
val(inp, v, code);
if( code = 0) then values[CurRow, CurCol] := v;
InitKeyBoard;
ChangeRowCol(0,+1);
end; { InsertValue }
Procedure LoopOverKeys;
var
k : TKeyEvent;
kec : Word; { key event code}
kes : String; {key event string}
begin
InitKeyBoard;
Repeat
k := PollKeyEvent;
if k<>0 then
begin
k := GetKeyEvent;
k := TranslateKeyEvent(k);
kec := GetKeyEventCode(k);
kes := KeyEventToString(k);
if(kec = 65313) then ChangeRowCol(-1,0); {up arrow}
if(kec = 65315) then ChangeRowCol(0,-1); {left arrow}
if(kec = 65317) then ChangeRowCol(0,+1); {right arrow}
if(kec = 65319) then ChangeRowCol(+1,0); {down arrow}
if StrEq(kes, 'i') then InsertValue;
{ writeln;
writeln('got key : ' ,KeyEventToString(k));
writeln('key event code : ', GetKeyEventCode(k));}
ShowGrid;
end
{ else
write('.');}
until (GetKeyEventChar(k)='q');
DoneKeyBoard;
end;
begin
InitGrid;
ShowGrid;
LoopOverKeys;
end.
--
The science of economics is the cleverest proof of free will yet constructed.
.
- Follow-Ups:
- Re: Freepascal rocks!
- From: Jason Burgon
- Re: Freepascal rocks!
- From: Marco van de Voort
- Re: Freepascal rocks!
- From: Mark Carter
- Re: Freepascal rocks!
- References:
- Freepascal rocks!
- From: Mark Carter
- Freepascal rocks!
- Prev by Date: Freepascal rocks!
- Next by Date: Re: Freepascal rocks!
- Previous by thread: Freepascal rocks!
- Next by thread: Re: Freepascal rocks!
- Index(es):
Relevant Pages
|