Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Mutator method
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Racket=== In [[Racket (programming language)|Racket]], the object system is a way to organize code that comes in addition to modules and units. As in the rest of the language, the object system has first-class values and lexical scope is used to control access to objects and methods. <syntaxhighlight lang="racket"> #lang racket (define student% (class object% (init-field name) (define/public (get-name) name) (define/public (set-name! new-name) (set! name new-name)) (super-new))) (define s (new student% [name "Alice"])) (send s get-name) ; => "Alice" (send s set-name! "Bob") (send s get-name) ; => "Bob" </syntaxhighlight> Struct definitions are an alternative way to define new types of values, with mutators being present when explicitly required: <syntaxhighlight lang="racket"> #lang racket (struct student (name) #:mutable) (define s (student "Alice")) (set-student-name! s "Bob") (student-name s) ; => "Bob" </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)