I have just finished up the compilers course at IU and am trying to add a few more forms to my little “scheme”. We added several forms into our language via syntactic sugar where a full scheme would typically use macro-expansion (and and or were the main ones). The problem I’ve come across is desugaring a cond statement.
As a note: I am going back and forth between Chez and Petite Chez as I work.
I am trying to handle all of the cond clause forms. When handling the (test => expr) form, I seem to be running into problems working with the =>. I can’t seem to do anything to it without getting a misplaced aux keyword error or having the clause fall through to the next line in my match statement.
Any ideas on how I can detect this keyword?
I wrote my own Scheme metacircular interpreter some time ago, with support for the
=>syntax in thecondspecial form. In essence, this is what I had to do:When iterating over all the clauses (pairs of predicates and actions) of a
condexpression, I expand each action and ask if the=>token is present in the clause (usingcond-has-then?). If=>was found, I apply the action part of the clause to the predicate.Here’s the complete piece of code in charge of evaluating
condexpressions in my interpreter, the main procedure (the one called fromeval) iscond->if, which transforms acondexpression into a series of nestedifexpressions, and also deals with the=>syntax; I hope this is helpful for you: