5 ms·
It seems to me like this should be something that can be done using continuations in Scheme. I tried writing the first example: (define x 1) (define t
by Zambyte 3y ago
It seems to me like this should be something that can be done using continuations in Scheme. I tried writing the first example:
(define x 1)
(define t (now))
(display x)
(at t
(set! x 2))
and trying to implement now and at in a way that would behave correctly. I ran into a wall trying to implement it, because I don't think there is a way to define at that could reference the environment that t was defined in. Maybe a more powerful language like Kernel[0] could implement the same features, but I don't think Scheme can. Very cool!
Also FWIW here is the definition of now and at that I had before I decided to stop:
(define-syntax now
(syntax-rules ()
((_)
(call/cc
(lambda (k)
(lambda (at-body) (at-body) (k #f)))))))
(define-syntax at
(syntax-rules ()
((_ instant body1 body ...)
(instant (lambda () body1 body ...)))))
[0] https://web.cs.wpi.edu/~jshutt/kernel.html https://web.cs.wpi.edu/~jshutt/kernel.html
- rkagerer 3y agoI wonder if C macros would get you any further?
- tmtvl 3y agoYou could probably do it in the reflective language Black (<https://www.is.ocha.ac.jp/~asai/Black/ https://www.is.ocha.ac.jp/~asai/Black/>), but I'm gonna leave actually doing so as an exercise for someone who is interested.
- MathMonkeyMan 3y agoYou might have to require that any code that uses the now/at constructs be wrapped in a macro invocation, e.g. (with-time-travel ...). The with-time-travel macro would then be a syntax transformer that rewrites the program. I'm not sure how, though... you'd have to enumerate all of the code blocks that are inside "at" forms, and then conditionally dispatch to them in the expansion of the "now" form; but that doesn't quite work because (now) is a value, and so figuring out which "at" forms consume it is probably undecidable. You can't have all the cases in the expansion, either, because of the incompatible environments. It's an interesting problem, but one that I think is ok not to be able to solve in Scheme.
- autumn-antlers 3y agoIt's only legal for each `now` to be consumed by at-most one `at` form, so at that point you'd just be re-implementing the "timeline" and "instant" system from mariposa. The need to wrap the program in a form and the management of `now` "values" has me pondering the implications of IanTheHenry's macaroni[1] system, which (like the CSS :has operator) allow macros to climb up into manipulations of their parent forms-- the `now` macro could effectively wrap every remaining form in the program with a new context that augments eg. the closure of `at`. But indeed, perhaps a problem to not become too invested in :p 1: https://github.com/ianthehenry/macaroni https://github.com/ianthehenry/macaroni
- autumn-antlers 3y ago> perhaps a problem to not become too invested in uh, case in point, that hypothetical closure would have some difficulty crossing module boundries (and that's assuming it gets away with re-writing top-level define forms), but still nothing technically incomputable, just supremely ill-advised and still closer to a reimplimentation of mariposa's semantics than a truely native concept emerging out of the continuations system