Difference between mirror clear-assoc and delete-at #1757

Open
mrjbq7 opened this Issue Dec 4, 2016 · 5 comments

Projects

None yet

3 participants

@mrjbq7
Member
mrjbq7 commented Dec 4, 2016

I just noticed that in the mirrors vocabulary, theM\ mirror delete-at sets a slot to f:

M: mirror delete-at ( key mirror -- )
    [ f ] 2dip set-at ;

But the M\ mirror clear-assoc sets the slot to its initial value:

M: mirror clear-assoc ( mirror -- )
    [ object-slots ] [ object>> ] bi '[
        [ initial>> ] [ offset>> _ swap set-slot ] bi
    ] each ;

Probably those should be consistent?

@mrjbq7
Member
mrjbq7 commented Dec 5, 2016
IN: scratchpad TUPLE: foo { a integer initial: 12 } ;

IN: scratchpad T{ foo f 2 } dup make-mirror clear-assoc a>> .
12

IN: scratchpad T{ foo f 2 } "a" over make-mirror delete-at a>> .
Bad store to specialized slot
value f
class integer

Type :help for debugging help.
@mrjbq7
Member
mrjbq7 commented Dec 24, 2016

It also looks like M\ mirror clear-assoc doesn't respect read-only slots:

IN: scratchpad TUPLE: foo { a integer initial: 12 read-only } ;

IN: scratchpad T{ foo f 15 } dup make-mirror clear-assoc a>> .
12
@bjourne
Member
bjourne commented Dec 28, 2016

Imho, it would be better if clear-assoc and delete-at threw errors. They don't make sense because you can't remove slots from tuples. Its analogous to how you can't resize arrays -- you can't (or shouldn't be able to) resize mirrors.

@mrjbq7
Member
mrjbq7 commented Dec 28, 2016

You mean better if those words did not work and mirrors were effectively read-only?

@jonenst
Contributor
jonenst commented Dec 28, 2016

Mirrors wouldn't be read-only, you would still be able to modify the value of slots with set-at. I agree with @bjourne, clear-assoc and delete-at should throw for mirrors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment