-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
142: Add the 'fields' primitive. r=ptersilie a=ltratt This returns a class's fields. However, SOM's semantics on this are currently unclear (see SOM-st/SOM#40). Although we allow users to mutate the 'methods' array, this is less sensible with fields in my opinion, since it would turn SOM from a statically into a dynamically scoped language. Thus, each time you call 'fields' you get a fresh array back such that any mutations made are ignored (see the `mutate_fields` test). Co-authored-by: Laurence Tratt <[email protected]>
- Loading branch information
Showing
4 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
" | ||
VM: | ||
status: success | ||
stdout: | ||
instance of Array | ||
true | ||
true | ||
" | ||
|
||
instance_fields = ( | ||
| x y | | ||
run = ( | ||
| fds | | ||
fds := instance_fields fields. | ||
fds println. | ||
(fds contains: #x) println. | ||
(fds contains: #y) println. | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
" | ||
VM: | ||
status: success | ||
stdout: | ||
true | ||
true | ||
true | ||
true | ||
false | ||
" | ||
|
||
mutate_fields = ( | ||
| x y | | ||
run = ( | ||
| fds | | ||
fds := mutate_fields fields. | ||
(fds contains: #x) println. | ||
(fds contains: #y) println. | ||
fds at: 1 put: #z. | ||
fds := mutate_fields fields. | ||
(fds contains: #x) println. | ||
(fds contains: #y) println. | ||
(fds contains: #z) println. | ||
) | ||
|
||
find: sym = ( | ||
method_holder methods do: [:e | ((e signature) == sym) ifTrue: [ ^e ]]. | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters