thomaswevans
2020-8-10 19:39:28

@thomaswevans has joined the channel


thomaswevans
2020-8-10 19:42:21

Hello, all.

In section 21 of HtDP, on designing an interpreter, it says: “Design a function interpreter. It consumes an S-expr and an SL. The former is supposed to represent an expression and the latter a list of definitions. The function parses both with the appropriate parsing functions and then uses eval-all from https://htdp.org/2020-5-6/Book/part_four.html#%28counter._%28exercise._ex~3absl-eval-all%29%29\|exercise 361 to evaluate the expression. Hint You must adapt the ideas of https://htdp.org/2020-5-6/Book/part_four.html#%28counter._%28exercise._ex~3absl-parse2%29%29\|exercise 350 to create a parser for definitions and lists of definitions.”

This made it sound like I only needed one parser, so what I did was have my list of definitions be interpreted by my SL parser, such that the signature for the latter was “SL -> BSL-fun-expr or BSL-da-all”. When I looked at the solution uploaded by the fellow who’s gone through the book and uploaded all of his work to Github, he had the list of definitions be parsed by a separate SL parser from the one for the input expression. I was wondering if one was deemed better than the other, in terms of program design? There are already examples in the book of functions that can output two different forms of data, in the form of [Maybe X]. Is it appropriate in this case too considering the same SL parser can do the job for both?


soegaard2
2020-8-10 20:03:25

@thomaswevans It seems to me that it is simpler to have two different functions. But since they do almost the same, I don’t see a problem with having just one.


thomaswevans
2020-8-10 20:31:25

@soegaard2 Thank you!