braveandtrue

https://www.braveclojure.com/
marek-sed 2016-05-06T10:31:19.000029Z

Hi guys, I am working through excercises in book and I can't figure how to solve excercise 2 in chapter 7. It is clear to me how to recursively build a nested list structure, but I am stuck on figuring out how to apply operator precedence to it. Can someone give some tips, how to do it? And btw in assignment this phrase is unclear to me "takes list like (1 + 3 * 4 - 5)", means function should take list of any size, or only lists with 4 numbers and 3 infixed operators? thank you very much for any help

nonrecursive 2016-05-06T12:34:10.000031Z

@marek-sed for your second question, “takes list like …” means take a list that has any arbitrary arithmetic expression

nonrecursive 2016-05-06T12:36:00.000032Z

coding operator precedence is definitely tricky. googling “operator precedence parser” might yield some useful results

nonrecursive 2016-05-06T12:36:47.000033Z

though the results are very involved and technical

kjbrock 2016-05-06T22:41:10.000034Z

@marek-sed You can give higher precedence to an operator by wrapping its operands up in their own list and using it as a component in the lower-precedence list. You can get a fairly short solution to the problem if you’re only dealing with two levels of precedence, as with +-/*.