Re: Freepascal rocks!



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.
.



Relevant Pages

  • Re: FreeBSD Programming
    ... Learn Fortran 95. ... >> pursue a career in either, then Fortran 95 is the language ... Lisp is by no means just for emacs programming. ...
    (comp.unix.bsd.freebsd.misc)
  • Re: Request for comment: follow-up to Summer of Code
    ... > (FORTRAN (MATMUL X Y IDIM) ... > just prefer Lisp. ... the point of the translation results was to show that there were ... But benchmarks are always transitory and saying one language is better than ...
    (comp.lang.lisp)
  • Re: thoughts on dynamic from a beginners perspective
    ... working engineering and heavy duty numerical codes from Fortran to ... reason to translate good code from another language. ... mainly talked about optimizing Lisp to run faster. ... I didn't see any reason not to use Lisp. ...
    (comp.programming)
  • Re: C++ sucks for games
    ... > Hopefully he'll end up with Lisp eventually, but maybe he's happy as he is. ... In Lisp you can just integrate the custom language into the program, ... Programmers who think in Fortran tend to believe that all languages ... fingers to spit out the translation. ...
    (comp.lang.cpp)
  • Re: C++ sucks for games
    ... > Hopefully he'll end up with Lisp eventually, but maybe he's happy as he is. ... In Lisp you can just integrate the custom language into the program, ... Programmers who think in Fortran tend to believe that all languages ... fingers to spit out the translation. ...
    (comp.lang.lisp)