What general tips do you have for golfing code in Pascal?

I know this is a tricky language very few people use this but I would like to know any tips from the professionals out there :)

I'm looking for tips that can reduce code size (every byte counts!) with special functions or even crazy combinations

Please post each tip as a separate answer, and avoid tips not specific to Pascal (e.g. remove whitespace, etc.)


Avoid Integer

VAR var1: Integer; (* Signed, 16 bits in TP7, 32 bits in FPC, It costs 7 bytes. *)
    var2: Word;    (* Unsigned 16 bit, works in most cases. *)
    var3: Int64;   (* Signed 64 bits, Only available in FPC. *)
    var4: 0..9;    (* TP7: same as ShortInt (-128..127), FPC: same as Byte (0..255) *)

Use ^J for line break

Write('abc'^J'def');        (* Both in TP7 and FPC *)

^J is two bytes ^ followed by J, not single byte for Ctrl-J.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.