Skip to content

Instantly share code, notes, and snippets.

@marianposaceanu
Forked from ELLIOTTCABLE/gist:953017
Created January 28, 2014 19:11
Show Gist options
  • Save marianposaceanu/8674141 to your computer and use it in GitHub Desktop.
Save marianposaceanu/8674141 to your computer and use it in GitHub Desktop.
{
# First, we need to add an empty key/value tuple (just an empty fork) to this `execution`, in preperation for
# making a `locals` list to store variables on.
#
# ┌ - we have to assume that native juxtaposition of `infrastructure` against the root-level `execution` will
# │ somehow “fall through.” I haven’t yet figured out the semantics of Nuclear-level scoping/fall-through.
# │ - considering: if `<this> locals` nothingnesses-out, then we juxtapose against enclosing scope at the
# │ interpreter level (which would imply, at this root scope, juxtaposing against the global scope I suppose)
# │
# │ ┌ - no `call()` implemented at this level, so we have to assume that the native-default juxtaposition for
# │ │ `execution`s has `call()`-like semantics: `branch()` and then `stage()` for us.
# │ │
# │ │ ┌ - this is simply a hack to get a handle on “ourselves” (the running execution), so we don’t have to
# │ │ │ assume the presence of a `locals` or `this` or `callee` variable injected by the interpreter.
# │ │ │ Theoretically, it’s a native routine that simply calls back its caller, with a resumption value of,
# │ │ │ well, the caller.
# │ │ │
# │ │ │ ┌ - for the moment, we assume the Nuclear APIs are psuedo-currying-style. We might do something
# │ │ │ │ coroutine-based instead, but this works for now.
# │ │ │ └────────────────────────────────────────────────────┐
# │ │ └───────────────────────────────────────────────┐ │
# │ └───────────────────────┐ │ │
# V V V V
infrastructure fork affix (infrastructure execution me ()) (infrastructure fork create ())
# Next, we add a key (`locals`), and then a value (new empty fork), to that tuple
#
# ┌ - no `last` at this layer of abstraction, so we do this the verbose way.
# │
# │ ┌ - still a call, even though there’s no parenthesis; remember, parenthesis are just indirection. it’s
# │ │ *juxtaposition* against an `execution` that causes a call; so this is a bit like what you would *think*
# │ │ would look like `… blah (“locals”)`
# │ └────────────────────────────────────────────────────────────────────────────────────────────────┐
# └─────────────────────────────────────────────────────────┐ │
# V V
infrastructure fork affix (infrastructure execution me () (infrastructure execution me () length)) locals
infrastructure fork affix (infrastructure execution me () (infrastructure execution me () length)) (infrastructure fork create ())
# From here on out, we can have local variables in this routine! finally! :D
#
# So, no more `infrastructure execution me ()`. Storing that as `.`.
infrastructure fork affix (infrastructure execution me () locals) (infrastructure fork create ())
infrastructure fork affix (infrastructure execution me () locals 1) .
infrastructure fork affix (infrastructure execution me () locals 1) (infrastructure execution me ())
# Just to play with arugments a bit as an example, we’ll store the `left` and `right` sides of the juxtaposition.
#
# ┌ - assuming the presence of a natively-implemented `fork reverse()` routine, because I’m feeling lazy
# │
# │ ┌ - discussed resumption-value-as-parametrization, couldn’t make work for this example. for now, I’m assuming
# │ │ we take the really old plan, of simply storing the juxtaposition parameters the same way we eventually
# │ │ will libside: in a list on `<this> owners`. This means having the interpreter “know” about certain keys,
# │ │ but it’s 3:30 AM. whatever.
# │ └──────────────────────────────────────────────────────────────────────┐
# └──────────────────────────────────────────────────────────────────────┐ │
infrastructure fork affix (. locals) (infrastructure fork create ()) # │ │
infrastructure fork affix (. locals 2) left # V──────────┘ V
infrastructure fork affix (. locals 2) (infrastructure fork reverse (infrastructure fork clone (. owner 1)))
infrastructure fork affix (. locals) (infrastructure fork create ())
infrastructure fork affix (. locals 3) right
infrastructure fork affix (. locals 3) (. owner 2)
# The start of the actual algorithm. We use a subroutine to capture and store a branch of ourselves that we’ll
# return to. A simple list reduction.
infrastructure fork affix (. locals) (infrastructure fork create ())
infrastructure fork affix (. locals 4) here
infrastructure fork affix (. locals 4) {
infrastructure fork affix (. locals) (infrastructure fork create ())
infrastructure fork affix (. locals 5) goto
infrastructure fork affix (. locals 5) (infrastructure execution branch (.))
infrastructure execution stage (.) ()
}
infrastructure fork affix (here) (infrastructure fork create ())
infrastructure fork affix (here (here length)) locals
infrastructure fork affix (here (here length)) (. locals)
here ()
infrastructure fork affix (. locals) (infrastructure fork create ())
infrastructure fork affix (. locals 6) then
infrastructure fork affix (. locals 6) {
# how to get the result out of this routine? assuming old, fugly way: that interpreter dropped a `caller`
# on us.
infrastructure execution stage (. caller) (left 1 2)
}
infrastructure fork affix (then) (infrastructure fork create ())
infrastructure fork affix (then (then length)) locals
infrastructure fork affix (then (then length)) (. locals)
infrastructure fork affix (. locals) (infrastructure fork create ())
infrastructure fork affix (. locals 7) else
infrastructure fork affix (. locals 7) {
infrastructure fork delete (left) (1)
goto ()
}
infrastructure fork affix (else) (infrastructure fork create ())
infrastructure fork affix (else (else length)) locals
infrastructure fork affix (else (else length)) (. locals)
infrastructure if (infrastructure fork identical? (left 1 1) (right)) (then) (else)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment