procgen  Changes To struct.scm

Changes to "struct.scm" between 2019-03-30 05:59:13 and 2019-03-30 06:00:56

     1      1   <h1>functional structures in scheme</h1>
     2         -<code>struct.scm</code> contains a function to generate functional "structs." these structs are immutable and are implemented as lambdas. you can create a new "struct type" by calling the <code>(struct)</code> function. consider the following code:
            2  +
            3  +<code>/lib/struct.scm</code> contains a function to generate functional "structs." these structs are immutable and are implemented as lambdas. you can create a new "struct type" by calling the <code>(struct)</code> function. consider the following code:
     3      4   
     4      5   <pre><code>(define user (struct 'name          'pw               'rank           'email              'age 'attunements))
     5      6   (define juan (user   "juán peralta" "p@labra-secr3ta" "special agent" "j.peralta@tla.gov" 69
     6      7                      '("hushed whispers" "the unconquered wilderness" "careful duplicity")))</code></pre>
     7      8   
     8      9   this code first creates a struct type, characterized by the function <code>(user)</code>. when <code>(user)</code> is called on the correct number of arguments, it generates a new record of that type. the new record is itself a function. to access a record, you simply call the function with the name of the field to look up. the library also supports what's known as "functional record update syntax," a pattern in which a new struct is returned with different values for named fields. this library currently only supports updating one record at a time, but you can get around this through currying.
     9     10