News for hackers. Stuff that matters.
Re:Optional If Expressions by haileys on Saturday April 15, 2023 @03:14AM (#35578387)
Would this not just return nil for the else case? This is already the behaviour of Ruby and Lua as well, of course both are unityped languages where "just return nil" semantics are the natural conclusion.

The OP however is discussing how this kind of thing would work in a language with a richer type system, like Rust.

Re:Optional If Expressions by SeanLuke on Saturday April 15, 2023 @07:34AM (#35579664)
I guess the Lisp example is an example of a nullable type, which he's railing against; he'd rather have prewrapped types like Some(result) vs None. But it's still an optional expression, and I'm not convinced that declaring an optional type, doing the expression(s), then unwrapping and checking the result for None, is any better than just using an exception handler. He insists that nullable types force you to check for null, but they don't, at least in his math example here. Just let the runtime do it and throw an exception.
Re:Optional If Expressions by f_devd on Saturday April 15, 2023 @08:02AM (#35579823)
> Just let the runtime do it and throw an exception.

Afaik there are no exceptions in rust only panics & `Result`s (and `Option` I suppose)

Re:Optional If Expressions by eyelidlessness on Saturday April 15, 2023 @01:04PM (#35582410)
It will typically return nil, but it’s worth noting that in some lisps nil is the same as the empty list (). Not quite the same as Option/None, but conceptually more similar than most other languages’ null types.