Hacker News new | ask | show | jobs
by vindarel 1261 days ago
> Just replace multiple-value-returns with structs, they don't add anything useful.

Oh yes they do! They allow to add a return value without modifying all the calling sites. Extremely useful.

2 comments

Algol based languages -> 1st order logic (implicit 'single' return)

algol languages array/stack with 'struct' abstract ('struc' abstract converted by compiler to ether parallel array(s) and/or array byte grouping per array ordinal index offset)

Lisp languages -> 2nd order logic (implicit nil/1 or many returns)

lisp is a tree / heap language where tree node is the 'implied' struct.

tree/heap much more flexible than fixed size array of strucs.

They also don't cons. Structs do.
Wrapping the multivalue return using decorators / generators would provide the 'struct' equivalent without rewriting to 'single' struct.

lisp approach to dectorators / generators disucssion. https://stackoverflow.com/questions/32956033/is-there-a-stra...

lisp -> 1-n; s-expression 1st element ins () is the "memory index"

structs -> n * M; "m-expression" 1st element outside of () is the "memory index".

cons struc vs. cons lisp () is apples/oranages comparison.

if convert both the 'cons struc' and the cons lisp () to same byte vector/stack or equivalent byte tree/heap, then yes, both 'cons' functions are equivalent.

higher order equivalent of mealy state machine vs. moore state machine. [1]

side note: ( 1 - n ) vs (n * m) is context reference to ploting base 2 log(x).

(1 - n ) can never exceed 1.

N * M, relative to (1 - n) is unbounded.

=====

[1] : https://www.geeksforgeeks.org/difference-between-mealy-machi...