2021-08-09 23:58:40 -04:00
(with_import "./collections.kp"
(let (
2021-09-06 03:00:33 -04:00
; For right now we only support calling partial_eval in such a way that it partial evals against
; the root env, but this is could and really should be extended. We could at least check if the env we're called with
; is the root_env, or if what we look up in whatever env is passed in matches something in the root env
; Care should also be taken when evaluating outside combinators to have them be in the right env, etc
2021-08-09 23:58:40 -04:00
; Here is every form in k'
; True
; False
; Env: *KPEnv
; Combiner: KPCombiner / BuiltinCombiner: KPBuiltinCombiner
; String: str
; Symbol: str
; Int: int
; Array: rc<vec<KPValue>>
; Nil
; Ok, some more things we need / need to change
2021-09-06 03:00:33 -04:00
; 1) meta...
; Honestly, I'm tempted to get rid of it
2021-08-09 23:58:40 -04:00
2021-09-05 00:25:33 -04:00
; !!!!!!!!!!!!!!!!!!!!!!!!!!
; ! To avoid exponential blowup due to evaluating function, then params, then function with params, etc etc
; ! Should probabally implement some form of evaluating to head-normal form controlled by boolean
; ! that quits as soon as it has any sort of value (I suppose the real change is only to combinators and arrays)
; ! so that we don't waste time re-trying etc. Anything in parameter position would be fully evaluated, so I don't think
; ! we'd waste overmuch, but it could make things less efficient I suppose...
; ! Maybe it's a bad idea - food for thought! Might need a better cacheing strategy
; !!!!!!!!!!!!!!!!!!!!!!!!!
2021-09-06 03:00:33 -04:00
; Possible marked values
; ['val v] - v is a value that evaluates to itself, and not a combiner or env, as those have their own metadata. Not an array or symbol
; That means it's true/false/a string/ an int/nil
; ['marked_array is_val a] - a contains marked values. if is_val, then it's the value version, and must be stripped back into (array ...),
; otherwise it's a calling form, and should be lowered back to (...). Also, if it's is_val, partial_eval won't perform a call, etc
; ['marked_symbol is_val s] - a symbol. is_val has the same meaning as in marked_array
; ['comb wrap_level de? se variadic params body <actual_function>] - A combiner. Contains the static env and the actual function, if possible.
; It is possible to have a combiner without an actual function, but that's only generated when
; we know it's about to be called and we won't have to strip-lower it
; ['prim_comb <handler_function> <actual_function>] - A primitive combiner! It has it's own special handler function to partial eval
; ['env [ ['symbol marked_value ]... <upper_marked_env> ] <actual_env>] - A marked env
2021-08-09 23:58:40 -04:00
2021-08-10 22:56:12 -04:00
val? (lambda (x) (= 'val (idx x 0)))
.val (lambda (x) (idx x 1))
marked_array? (lambda (x) (= 'marked_array (idx x 0)))
2021-09-06 03:00:33 -04:00
.marked_array_is_val (lambda (x) (idx x 1))
.marked_array_values (lambda (x) (idx x 2))
marked_symbol? (lambda (x) (= 'marked_symbol (idx x 0)))
.marked_symbol_is_val (lambda (x) (idx x 1))
.marked_symbol_value (lambda (x) (idx x 2))
later? (lambda (x) (or (and (marked_array? x) (= false (.marked_array_is_val x)))
(and (symbol? x) (= false (.symbol_is_val x)))))
2021-08-10 22:56:12 -04:00
comb? (lambda (x) (= 'comb (idx x 0)))
.comb (lambda (x) (slice x 1 -1))
prim_comb? (lambda (x) (= 'prim_comb (idx x 0)))
.prim_comb (lambda (x) (idx x 1))
marked_env? (lambda (x) (= 'env (idx x 0)))
2021-08-11 23:30:49 -04:00
.env_marked (lambda (x) (idx x 1))
.env_real (lambda (x) (idx x 2))
2021-08-10 22:56:12 -04:00
2021-08-16 00:37:56 -04:00
env-lookup-helper (rec-lambda recurse (dict key i fail success) (cond (and (= i (- (len dict) 1)) (= nil (idx dict i))) (fail)
2021-08-15 01:27:53 -04:00
(= i (- (len dict) 1)) (recurse (idx (idx dict i) 1) key 0 fail success)
(= key (idx (idx dict i) 0)) (success (idx (idx dict i) 1))
true (recurse dict key (+ i 1) fail success)))
2021-08-17 01:19:38 -04:00
env-lookup (lambda (env key) (env-lookup-helper (idx env 1) key 0 (lambda () (error (str key " not found in env " (idx env 1)))) (lambda (x) x)))
2021-08-15 01:27:53 -04:00
2021-09-06 03:00:33 -04:00
mark (rec-lambda recurse (x) (cond (env? x) (error (str "called mark with an env " x))
(combiner? x) (error (str "called mark with a combiner " x))
(symbol? x) ['marked_symbol false x]
(array? x) ['marked_array false (map recurse x)]
true ['val x]))
strip (rec-lambda recurse (x)
(do (println "calling strip with " x)
(cond (val? x) (.val x)
(marked_array? x) (let (stripped_vales (map recurse (.marked_array_values x)))
(if (.marked_array_is_val x) (cons array stripped_values)
stripped_values))
(marked_symbol? x) (if (.marked_symbol_is_val x) [quote (.marked_symbol_value x)]
(.marked_symbol_value x))
(comb? x) (let (c (idx x 7))
(if (= nil c) (error (str "partial eval failed: regular stripping a combinator without a real combinator (due to nil enviornment, no doubt, but how?)" x))
c))
(prim_comb? x) (idx x 2)
(marked_env? x) (error "Env escaped to strip!")
true (error (str "some other strip? " x))
))
)
; A bit wild, but what if instead of is_value we had an evaluation level integer, kinda like wrap?
; when lowering, it could just turn into multiple evals or somesuch, though we'd have to be careful of envs...
try_unval (rec-lambda recurse (x)
(cond (marked_array? x) (if (not (.marked_array_is_val x)) [false nil]
(let ([sub_ok subs] (foldl (lambda ([ok a] x) (let ([nok p] (recurse x))
[(and ok nok) (concat a [p])]))
[true []]
(.marked_array_values x)))
(if sub_ok [true ['marked_array false subs]]
[false nil])))
(marked_symbol? x) (if (.marked_symbol_is_val x) [true ['marked_symbol false (.marked_symbol_value x)]]
[false nil])
true x
)
)
try_unval_array (lambda (x) (foldl (lambda ([ok a] x) (let ([nok p] (try_unval x))
[(and ok nok) (concat a [p])]))
[true []]
x))
2021-08-23 23:43:47 -04:00
; This is a conservative analysis, since we can't always tell what constructs introduce
; a new binding scope & would be shadowing... we should at least be able to implement it for
; vau/lambda, but we won't at first
closes_over_var_from_this_env_marked (rec-lambda recurse (env x) (cond
2021-09-06 03:00:33 -04:00
(val? x) false
(marked_symbol? x) (env-lookup-helper (concat (slice (idx env 1) 0 -2) [nil]) (.marked_symbol_value x) 0 (lambda () false) (lambda (x) [x]))
(marked_array? x) (foldl (lambda (a x) (or a (recurse env x))) false (.marked_array_values x))
(comb? x) (let (
2021-08-26 01:03:36 -04:00
[wrap_level de? se variadic params body actual_function] (.comb x)
2021-09-06 03:00:33 -04:00
; This is where we'd be smart and remove shadowed stuff
2021-08-23 23:43:47 -04:00
; Also this won't work yet because env
(error (str "haven't handled comb yet really either for closes_over_var_from_this_env_marked " x))
) (or (recurse env se) (recurse env body)))
(prim_comb? x) false
; Should check to see if the env has anything form env in it, somehow? See if it has this env itself in it?
(marked_env? x) (error "haven't handled env in closes_over_var_from_this_env_marked!")
true (error (str "Something odd passed to closes_over_var_from_this_env_marked " x))
2021-09-06 03:00:33 -04:00
))
2021-08-23 23:43:47 -04:00
2021-08-22 13:03:33 -04:00
indent_str (rec-lambda recurse (i) (if (= i 0) ""
(str " " (recurse (- i 1)))))
2021-08-10 22:56:12 -04:00
2021-09-05 00:25:33 -04:00
2021-09-06 03:00:33 -04:00
partial_eval_helper (rec-lambda recurse (x env imm_eval indent)
(cond (val? x) x
(marked_env? x) x
(comb? x) x
(prim_comb? x) x
(marked_symbol? x) (if (.marked_symbol_is_val x) x
(env-lookup env (.marked_symbol_value x)))
(marked_array? x) (cond (.marked_array_is_val x) x
(= 0 (len (.marked_array_values x))) (error "Partial eval on empty array")
true (let (values (.marked_array_values x)
comb (recurse (idx values 0) env true (+ 1 indent))
literal_params (slice values 1 -1)
_ (println (indent_str indent) "Going to do an array call!")
_ (println (indent_str indent) " total is " x)
_ (println (indent_str indent) " evaled comb is " comb)
2021-08-23 23:43:47 -04:00
)
2021-09-06 03:00:33 -04:00
; Replacing the old note here with one that mentions that
; we use the imm_eval to know if it's ok to generate
; comb's without a real combiner (because it doesn't have a real env)
; because in the imm_eval case we don't need a real combiner since
; we're about to partial eval the call away
(cond (later? comb) ['marked_array false (cons comb literal_params)]
(prim_comb? comb) ((.prim_comb comb) env literal_params imm_eval (+ 1 indent))
2021-08-10 22:56:12 -04:00
(comb? comb) (let (
2021-08-26 01:03:36 -04:00
[wrap_level de? se variadic params body actual_function] (.comb comb)
2021-09-06 03:00:33 -04:00
[ok appropriatly_evaled_params] ((rec-lambda param-recurse (wrap params)
2021-08-15 01:27:53 -04:00
(if (!= 0 wrap)
2021-09-06 03:00:33 -04:00
(let ([ok unval_params] (try_unval_array params))
(if (not ok) [ok nil]
(let (evaled_params (map (lambda (p) (recurse p env false (+ 1 indent)))
unval_params))
(param-recurse (- wrap 1) evaled_params))))
[true params])
) wrap_level literal_params)
) (if (not ok) ['marked_array false (cons comb literal_params)]
2021-09-05 00:25:33 -04:00
(let (
2021-08-26 01:03:36 -04:00
final_params (if variadic (concat (slice appropriatly_evaled_params 0 (- (len params) 1))
2021-09-06 03:00:33 -04:00
[['marked_array true (slice appropriatly_evaled_params (- (len params) 1) -1)]])
2021-08-26 01:03:36 -04:00
appropriatly_evaled_params)
2021-08-17 01:19:38 -04:00
de_entry (if (!= nil de?) [ [de? env] ] [])
2021-08-26 01:03:36 -04:00
_ (println (indent_str indent) "final_params params " final_params)
2021-08-22 13:03:33 -04:00
de_real_entry (if (!= nil de?) [ [de? (.env_real env)] ] [])
2021-08-17 01:19:38 -04:00
se_real_env (.env_real se)
2021-08-22 13:03:33 -04:00
inner_real_env (if (and se_real_env (or (not de?) (.env_real env)))
2021-08-17 01:19:38 -04:00
(add-dict-to-env se_real_env
2021-08-26 01:03:36 -04:00
(concat (zip params (map strip final_params))
2021-08-17 01:19:38 -04:00
de_real_entry))
nil)
2021-08-22 13:03:33 -04:00
_ (println (indent_str indent) "Inner_real_env is " inner_real_env " because de_real " de_real_entry " se_real_env " se_real_env)
2021-08-26 01:03:36 -04:00
inner_env ['env (concat (zip params final_params) de_entry [se]) inner_real_env]
2021-08-22 13:03:33 -04:00
_ (println (indent_str indent) "going to eval " body " with inner_env is " inner_env)
2021-08-23 23:43:47 -04:00
; Ok, this might be a later with un-evaled references to parameter symbols,
; in which case we need to re-wrap up in a vau, since
; if they're used as parameters to a 'later value that might be a vau,
; since we don't know if they have to be evaluated and thus
2021-08-17 01:19:38 -04:00
; can't partially evaluate them.
2021-08-23 23:43:47 -04:00
; We check with closes_over_var_from_this_env_marked, which can be made more
; sophisticated, see its definition
2021-09-06 03:00:33 -04:00
func_result (recurse body inner_env imm_eval (+ 1 indent))
2021-08-23 23:43:47 -04:00
_ (println (indent_str indent) "evaled result of function call (imm_eval was " imm_eval ") is " func_result)
result (if (and (later? func_result)
(closes_over_var_from_this_env_marked inner_env func_result))
2021-09-06 03:00:33 -04:00
; this is exponential-y - we retry without imm to see if we can
; have a better partial eval'd later instead of giving up entirely
(let (comb (recurse (idx values 0) env false (+ 1 indent)))
['marked_array false (cons comb literal_params)])
func_result)
2021-09-05 00:25:33 -04:00
) result)))
2021-09-06 03:00:33 -04:00
true (error (str "Partial eval noticed that you will likely call not a function " comb " total is " x)))))
true (error (str "impossible partial_eval value " x))
2021-08-09 23:58:40 -04:00
)
)
2021-09-06 03:00:33 -04:00
is_all_values (lambda (evaled_params) (foldl (lambda (a x) (and a (not (later? x)))) true evaled_params))
2021-08-10 22:56:12 -04:00
needs_params_val_lambda (vau de (f_sym) (let (
actual_function (eval f_sym de)
2021-09-06 03:00:33 -04:00
handler (rec-lambda recurse (de params imm_eval indent) (let (
evaled_params (map (lambda (p) (partial_eval_helper x de false (+ 1 indent))) params)
2021-08-11 23:30:49 -04:00
)
2021-09-06 03:00:33 -04:00
(if (is_all_values evaled_params) (mark (lapply actual_function (map strip evaled_params)))
['marked_array false (cons ['prim_comb recurse actual_function] evaled_params)])))
2021-08-10 22:56:12 -04:00
) [f_sym ['prim_comb handler actual_function]]))
2021-09-06 03:00:33 -04:00
give_up_eval_params (vau de (f_sym) (let (
2021-08-10 23:26:22 -04:00
actual_function (eval f_sym de)
2021-09-06 03:00:33 -04:00
handler (rec-lambda recurse (de params imm_eval indent) (let (
evaled_params (map (lambda (p) (partial_eval_helper x de false (+ 1 indent))) params)
)
['marked_array false (cons ['prim_comb recurse actual_function] evaled_params)]))
2021-08-10 23:26:22 -04:00
) [f_sym ['prim_comb handler actual_function]]))
2021-08-10 22:56:12 -04:00
2021-09-06 03:00:33 -04:00
; !!!!!!
; ! I think needs_params_val_lambda should be combined with parameters_evaled_proxy
; !!!!!!
parameters_evaled_proxy (rec-lambda recurse (pasthr_ie inner_f) (lambda (de params imm_eval indent) (let (
[evaled_params l] (foldl (lambda ([ac i] p) (let (p (partial_eval_helper p de (if (= i pasthr_ie) imm_eval false) (+ 1 indent)))
[(concat ac [p]) (+ i 1)]))
[[] 0]
params)
) (inner_f (lambda (& args) (lapply (recurse passthrough_ie inner_f) args)) de evaled_params imm_eval indent))))
2021-08-17 20:31:07 -04:00
2021-08-11 23:30:49 -04:00
root_marked_env ['env [
; Ok, so for combinators, it should partial eval the body.
; It should then check to see if the partial-evaled body has closed over
; any 'later values from above the combinator. If so, the combinator should
; evaluate to a ['later [vau de? params (strip partially_evaled_body)]], otherwise it can evaluate to a 'comb.
; Note that this 'later may be re-evaluated later if the parent function is called.
2021-09-06 03:00:33 -04:00
['vau ['prim_comb (rec-lambda recurse (de params imm_eval indent) (let (
2021-08-15 01:27:53 -04:00
de? (if (= 3 (len params)) (idx params 0))
2021-08-16 11:54:05 -04:00
vau_de? (if (= nil de?) [] [de?])
2021-08-26 01:03:36 -04:00
[variadic vau_params] (foldl (lambda ([v a] x) (if (= x '&) [true a] [v (concat a [x])])) [false []] (if (= nil de?) (idx params 0) (idx params 1)))
2021-08-15 01:27:53 -04:00
body (if (= nil de?) (idx params 1) (idx params 2))
2021-09-06 03:00:33 -04:00
inner_env ['env (concat (map (lambda (p) [p ['marked_symbol false p]]) vau_params) (if (= nil de?) [] [ [de? ['marked_symbol false de?]] ]) [de]) nil]
2021-08-23 23:43:47 -04:00
_ (println (indent_str indent) "in vau, evaluating body with 'later params - " body)
2021-09-06 03:00:33 -04:00
pe_body (partial_eval_helper body inner_env false (+ 1 indent))
2021-08-23 23:43:47 -04:00
_ (println (indent_str indent) "in vau, result of evaluating body was " pe_body " stripping")
2021-08-22 13:03:33 -04:00
for_later (= nil (.env_real de))
2021-08-23 23:43:47 -04:00
_ (println (indent_str indent) "imm_eval is " imm_eval " and for_later is " for_later " for " params " because of env being null " de)
2021-09-06 03:00:33 -04:00
) (if for_later (if (not imm_eval) ['marked_array false (concat [['prim_comb recurse vau]] vau_de? [vau_params pe_body])]
['comb 0 de? de variadic vau_params pe_body nil])
(let (real_func (eval (concat [vau] vau_de? [vau_params (strip pe_body)]) (.env_real de))
marked_func ['comb 0 de? de variadic vau_params pe_body real_func]
2021-08-22 20:27:48 -04:00
_ (println (indent_str indent) "Marked func is " marked_func)
2021-09-06 03:00:33 -04:00
) marked_func)))
2021-08-15 01:27:53 -04:00
) vau]]
2021-08-23 23:43:47 -04:00
2021-09-06 03:00:33 -04:00
['wrap ['prim_comb (parameters_evaled_proxy 0 (lambda (recurse de [evaled] imm_eval indent)
2021-08-26 01:03:36 -04:00
(if (comb? evaled) (let ([wrap_level de? se variadic params body actual_function] (.comb evaled)
2021-08-23 23:43:47 -04:00
wrapped_actual_fun (if (= nil actual_function) nil (wrap actual_function))
2021-08-26 01:03:36 -04:00
wrapped_marked_fun ['comb (+ 1 wrap_level) de? se variadic params body wrapped_actual_fun]
2021-09-06 03:00:33 -04:00
) wrapped_marked_fun)
['marked_array false [['prim_comb recurse wrap] evaled]]))
2021-08-16 01:20:10 -04:00
) wrap]]
2021-09-06 03:00:33 -04:00
['unwrap ['prim_comb (parameters_evaled_proxy 0 (lambda (recurse de [evaled] imm_eval indent)
2021-08-26 01:03:36 -04:00
(if (comb? evaled) (let ([wrap_level de? se variadic params body actual_function] (.comb evaled)
2021-08-23 23:43:47 -04:00
unwrapped_actual_fun (if (= nil actual_function) nil (unwrap actual_function))
2021-08-26 01:03:36 -04:00
unwrapped_marked_fun ['comb (- wrap_level 1) de? se variadic params body unwrapped_actual_fun]
2021-09-06 03:00:33 -04:00
) unwrapped_marked_fun)
['marked_array false [['prim_comb recurse wrap] evaled]]))
2021-08-16 01:20:10 -04:00
) unwrap]]
2021-08-11 23:30:49 -04:00
2021-09-06 03:00:33 -04:00
['eval ['prim_comb (rec-lambda recurse (de params imm_eval indent) (let (
self ['prim_comb recurse eval]
eval_env (if (= 2 (len params)) (partial_eval_helper (idx params 1) de false (+ 1 indent))
de)
) (if (not (marked_env? eval_env)) ['marked_array false (cons self params)]
2021-08-17 01:19:38 -04:00
(let (
2021-08-22 13:03:33 -04:00
_ (println (indent_str indent) "ok, env was " eval_env)
2021-09-06 03:00:33 -04:00
body (partial_eval_helper (idx params 0) de imm_eval (+ 1 indent))
_ (println (indent_str indent) "after first eval of param " body)
[ok unval_body] (try_unval body1))
body2 (if ok (partial_eval_helper unval_body eval_env imm_eval (+ 1 indent))
['marked_array false (cons self (if (= 2 (len params)) [body1 eval_env]
[body1]))])
_ (println (indent_str indent) "and body2 is " body2)
) body2)
)) eval]]
2021-08-23 23:43:47 -04:00
;TODO: This could go a lot farther, not stopping after the first 'later, etc
; Also, GAH on odd params - but only one by one - a later odd param can't be imm_eval cuz it will
; be frozen if an earlier cond is 'later....
2021-09-06 03:00:33 -04:00
['cond ['prim_comb (parameters_evaled_proxy nil (lambda (recurse de evaled_params imm_eval indent)
2021-08-17 20:31:07 -04:00
(if (!= 0 (% (len evaled_params) 2)) (error (str "partial eval cond with odd evaled_params " evaled_params))
2021-09-06 03:00:33 -04:00
((rec-lambda recurse_inner (i)
(cond (later? (idx evaled_params i)) ['marked_array false (cons ['prim_comb recurse cond] (slice evaled_params i -1))]
(false? (idx evaled_params i)) (recurse_inner (+ 2 i))
true (idx evaled_params (+ 1 i))) ; we could partially_eval again passing in immediate
; eval if it was true, to partially counteract the above GAH
2021-08-17 20:31:07 -04:00
) 0)
)
)) cond]]
2021-08-10 22:56:12 -04:00
(needs_params_val_lambda symbol?)
(needs_params_val_lambda int?)
(needs_params_val_lambda string?)
2021-08-23 23:43:47 -04:00
; not even a gah, but kinda!
2021-09-06 03:00:33 -04:00
['combiner? ['prim_comb (parameters_evaled_proxy nil (lambda (recurse de [evaled_param] imm_eval indent)
(cond (comb? evaled_param) ['val true]
(prim_comb? evaled_param) ['val true]
(later? evaled_param) ['marked_array false [['prim_comb recurse combiner?] evaled_param]]
true ['val false]
2021-08-17 20:31:07 -04:00
)
)) combiner?]]
2021-08-23 23:43:47 -04:00
; not even a gah, but kinda!
2021-09-06 03:00:33 -04:00
['env? ['prim_comb (parameters_evaled_proxy nil (lambda (recurse de [evaled_param] imm_eval indent)
(cond (marked_env? evaled_param) ['val true]
(later? evaled_param) ['marked_array false [['prim_comb recurse env?] evaled_param]]
true ['val false]
2021-08-17 20:31:07 -04:00
)
)) env?]]
2021-08-10 22:56:12 -04:00
(needs_params_val_lambda nil?)
(needs_params_val_lambda bool?)
(needs_params_val_lambda str-to-symbol)
(needs_params_val_lambda get-text)
2021-09-06 03:00:33 -04:00
['array? ['prim_comb (parameters_evaled_proxy nil (lambda (recurse de [evaled_param] imm_eval indent)
(cond
(later? evaled_param) ['marked_array false [['prim_comb recurse array?] evaled_param]]
(marked_array? evaled_param) ['val true]
true ['val false]
2021-08-17 23:09:42 -04:00
)
)) array?]]
2021-09-06 03:00:33 -04:00
['array ['prim_comb (parameters_evaled_proxy nil (lambda (recurse de evaled_params imm_eval indent)
['marked_array true evaled_params]
2021-08-17 23:09:42 -04:00
)) array]]
2021-09-06 03:00:33 -04:00
['len ['prim_comb (parameters_evaled_proxy nil (lambda (recurse de [evaled_param] imm_eval indent)
(cond (later? evaled_param) ['marked_array false [['prim_comb recurse len] evaled_param]]
(marked_array? evaled_param) ['val (len (.marked_array_values evaled_param))]
true (error (str "bad type to len " evaled_param))
2021-08-17 23:09:42 -04:00
)
)) len]]
2021-09-06 03:00:33 -04:00
['idx ['prim_comb (parameters_evaled_proxy nil (lambda (recurse de [evaled_array evaled_idx] imm_eval indent)
(cond (and (val? evaled_idx) (marked_array? evaled_array) (.marked_array_is_val evaled_array)) (idx (.marked_array_values evaled_array) (.val evaled_idx))
true ['marked_array false [['prim_comb recurse idx] evaled_array evaled_idx]]
2021-08-17 23:09:42 -04:00
)
)) idx]]
2021-09-06 03:00:33 -04:00
['slice ['prim_comb (parameters_evaled_proxy nil (lambda (recurse de [evaled_array evaled_begin evaled_end] imm_eval indent)
(cond (and (val? evaled_begin) (val? evaled_end) (marked_array? evaled_array) (.marked_array_is_val evaled_array))
['marked_array true (slice (.marked_array_values evaled_array) (.val evaled_begin) (.val evaled_end))]
true ['marked_array false [['prim_comb recurse slice] evaled_array evaled_idx evaled_begin evaled_end]]
2021-08-17 23:09:42 -04:00
)
)) slice]]
2021-09-06 03:00:33 -04:00
['concat ['prim_comb (parameters_evaled_proxy nil (lambda (recurse de evaled_params imm_eval indent)
(cond (foldl (lambda (a x) (and a (and (marked_array? x) (.marked_array_is_val x))) true evaled_params) ['marked_array true (lapply concat (map (lambda (x)
(.marked_array_values x))
evaled_params))]
true ['marked_array false (cons ['prim_comb recurse concat] evaled_params)]
2021-08-17 23:09:42 -04:00
)
2021-09-06 03:00:33 -04:00
))) concat]]
2021-08-10 22:56:12 -04:00
(needs_params_val_lambda +)
(needs_params_val_lambda -)
(needs_params_val_lambda *)
(needs_params_val_lambda /)
(needs_params_val_lambda %)
(needs_params_val_lambda &)
(needs_params_val_lambda |)
(needs_params_val_lambda <<)
(needs_params_val_lambda >>)
(needs_params_val_lambda =)
(needs_params_val_lambda !=)
(needs_params_val_lambda <)
(needs_params_val_lambda <=)
(needs_params_val_lambda >)
(needs_params_val_lambda >=)
2021-08-09 23:58:40 -04:00
2021-09-06 03:00:33 -04:00
; these could both be extended to eliminate other known true values except for the end and vice-versa
['and ['prim_comb (parameters_evaled_proxy nil (lambda (recurse de evaled_params imm_eval indent)
((rec-lambda inner_recurse (i)
(cond (= i (- (len evaled_params) 1)) (idx evaled_params i)
(later? (idx evaled_params i)) ['marked_array false (cons ['prim_comb recurse and] (slice evaled_params i -1))]
(false? (idx evaled_params i)) (idx evaled_params i)
true (inner_recurse (+ 1 i)))
2021-08-17 23:09:42 -04:00
) 0)
)) and]]
2021-09-06 03:00:33 -04:00
; see above for improvement
['or ['prim_comb (parameters_evaled_proxy nil (lambda (recurse de evaled_params imm_eval indent)
((rec-lambda inner_recurse (i)
(cond (= i (- (len evaled_params) 1)) (idx evaled_params i)
(later? (idx evaled_params i)) ['marked_array false (cons ['prim_comb recurse or] (slice evaled_params i -1))]
(false? (idx evaled_params i)) (recurse (+ 1 i))
true (idx evaled_params i))
2021-08-17 23:09:42 -04:00
) 0)
)) or]]
2021-08-17 20:31:07 -04:00
; should make not a built in and then do here
2021-08-17 23:09:42 -04:00
; OR not - I think it will actually lower correctly partially evaled
2021-08-09 23:58:40 -04:00
2021-08-17 23:09:42 -04:00
(needs_params_val_lambda pr-str)
2021-08-10 22:56:12 -04:00
(needs_params_val_lambda str)
(needs_params_val_lambda prn)
2021-09-06 03:00:33 -04:00
(give_up_eval_params println)
2021-08-17 23:09:42 -04:00
; really do need to figure out if we want to keep meta, and add it if so
2021-09-06 03:00:33 -04:00
(give_up_eval_params meta)
(give_up_eval_params with-meta)
2021-08-17 23:09:42 -04:00
; if we want to get fancy, we could do error/recover too
2021-09-06 03:00:33 -04:00
(give_up_eval_params error)
(give_up_eval_params recover)
2021-08-17 23:09:42 -04:00
(needs_params_val_lambda read-string)
2021-09-06 03:00:33 -04:00
(give_up_eval_params slurp)
(give_up_eval_params get_line)
(give_up_eval_params write_file)
2021-08-11 23:30:49 -04:00
['empty_env ['env [] empty_env]]
2021-08-16 00:37:56 -04:00
nil
2021-08-11 23:30:49 -04:00
] root_env]
2021-09-06 03:00:33 -04:00
partial_eval (lambda (x) (partial_eval_helper (mark x) root_marked_env false 0))
2021-08-09 23:58:40 -04:00
)
2021-08-10 22:56:12 -04:00
(provide partial_eval strip)
2021-08-09 23:58:40 -04:00
))