[Omake] allowing for lazy extends?
Aleksey Nogin
nogin at metaprl.org
Mon Jan 29 09:49:13 PST 2007
On 28.01.2007 16:04, Erick Tryzelaar wrote:
> Aleksey Nogin wrote:
>>> Without it, I run into all sorts of issues because "extends" forces
>>> evaluation, even if it's a lazy variable. So I have to do all sorts
>>> of hacks in order to avoid extending things until the last possible
>>> moment.
>>
>> Note that you can implement lazy extension yourself:
>
> Thanks for that! That does exactly what I want. I did notice that it
> does add some extra things (name, var, val) to my object, which I'm not
> sure is on purpose:
No - this was a combination of two unfortunate things:
1. In 0.9.8, the function arguments are scoped the exact same way as
object fields, so it is very easy to accidentally get function arguments
"spilled" into an object. This is something that 0.9.9 is supposed to
address, but for the time being it is very annoying.
2. I tried to address "1" by making keeping the "vars" variable and only
exporting the correct fields, but did not do it correctly - the vars was
always empty and "export $(EMPTY)" actually exports everything, not
nothing (I've filed http://bugzilla.metaprl.org/show_bug.cgi?id=636 ).
The correct form is:
lazy_extend(name) =
private.Obj = $(getvar $(name))
public.vars[] =
private.skip[] =
$'$class'
object-length
object-mem
object-add
object-find
object-map
object-foreach
lazy_update(var, val) =
if $(not $(mem $(var), $(private.skip)))
public.vars[] += $(var)
this = $(obj-add $(this), $(var), $`(obj-find $(getvar
$,(name)), $,(var)))
export vars $(public.vars)
export vars $(public.vars)
obj-map($(private.Obj), $(lazy_update))
export $(public.vars)
Aleksey
More information about the Omake
mailing list