You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to understand how examples/record_inheritance.nelua works.
Particularly there is this line rectype.methods[name] = hygienize(function(f) f() end) which I understand to mean the original context of the function is enforced upon whatever is passed in to the function. This is then stored in a table which was patched in to the object type.
What I don't understand is this part:
##[[
local function override()
local fundefnode = context:get_visiting_node(1)[2]
local rectype, name = fundefnode[2].attr.value, fundefnode[1]
local method = rectype.base.methods[name]
method(function()]]
-- no problem to use ifs instead of switches because C compilers usually optimizes as a switch
if self.__kind == #[rectype.kindid]# then
return (@*#[rectype]#)(self):#|name|#()
end ##[[
end)
end
]]
I understand that it looks up the function that was just defined and pulls a reference to the type via the self parameter and then finds the original base method through that. But then it just calls the curried function and yet somehow this results in the clause being added to the original function? The description just says Wraps a function to into a hygienized function. A hygienized function can see only symbols and pragmas that were available at the time hygienize is called.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm trying to understand how
examples/record_inheritance.nelua
works.Particularly there is this line
rectype.methods[name] = hygienize(function(f) f() end)
which I understand to mean the original context of the function is enforced upon whatever is passed in to the function. This is then stored in a table which was patched in to the object type.What I don't understand is this part:
I understand that it looks up the function that was just defined and pulls a reference to the type via the self parameter and then finds the original base method through that. But then it just calls the curried function and yet somehow this results in the clause being added to the original function? The description just says
Wraps a function to into a hygienized function. A hygienized function can see only symbols and pragmas that were available at the time
hygienizeis called.
Beta Was this translation helpful? Give feedback.
All reactions