0

Rust's tuples allow for an anonymous, packed, stack-allocated data-structure that holds multiple values.

Example:

let (a, b) = returns_tuple(); // fn returns_tuple() -> (i32, String);

In (free) pascal i'd do it with a named record type, i guess, but it will not let me destructure so i'd need a separate variable.

type
  Tuple = packed record
    a: integer;
    b: string;
  end;

var
  a: integer;
  b: string;
  t: tuple;
  
function returns_tuple (): Tuple;
{ function body ommited }

begin
  t := returns_tuple;
  a := t.a;
  b := t.b;
end.
glennsl
  • 28,186
  • 12
  • 57
  • 75
Soft Waffle
  • 356
  • 1
  • 12
  • No — Pascal pre-dates Rust by decades and AFAIK, the standard versions of Pascal include no such niceties. There's a chance that some modern implementation of Pascal has been augmented to do so, but it is very unlikely to be standardized. – Jonathan Leffler Oct 01 '20 at 16:11
  • @JonathanLeffler ISO and Extended pascal are limited and i don't think there will be new pascal standards soon, so maybe in free pascal – Soft Waffle Oct 01 '20 at 16:16
  • @JonathanLeffler though it should be noted that tuples (aka anonymous structs / anonymous records) predate rust by... probably 40 years at least? I don't know if the original ML had tuples but I believe every dialect of it does, so it would make sense. – Masklinn Oct 01 '20 at 16:23
  • @SoftWaffle: Are you interested in FreePascal or Delphi? These are the two modern Pascal dialects. – Andreas Rejbrand Oct 01 '20 at 16:25
  • @AndreasRejbrand FreePascal – Soft Waffle Oct 01 '20 at 16:27

1 Answers1

1

Afaik the only such anonymous (undeclared) structure in Delphi is the closure like state of an anonymous method, and Free Pascal doesn't even support that yet.

So no support, and I'm not aware of any plans. Pascal is generally big on typing.

If you really need to replace something working, you can try to build something on top of array of variant. If you only want it for the aesthetic, leave it.

Marco van de Voort
  • 25,628
  • 5
  • 56
  • 89