r/ryelang • u/middayc • 24d ago
Output-intent, input-intent ... or a Runtime Effect-like System?
I was quite enthusiastic about the idea of output-intent and input-intent when I created it ... dry-run mode, scenario mode, etc ..., but it didn't really click with any of the readers/users. I kept working on this, exploring the subject, and came to languages with effect systems. With languages like Koka, Unison, OCaml ... these are mostly strongly typed functional languages, bordering research languages. And there the effect system is based on types, ... to say ... it's not really runtime dynamic, like Rye is.
Rye is a runtime homoiconic language and the effect-related-system (yes, I changed the word intent for effect, so now we have input-effect and output-effect) is also fully runtime oriented ... i.e. dynamic.
I saw some related ideas, not in general purpose dynamic languages, but things like Terraform and Ansible. This made me add rye CLI flags --eff-ask and --eff-confirm
These are very simple flags, but add a lot to Rye runtime behaviour. Meaning, you can use a normal Rye script in fully new ways, with new guarantees, checks and options.
Minimal example of using --eff-ask mode:
--useLinux >> cat 05-ask.rye
; Run:
; rye -eff-ask 05-ask.rye
;
; Press Enter to keep the provided value, or type a new value.
; Typed value is checked with the same validation dialect.
port: input-effect 'port { integer } { first Load %.port.val }
print join [ "Using port: " port ]
--useLinux >> rye 05-ask.rye
Using port: 8080
--useLinux >> rye --eff-ask 05-ask.rye
port [8080]: HELLO
invalid port: not integer
port [8080]: 1234
Using port: 1234 And example of using --eff-confirm
--useLinux >> cat 04-confirm.rye
; Run:
; rye -eff-confirm 04-confirm.rye
;
; Answer y to run an effect, or n/just Enter to skip it.
output-effect 'first "one" {
print "ran first effect"
}
output-effect 'second "two" {
print "ran second effect"
}
print "Script finished."
--useLinux >> rye 04-confirm.rye
ran first effect
ran second effect
Script finished.
--useLinux >> rye --eff-confirm 04-confirm.rye
run first: one? [y/N]
run second: two? [y/N] y
ran second effect
Script finished.I hope you see some use in this, because I sure do :) ... Both ask and confirm modes should also allow have option where you can ask / confirm just specific effect blocks. For a large script you probably don't want to provide all the inputs, but just some. Or confirm all the outputs.
There are plenty more ideas, also for audit of effect, and mode where code needs to have all effecting functions inside effect blocks, but this is multiple iterations in the future still.
What you see above should be available in Rye v0.2.81 release, so follow us on: https://github.com/refaktor/rye/