BlockstreamResearch / simfony

Rust-like high-level language that compiles down to Simplicity bytecode. Work in progress.
26 stars 9 forks source link

Pattern matching syntax #3

Closed uncomputable closed 6 months ago

uncomputable commented 10 months ago

(We renamed S-Lang to Simphony because S-Lang already exists)

The feature I needed most while writing Simphony programs was pattern matching: A jet returns an sum value / optional value and the program needs to react. I was wondering, @sanket1729, what kind of syntax you had in mind.

The README says that Simphony is based on JavaScript. AFAIU, there is no pattern matching in JavaScript.

Types are important in Simplicity, so maybe match or if-let statements like in Rust would be helpful.

Example from SIGHASH_SINGLE:

let sha2_ctx = if let Some(nonce) = jet_output_nonce(index) {
    jet_nonce_hash(sha2_ctx, nonce)
} else {
    sha2_ctx
};

Simphony always seemed like Rust to me, but I am not familiar with JavaScript, so there might be a bias.

apoelstra commented 10 months ago

We should definitely not copy the hideous if-let syntax from Rust :)

Rust's match syntax is pretty good.