Live data from Hacker News

Show HN: A small programming language where everything is pass-by-value

github.com

61–64 of 64 posts

Re: Show HN: A small programming language where everything is pass-by-value

#61

The threading story here is what grabbed my attention. Pass-by-value with copy-on-write means you get data-race immunity without any locks or channels. You just pass data to a thread and mutations stay local. That's a genuinely useful property. I've worked on systems where we spent more time reasoning about shared state than writing actual logic. The typical answer is "just make everything immutable" but then you los…

Swift actually does this copy-on-mutation strategy as well for its standard library’s container types like Array and Dictionary, and it does indeed make multithreaded programming much easier without requiring full copies. The downside is that you pay reference-counting overhead.

Re: Show HN: A small programming language where everything is pass-by-value

#62

Syntax comment: in your control structures you use a keyword ("do", "then") to start a block as well as wrapping the block in parentheses. This feels superfluous. I suggest sticking with either keywords or parens to delineate blocks, not both.

This is a little bit tricky because the parser has to distinguish between: for x in arr (something ()) \ /-- function call and for x in arr (something ()) \ /-- loop body This is consequence of combining "blocks" and "precedence" into the same construct (). A more fitting example would be to support: for x in arr do set z += x; for x in arr do something x; IIRC these both currently require an explicit block in my par…

I see, thanks for the clear example of the ambiguity you need to avoid! Fun stuff.

Re: Show HN: A small programming language where everything is pass-by-value

#63
post #60
post #8

Earlier quoted context omitted.

I'm not sure if I understand the question? There are two ways to define a variable binding: x = 1; // declares x as immutable var y = 2; // declares y as mutable The "default" behaviour (if no keyword is used) is to define a new immutable variable.

I'm asking if the reality wouldn't be that "everything" is set as mutable by default and the non mutable part is ignored.

In the programs I write probably about 80-90% of variables are immutable, and I think this probably corresponds to most other code. Except in certain domains and programming styles, not that much stuff tends to need mutability.

This is why the syntax "encourages" immutability by making it the easiest option (similar to e.g. Rust, F#). On the other hand, if it was an extra keyword nobody would use it (e.g. like Java).

Re: Show HN: A small programming language where everything is pass-by-value

#64

Nim has a similar, strong preference for value semantics. However, its dynamic heap types (strings, seqs, tables) are all implemented as wrappers that hide the internal references and behave with value semantics by default, unless explicitly escape hatched. It makes it incredibly easy to manipulate almost any data in a functional, expression-oriented manner, while preserving the speed and efficiency of being backed b…

that is exactly what this one is doing too, according to OP
Post reply on HN