Metaprogramming: Difference between revisions
Content deleted Content added
→{{header|Common Lisp}}: Show identity comprehension too. Anyone care for state transformer? |
|||
Line 84: | Line 84: | ||
Also, a monad is a class, and there is a way in the DEFINE-MONAD syntax to declare what the base classes are (multiple inheritance) as well as any additional custom slots. |
Also, a monad is a class, and there is a way in the DEFINE-MONAD syntax to declare what the base classes are (multiple inheritance) as well as any additional custom slots. |
||
Another example, using the identity monad. With the identity monad, the comprehension becomes a sequence of successive variable bindings, and a form evaluated in the scope of those bindings. It is basically like a "Lispified" Haskell DO syntax: |
|||
<lang lisp>(identity-comp (list x y z) (x 1) (y (* 3 x)) (z (+ x y))) |
|||
-> (1 3 4) |
|||
</lang> |
|||
I.e. combine the values X, Y and Z into a triplet list, were X is 1, Y is 3X, and Z is X + Y. |
|||
To see the original version of this code with lengthy comments, have a look in the Lisp Pastebin. http://paste.lisp.org/display/71196 |
To see the original version of this code with lengthy comments, have a look in the Lisp Pastebin. http://paste.lisp.org/display/71196 |