<div class="__aliyun_email_body_block"><div  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun"><div  style="clear: both; font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><span >I was a Scala programmer before. In Scala, case class is widely adopted for data processing.</span></div><div  style="clear: both; font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><span ><br ></span></div><div  style="clear: both; font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><span >I just implemented the equiv of case class in Goldfish Scheme and packaged it in the (liii case) R7RS library:</span></div><div  style="clear: both; font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><span ><a  href="https://github.com/LiiiLabs/goldfish/blob/main/goldfish/liii/case.scm" target="_blank">https://github.com/LiiiLabs/goldfish/blob/main/goldfish/liii/case.scm</a></span></div><div  style="clear: both; font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><span ><br ></span></div><div  style="clear: both; font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><span >Here are sample usages of define-case-class.</span></div><div  style="clear: both; font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><span ><br ></span></div><div  style="clear: both; font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><div ><span  class="text-only" data-eleid="6" style="white-space: pre;">Sample code 1: simplest use case</span></div><div ><span  class="text-only" data-eleid="6" style="white-space: pre;">----------------------------------------------------------</span></div><span >(define-case-class person</span><div  style="clear: both;">&nbsp; ((name string? "Bob")</div><div  style="clear: both;"> &nbsp; (age integer?)))</div><div  style="clear: both;"><br ></div><div  style="clear: both;">(let1 bob (person :name "Bob" :age 21)</div><div  style="clear: both;">&nbsp; (check (bob 'name) =&gt; "Bob")</div><div  style="clear: both;">&nbsp; (check (bob 'age) =&gt; 21)</div><div  style="clear: both;">&nbsp; (check ((bob :name "hello") 'name) =&gt; "hello")</div><div  style="clear: both;">&nbsp; (check-catch 'value-error (bob 'sex))</div><div  style="clear: both;">&nbsp; (check-true (person? bob)))</div><div  style="clear: both;"><br ></div><div  style="clear: both;">(check-true (person=? (person "Bob" 21) (person "Bob" 21)))</div><div  style="clear: both;">(check-false (person=? (person "Bob" 21) (person "Bob" 20)))</div><div ><span >(check-catch 'type-error (person 1 21))</span></div><div ><span >--------------------------------------------------------------------------</span></div><div ><span >Note: let1 is the simplified version of let in the (liii base) library</span></div><span ><br ></span></div><div  style="clear: both; font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><span >Sample code 2:&nbsp;<span >Use case class with pattern matching</span></span></div><div  style="clear: both; font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><span >---------------------------------------------------------------------------------</span></div><div  style="clear: both; font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><span >(let ((bob (person "Bob" 21))</span><div  style="clear: both;">&nbsp; &nbsp; &nbsp; (get-name (lambda (x)</div><div  style="clear: both;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (case* x</div><div  style="clear: both;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ((#&lt;person?&gt;) (x 'name))</div><div  style="clear: both;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (else (???))))))</div><div  style="clear: both;">&nbsp; (check (get-name bob) =&gt; "Bob")</div><div ><span >&nbsp; (check-catch 'not-implemented-error (get-name 1)))</span></div><div ><span >------------------------------------------------------------------------------------</span></div><div ><span >Note: (???) means (error 'not-implemented-error), it comes for Scala</span></div><div ><span ><br ></span></div><div >Sample code 3:&nbsp;<span >Use case class with companion functions</span></div><div ><span >------------------------------------------------------------------------------------</span></div><div ><span ><span >(define-case-class jerson</span></span><div  style="clear: both;">&nbsp; ((name string?)</div><div  style="clear: both;"> &nbsp; (age integer?))</div><div  style="clear: both;">&nbsp; (define (to-string)</div><div  style="clear: both;">&nbsp; &nbsp; (string-append "I am " name " " (number-&gt;string age) " years old!"))</div><div  style="clear: both;">&nbsp; (define (greet x)</div><div  style="clear: both;">&nbsp; &nbsp; (string-append "Hi " x ", " (to-string)))</div><div ><span >)</span></div></div><div ><span >-----------------------------------------------------------------------------------</span></div><div ><span ><br ></span></div><div ><span ><br ></span></div><div ><span ><br ></span></div><span ><br ></span></div><div  style="clear: both; font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><span ><br ></span></div><div  style="clear: both; font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><span ><br ></span></div><div  style="clear: both; font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><span ><br ></span></div></div></div>