Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 521493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:15:22+00:00 2026-05-13T08:15:22+00:00

I want to be able to modify Object dynamically by adding / removing properties

  • 0

I want to be able to modify Object dynamically by adding / removing properties or methods on the fly. For Adding no problem, for Removing I thought about using Set Difference Math Operator but it behaves weirdly as far as I can see when removing a method from the object.

For example if I have

O: make object! [
    a: 1        
    f: func [][]
    b: 1
]

I can substract [a: 1 b: 1] with no problem

>> difference third O [b: 1 a: 1]
== [f: func [][]]

But I cannot substract f: func[][]:

>> difference third O [f: func[][]]
== [a: 1 b: func [][] func []]
>>

Output is weird (I put strange maybe it doesn’t sound english as I’m not english native 🙂 )

Why and what should I do instead ?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T08:15:22+00:00Added an answer on May 13, 2026 at 8:15 am

    Issue #1: Difference Discards Duplicates From Both Inputs

    Firstly, difference shouldn’t be thought of as a “subtraction” operator. It gives you one of each element that is unique in each block:

    >> difference [1 1 2 2] [2 2 2 3 3 3]
    == [1 3]
    
    >> difference [2 2 2 3 3 3] [1 1 2 2]
    == [3 1]
    

    So you’d get an equivalent set by differencing with [a: 1 b: 1] and [1 a: b:]. This is why the second 1 is missing from your final output. Even differencing with the empty set will remove any duplicate items:

    >> difference [a: 1 b: 1] []
    == [a: 1 b:]
    

    If you’re looking to actually search and replace a known sequential pattern, then what you want is more likely replace with your replacement as the empty set:

    >> replace [a: 1 b: 1] [b: 1] []
    == [a: 1]
    

    Issue #2: Function Equality Is Based On Identity

    Two separate functions with the same definition will evaluate to two distinct function objects. For instance, these two functions both take no parameters and have no body, but when you use a get-word! to fetch them and compare they are not equal:

    >> foo: func [] []
    >> bar: func [] []
    
    >> :foo == :bar
    == false
    

    So another factor in your odd result is that f: is being subtracted out of the set, and the two (different) empty functions are unique and thus both members of the differenced set.

    R2 is a little weirder than R3 and I can’t get :o/f to work. But the following is a way to get an ”artificially correct-looking version” of the difference you are trying to achieve:

    >> foo: func [] []
    
    >> o: make object! [a: 1 f: :foo b: 2]
    
    >> difference third o compose [f: (:foo)]  
    == [a: 1 b: 2]
    

    Here you’re using the same function identity that you put in the object in the block you are subtracting.

    In R3, difference does not support function values in this way. It may relate to the underlying implementation being based on map! which cannot have ”function values” as keys. Also in Rebol 3, using difference on an object is not legal. So even your first case won’t work. 🙁

    Issue #3: This isn’t how to add and remove properties

    In Rebol 3 you can add properties to an object dynamically with no problems.

    >> obj: object [a: 1]
    == make object! [
        a: 1
    ]
    
    >> append obj [b: 2]
    == make object! [
       a: 1
       b: 2
    ]
    

    But as far as I know of, you cannot remove them once they have been added. You can set them to none of course, but the reflection APIs will still report them as being there.

    If you want to make trying to read them throw an error you can set it to an error object and then protect them from reads. A variant of this also works in R2:

    >> attempt [obj/b: to-error "invalid member"]
    == none
    
    >> probe obj
    == make object! [
        a: 1
        b: make error! [
            code: 800
            type: 'User
            id: 'message
            arg1: "invalid member"
            arg2: none
            arg3: none
            near: none
            where: none
        ]
    ]
    
    >> obj/b
    ** User error: "invalid member"
    

    R3 takes this one step further and lets you protect the member from writes, and even hide the member from having any new bindings made to it.

    >> protect 'obj/b
    == obj/b
    
    >> obj/b: 100
    ** Script error: protected variable - cannot modify: b
    
    >> protect/hide 'obj/b
    == obj/b
    
    >> obj
    == make object! [
        a: 1
    ]
    

    If you need to dynamically add and remove members in R2, you might also consider a data member in your object which is a block. Blocks and objects are interchangeable for many operations, e.g:

    >> data: [a: 1 b: 2]
    == [a: 1 b: 2]
    
    >> data/a
    == 1
    
    >> data/b
    == 2
    

    And you can remove things from them…

    >> remove/part (find data (to-set-word 'a)) 2
    == [b: 2]
    

    It all depends on your application. The main thing object! has going over block! is the ability to serve as a context for binding words…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 383k
  • Answers 383k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Your above code for configuring the DatePicker should be in… May 14, 2026 at 10:49 pm
  • Editorial Team
    Editorial Team added an answer You need to call the method on a new Thread,… May 14, 2026 at 10:48 pm
  • Editorial Team
    Editorial Team added an answer Looks like there's no easy way to convert them. These… May 14, 2026 at 10:48 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.