Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better api for beReadOnlyObject #16799

Open
Ducasse opened this issue Jun 24, 2024 · 0 comments · May be fixed by #16831
Open

Better api for beReadOnlyObject #16799

Ducasse opened this issue Jun 24, 2024 · 0 comments · May be fixed by #16831

Comments

@Ducasse
Copy link
Member

Ducasse commented Jun 24, 2024

imagine the method

A >> returnAnArray
   ^ #(1 2 3) beReadonlyObject

A new returnAnArray 
returns true

Why ? Because

beReadOnlyObject
	"If the VM supports read-only objects it will not write to read-only objects.
	 An attempt to write to an instance variable of a read-only object will
	 cause the VM to send attemptToAssign:withIndex: to the read-only object.
	 An attempt to modify a read-only object in a primitive will cause the
	 primitive to fail with a #'no modification' error code.
	 Set the read-only flag of the receiver to true and answer the previous vaue of the flag."
	^self setIsReadOnlyObject: true

To avoid to force the receiver to define

experienceThree

	| a |
	a := #( 1 2 3).
	a beReadOnlyObject.
	^ a

About beReadOnlyObject, is it the previous value of the flag used?
We could have two APIs beReadOnlyObject and setIsReadOnlyObject:
with beReadOnlyObject defined as

beReadOnlyObject
	"If the VM supports read-only objects it will not write to read-only objects.
	 An attempt to write to an instance variable of a read-only object will
	 cause the VM to send attemptToAssign:withIndex: to the read-only object.
	 An attempt to modify a read-only object in a primitive will cause the
	 primitive to fail with a #'no modification' error code.
	 Set the read-only flag of the receiver to true and answer the previous vaue of the flag."
	self setIsReadOnlyObject: true.
        ^ self 

and if the user needs the old value just uses setIsReadOnlyObject:

fouziray added a commit to fouziray/pharo that referenced this issue Jun 28, 2024
@fouziray fouziray linked a pull request Jun 28, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant