Function proxy a la Misty #11

Open
opened 2025-05-28 18:46:06 +00:00 by john · 0 comments
Owner

Proxy

A function can be used as a proxy for a record. If a function is called as
function.name(input_value_a, input_value_b)
then the function will be called as though it had been written as
function("name", [input_value_a, input_value_b])
The function will be called with the name of the method and an array of input values. The result that is returned by the function will be given to the caller.
Example:
def my_record: {
a(value) (
"a-" & value
)
}

def pseudorecord(
name
input_values
) {
if function?(my_record[name])
return apply(my_record[name], input_values)
fi
log error: "something is wrong with" ≈ name
disrupt
}

function?(pseudorecord) # true
stone?(pseudorecord) # true
record?(pseudorecord) # false
length(pseudorecord) # 0
arity(pseudorecord) # 2

pseudorecord.a("ok") # "a-ok"
pseudorecord.b("ok") # disrupt

////

This would break some code, but not much, and would be as useful as the JS proxy, but more well defined, and thus faster

Proxy A function can be used as a proxy for a record. If a function is called as function.name(input_value_a, input_value_b) then the function will be called as though it had been written as function("name", [input_value_a, input_value_b]) The function will be called with the name of the method and an array of input values. The result that is returned by the function will be given to the caller. Example: def my_record: { a(value) ( "a-" & value ) } def pseudorecord( name input_values ) { if function?(my_record[name]) return apply(my_record[name], input_values) fi log error: "something is wrong with" ≈ name disrupt } function?(pseudorecord) # true stone?(pseudorecord) # true record?(pseudorecord) # false length(pseudorecord) # 0 arity(pseudorecord) # 2 pseudorecord.a("ok") # "a-ok" pseudorecord.b("ok") # disrupt //// This would break some code, but not much, and would be as useful as the JS proxy, but more well defined, and thus faster
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: john/cell#11
No description provided.