# Alloy Authors - Practical Alloy - Handling recursion (Highlights) ![rw-book-cover|256](https://readwise-assets.s3.amazonaws.com/static/images/article0.00998d930354.png) ## Metadata **Review**:: [readwise.io](https://readwise.io/bookreview/51282134) **Source**:: #from/readwise #from/reader **Zettel**:: #zettel/fleeting **Status**:: #x **Authors**:: [[Alloy Authors]] **Full Title**:: Practical Alloy - Handling recursion **Category**:: #articles #readwise/articles **Category Icon**:: 📰 **URL**:: [practicalalloy.github.io](https://practicalalloy.github.io/chapters/structural-topics/topics/recursion/index.html) **Host**:: [[practicalalloy.github.io]] **Highlighted**:: [[2025-05-10]] **Created**:: [[2025-05-14]] ## Highlights - Alloy provides a predefined library `util/natural` that provides a codification of natural numbers in plain Alloy, and allows us to refrain from using the built-in type `Int`. ([View Highlight](https://read.readwise.io/read/01jtw2szrg3px3xpyrphn7tebf)) ^887736214 - Nonetheless, Alloy does support recursive function definitions, but in a very restrictive manner since we have to impose a bound on the number of function unrolls. This feature is disabled by default, and must be turned on the options, and is limited to a maximum of 3 unrolls due to performance issues. ([View Highlight](https://read.readwise.io/read/01jtw30r33748jzkrpw7vxga4x)) ^887736326 - When the maximum recursion depth allowed is exceeded, it just “fails silently” by returning an empty relation. ([View Highlight](https://read.readwise.io/read/01jtw31t9s77ez5rw3rccrggn7)) ^887736343 - The alternative approach follows a strategy that resembles *memoization*: we introduce a new field in the signature that is to be recursively traversed, and store in this field the local result of the recursive call. Then, we declaratively specify the value of this field for all atoms using only the the value for its ancestors. ([View Highlight](https://read.readwise.io/read/01jtw33g7f40pg6msyabc4mns6)) ^887736384