├── .gitignore ├── COPYING ├── Changelog ├── README.md ├── project.clj ├── src └── robert │ └── hooke.clj └── test └── robert └── test_hooke.clj /.gitignore: -------------------------------------------------------------------------------- 1 | pom.xml 2 | *jar 3 | /lib/ 4 | /classes/ 5 | .lein-failures 6 | .lein-deps-sum 7 | /target 8 | /pom.xml.asc 9 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | Source code distributed under the Eclipse Public License - v 1.0: 2 | 3 | THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE 4 | PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF 5 | THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. 6 | 7 | 1. DEFINITIONS 8 | 9 | "Contribution" means: 10 | 11 | a) in the case of the initial Contributor, the initial code and 12 | documentation distributed under this Agreement, and 13 | 14 | b) in the case of each subsequent Contributor: 15 | 16 | i) changes to the Program, and 17 | 18 | ii) additions to the Program; 19 | 20 | where such changes and/or additions to the Program originate from and 21 | are distributed by that particular Contributor. A Contribution 22 | 'originates' from a Contributor if it was added to the Program by such 23 | Contributor itself or anyone acting on such Contributor's 24 | behalf. Contributions do not include additions to the Program which: 25 | (i) are separate modules of software distributed in conjunction with 26 | the Program under their own license agreement, and (ii) are not 27 | derivative works of the Program. 28 | 29 | "Contributor" means any person or entity that distributes the Program. 30 | 31 | "Licensed Patents" mean patent claims licensable by a Contributor 32 | which are necessarily infringed by the use or sale of its Contribution 33 | alone or when combined with the Program. 34 | 35 | "Program" means the Contributions distributed in accordance with this 36 | Agreement. 37 | 38 | "Recipient" means anyone who receives the Program under this 39 | Agreement, including all Contributors. 40 | 41 | 2. GRANT OF RIGHTS 42 | 43 | a) Subject to the terms of this Agreement, each Contributor hereby 44 | grants Recipient a non-exclusive, worldwide, royalty-free copyright 45 | license to reproduce, prepare derivative works of, publicly display, 46 | publicly perform, distribute and sublicense the Contribution of such 47 | Contributor, if any, and such derivative works, in source code and 48 | object code form. 49 | 50 | b) Subject to the terms of this Agreement, each Contributor hereby 51 | grants Recipient a non-exclusive, worldwide, royalty-free patent 52 | license under Licensed Patents to make, use, sell, offer to sell, 53 | import and otherwise transfer the Contribution of such Contributor, if 54 | any, in source code and object code form. This patent license shall 55 | apply to the combination of the Contribution and the Program if, at 56 | the time the Contribution is added by the Contributor, such addition 57 | of the Contribution causes such combination to be covered by the 58 | Licensed Patents. The patent license shall not apply to any other 59 | combinations which include the Contribution. No hardware per se is 60 | licensed hereunder. 61 | 62 | c) Recipient understands that although each Contributor grants the 63 | licenses to its Contributions set forth herein, no assurances are 64 | provided by any Contributor that the Program does not infringe the 65 | patent or other intellectual property rights of any other entity. Each 66 | Contributor disclaims any liability to Recipient for claims brought by 67 | any other entity based on infringement of intellectual property rights 68 | or otherwise. As a condition to exercising the rights and licenses 69 | granted hereunder, each Recipient hereby assumes sole responsibility 70 | to secure any other intellectual property rights needed, if any. For 71 | example, if a third party patent license is required to allow 72 | Recipient to distribute the Program, it is Recipient's responsibility 73 | to acquire that license before distributing the Program. 74 | 75 | d) Each Contributor represents that to its knowledge it has sufficient 76 | copyright rights in its Contribution, if any, to grant the copyright 77 | license set forth in this Agreement. 78 | 79 | 3. REQUIREMENTS 80 | 81 | A Contributor may choose to distribute the Program in object code form 82 | under its own license agreement, provided that: 83 | 84 | a) it complies with the terms and conditions of this Agreement; and 85 | 86 | b) its license agreement: 87 | 88 | i) effectively disclaims on behalf of all Contributors all warranties 89 | and conditions, express and implied, including warranties or 90 | conditions of title and non-infringement, and implied warranties or 91 | conditions of merchantability and fitness for a particular purpose; 92 | 93 | ii) effectively excludes on behalf of all Contributors all liability 94 | for damages, including direct, indirect, special, incidental and 95 | consequential damages, such as lost profits; 96 | 97 | iii) states that any provisions which differ from this Agreement are 98 | offered by that Contributor alone and not by any other party; and 99 | 100 | iv) states that source code for the Program is available from such 101 | Contributor, and informs licensees how to obtain it in a reasonable 102 | manner on or through a medium customarily used for software exchange. 103 | 104 | When the Program is made available in source code form: 105 | 106 | a) it must be made available under this Agreement; and 107 | 108 | b) a copy of this Agreement must be included with each copy of the Program. 109 | 110 | Contributors may not remove or alter any copyright notices contained 111 | within the Program. 112 | 113 | Each Contributor must identify itself as the originator of its 114 | Contribution, if any, in a manner that reasonably allows subsequent 115 | Recipients to identify the originator of the Contribution. 116 | 117 | 4. COMMERCIAL DISTRIBUTION 118 | 119 | Commercial distributors of software may accept certain 120 | responsibilities with respect to end users, business partners and the 121 | like. While this license is intended to facilitate the commercial use 122 | of the Program, the Contributor who includes the Program in a 123 | commercial product offering should do so in a manner which does not 124 | create potential liability for other Contributors. Therefore, if a 125 | Contributor includes the Program in a commercial product offering, 126 | such Contributor ("Commercial Contributor") hereby agrees to defend 127 | and indemnify every other Contributor ("Indemnified Contributor") 128 | against any losses, damages and costs (collectively "Losses") arising 129 | from claims, lawsuits and other legal actions brought by a third party 130 | against the Indemnified Contributor to the extent caused by the acts 131 | or omissions of such Commercial Contributor in connection with its 132 | distribution of the Program in a commercial product offering. The 133 | obligations in this section do not apply to any claims or Losses 134 | relating to any actual or alleged intellectual property 135 | infringement. In order to qualify, an Indemnified Contributor must: a) 136 | promptly notify the Commercial Contributor in writing of such claim, 137 | and b) allow the Commercial Contributor tocontrol, and cooperate with 138 | the Commercial Contributor in, the defense and any related settlement 139 | negotiations. The Indemnified Contributor may participate in any such 140 | claim at its own expense. 141 | 142 | For example, a Contributor might include the Program in a commercial 143 | product offering, Product X. That Contributor is then a Commercial 144 | Contributor. If that Commercial Contributor then makes performance 145 | claims, or offers warranties related to Product X, those performance 146 | claims and warranties are such Commercial Contributor's responsibility 147 | alone. Under this section, the Commercial Contributor would have to 148 | defend claims against the other Contributors related to those 149 | performance claims and warranties, and if a court requires any other 150 | Contributor to pay any damages as a result, the Commercial Contributor 151 | must pay those damages. 152 | 153 | 5. NO WARRANTY 154 | 155 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS 156 | PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 157 | KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY 158 | WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY 159 | OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely 160 | responsible for determining the appropriateness of using and 161 | distributing the Program and assumes all risks associated with its 162 | exercise of rights under this Agreement , including but not limited to 163 | the risks and costs of program errors, compliance with applicable 164 | laws, damage to or loss of data, programs or equipment, and 165 | unavailability or interruption of operations. 166 | 167 | 6. DISCLAIMER OF LIABILITY 168 | 169 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR 170 | ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, 171 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING 172 | WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF 173 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 174 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR 175 | DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED 176 | HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 177 | 178 | 7. GENERAL 179 | 180 | If any provision of this Agreement is invalid or unenforceable under 181 | applicable law, it shall not affect the validity or enforceability of 182 | the remainder of the terms of this Agreement, and without further 183 | action by the parties hereto, such provision shall be reformed to the 184 | minimum extent necessary to make such provision valid and enforceable. 185 | 186 | If Recipient institutes patent litigation against any entity 187 | (including a cross-claim or counterclaim in a lawsuit) alleging that 188 | the Program itself (excluding combinations of the Program with other 189 | software or hardware) infringes such Recipient's patent(s), then such 190 | Recipient's rights granted under Section 2(b) shall terminate as of 191 | the date such litigation is filed. 192 | 193 | All Recipient's rights under this Agreement shall terminate if it 194 | fails to comply with any of the material terms or conditions of this 195 | Agreement and does not cure such failure in a reasonable period of 196 | time after becoming aware of such noncompliance. If all Recipient's 197 | rights under this Agreement terminate, Recipient agrees to cease use 198 | and distribution of the Program as soon as reasonably 199 | practicable. However, Recipient's obligations under this Agreement and 200 | any licenses granted by Recipient relating to the Program shall 201 | continue and survive. 202 | 203 | Everyone is permitted to copy and distribute copies of this Agreement, 204 | but in order to avoid inconsistency the Agreement is copyrighted and 205 | may only be modified in the following manner. The Agreement Steward 206 | reserves the right to publish new versions (including revisions) of 207 | this Agreement from time to time. No one other than the Agreement 208 | Steward has the right to modify this Agreement. The Eclipse Foundation 209 | is the initial Agreement Steward. The Eclipse Foundation may assign 210 | the responsibility to serve as the Agreement Steward to a suitable 211 | separate entity. Each new version of the Agreement will be given a 212 | distinguishing version number. The Program (including Contributions) 213 | may always be distributed subject to the version of the Agreement 214 | under which it was received. In addition, after a new version of the 215 | Agreement is published, Contributor may elect to distribute the 216 | Program (including its Contributions) under the new version. Except as 217 | expressly stated in Sections 2(a) and 2(b) above, Recipient receives 218 | no rights or licenses to the intellectual property of any Contributor 219 | under this Agreement, whether expressly, by implication, estoppel or 220 | otherwise. All rights in the Program not expressly granted under this 221 | Agreement are reserved. 222 | 223 | This Agreement is governed by the laws of the State of Washington and 224 | the intellectual property laws of the United States of America. No 225 | party to this Agreement will bring a legal action under this Agreement 226 | more than one year after the cause of action arose. Each party waives 227 | its rights to a jury trial in any resulting litigation. 228 | 229 | 230 | 231 | Images distributed under the Creative Commons Attribution + ShareAlike 232 | License version 3.0: 233 | 234 | THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS 235 | CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS 236 | PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE 237 | WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS 238 | PROHIBITED. 239 | 240 | BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND 241 | AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS 242 | LICENSE MAY BE CONSIDERED TO BE A CONTRACT, THE LICENSOR GRANTS YOU 243 | THE RIGHTS CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH 244 | TERMS AND CONDITIONS. 245 | 246 | 1. Definitions 247 | 248 | "Adaptation" means a work based upon the Work, or upon the Work 249 | and other pre-existing works, such as a translation, adaptation, 250 | derivative work, arrangement of music or other alterations of a 251 | literary or artistic work, or phonogram or performance and 252 | includes cinematographic adaptations or any other form in which 253 | the Work may be recast, transformed, or adapted including in any 254 | form recognizably derived from the original, except that a work 255 | that constitutes a Collection will not be considered an Adaptation 256 | for the purpose of this License. For the avoidance of doubt, where 257 | the Work is a musical work, performance or phonogram, the 258 | synchronization of the Work in timed-relation with a moving image 259 | ("synching") will be considered an Adaptation for the purpose of 260 | this License. 261 | 262 | "Collection" means a collection of literary or artistic works, 263 | such as encyclopedias and anthologies, or performances, phonograms 264 | or broadcasts, or other works or subject matter other than works 265 | listed in Section 1(f) below, which, by reason of the selection 266 | and arrangement of their contents, constitute intellectual 267 | creations, in which the Work is included in its entirety in 268 | unmodified form along with one or more other contributions, each 269 | constituting separate and independent works in themselves, which 270 | together are assembled into a collective whole. A work that 271 | constitutes a Collection will not be considered an Adaptation (as 272 | defined below) for the purposes of this License. 273 | 274 | "Creative Commons Compatible License" means a license that is 275 | listed at http://creativecommons.org/compatiblelicenses that has 276 | been approved by Creative Commons as being essentially equivalent 277 | to this License, including, at a minimum, because that license: 278 | (i) contains terms that have the same purpose, meaning and effect 279 | as the License Elements of this License; and, (ii) explicitly 280 | permits the relicensing of adaptations of works made available 281 | under that license under this License or a Creative Commons 282 | jurisdiction license with the same License Elements as this 283 | License. 284 | 285 | "Distribute" means to make available to the public the original 286 | and copies of the Work or Adaptation, as appropriate, through sale 287 | or other transfer of ownership. 288 | 289 | "License Elements" means the following high-level license 290 | attributes as selected by Licensor and indicated in the title of 291 | this License: Attribution, ShareAlike. 292 | 293 | "Licensor" means the individual, individuals, entity or entities 294 | that offer(s) the Work under the terms of this License. 295 | 296 | "Original Author" means, in the case of a literary or artistic 297 | work, the individual, individuals, entity or entities who created 298 | the Work or if no individual or entity can be identified, the 299 | publisher; and in addition (i) in the case of a performance the 300 | actors, singers, musicians, dancers, and other persons who act, 301 | sing, deliver, declaim, play in, interpret or otherwise perform 302 | literary or artistic works or expressions of folklore; (ii) in the 303 | case of a phonogram the producer being the person or legal entity 304 | who first fixes the sounds of a performance or other sounds; and, 305 | (iii) in the case of broadcasts, the organization that transmits 306 | the broadcast. 307 | 308 | "Work" means the literary and/or artistic work offered under the 309 | terms of this License including without limitation any production 310 | in the literary, scientific and artistic domain, whatever may be 311 | the mode or form of its expression including digital form, such as 312 | a book, pamphlet and other writing; a lecture, address, sermon or 313 | other work of the same nature; a dramatic or dramatico-musical 314 | work; a choreographic work or entertainment in dumb show; a 315 | musical composition with or without words; a cinematographic work 316 | to which are assimilated works expressed by a process analogous to 317 | cinematography; a work of drawing, painting, architecture, 318 | sculpture, engraving or lithography; a photographic work to which 319 | are assimilated works expressed by a process analogous to 320 | photography; a work of applied art; an illustration, map, plan, 321 | sketch or three-dimensional work relative to geography, 322 | topography, architecture or science; a performance; a broadcast; a 323 | phonogram; a compilation of data to the extent it is protected as 324 | a copyrightable work; or a work performed by a variety or circus 325 | performer to the extent it is not otherwise considered a literary 326 | or artistic work. 327 | 328 | "You" means an individual or entity exercising rights under this 329 | License who has not previously violated the terms of this License 330 | with respect to the Work, or who has received express permission 331 | from the Licensor to exercise rights under this License despite a 332 | previous violation. 333 | 334 | "Publicly Perform" means to perform public recitations of the Work 335 | and to communicate to the public those public recitations, by any 336 | means or process, including by wire or wireless means or public 337 | digital performances; to make available to the public Works in 338 | such a way that members of the public may access these Works from 339 | a place and at a place individually chosen by them; to perform the 340 | Work to the public by any means or process and the communication 341 | to the public of the performances of the Work, including by public 342 | digital performance; to broadcast and rebroadcast the Work by any 343 | means including signs, sounds or images. 344 | 345 | "Reproduce" means to make copies of the Work by any means 346 | including without limitation by sound or visual recordings and the 347 | right of fixation and reproducing fixations of the Work, including 348 | storage of a protected performance or phonogram in digital form or 349 | other electronic medium. 350 | 351 | 2. Fair Dealing Rights. Nothing in this License is intended to reduce, 352 | limit, or restrict any uses free from copyright or rights arising from 353 | limitations or exceptions that are provided for in connection with the 354 | copyright protection under copyright law or other applicable laws. 355 | 356 | 3. License Grant. Subject to the terms and conditions of this License, 357 | Licensor hereby grants You a worldwide, royalty-free, non-exclusive, 358 | perpetual (for the duration of the applicable copyright) license to 359 | exercise the rights in the Work as stated below: 360 | 361 | to Reproduce the Work, to incorporate the Work into one or more 362 | Collections, and to Reproduce the Work as incorporated in the 363 | Collections; 364 | 365 | to create and Reproduce Adaptations provided that any such 366 | Adaptation, including any translation in any medium, takes 367 | reasonable steps to clearly label, demarcate or otherwise identify 368 | that changes were made to the original Work. For example, a 369 | translation could be marked "The original work was translated from 370 | English to Spanish," or a modification could indicate "The 371 | original work has been modified."; 372 | 373 | to Distribute and Publicly Perform the Work including as 374 | incorporated in Collections; and, 375 | 376 | to Distribute and Publicly Perform Adaptations. 377 | 378 | For the avoidance of doubt: 379 | 380 | Non-waivable Compulsory License Schemes. In those 381 | jurisdictions in which the right to collect royalties through 382 | any statutory or compulsory licensing scheme cannot be waived, 383 | the Licensor reserves the exclusive right to collect such 384 | royalties for any exercise by You of the rights granted under 385 | this License; 386 | 387 | Waivable Compulsory License Schemes. In those jurisdictions in 388 | which the right to collect royalties through any statutory or 389 | compulsory licensing scheme can be waived, the Licensor waives 390 | the exclusive right to collect such royalties for any exercise 391 | by You of the rights granted under this License; and, 392 | 393 | Voluntary License Schemes. The Licensor waives the right to 394 | collect royalties, whether individually or, in the event that 395 | the Licensor is a member of a collecting society that 396 | administers voluntary licensing schemes, via that society, 397 | from any exercise by You of the rights granted under this 398 | License. 399 | 400 | The above rights may be exercised in all media and formats whether now 401 | known or hereafter devised. The above rights include the right to make 402 | such modifications as are technically necessary to exercise the rights 403 | in other media and formats. Subject to Section 8(f), all rights not 404 | expressly granted by Licensor are hereby reserved. 405 | 406 | 4. Restrictions. The license granted in Section 3 above is expressly 407 | made subject to and limited by the following restrictions: 408 | 409 | You may Distribute or Publicly Perform the Work only under the 410 | terms of this License. You must include a copy of, or the Uniform 411 | Resource Identifier (URI) for, this License with every copy of the 412 | Work You Distribute or Publicly Perform. You may not offer or 413 | impose any terms on the Work that restrict the terms of this 414 | License or the ability of the recipient of the Work to exercise 415 | the rights granted to that recipient under the terms of the 416 | License. You may not sublicense the Work. You must keep intact all 417 | notices that refer to this License and to the disclaimer of 418 | warranties with every copy of the Work You Distribute or Publicly 419 | Perform. When You Distribute or Publicly Perform the Work, You may 420 | not impose any effective technological measures on the Work that 421 | restrict the ability of a recipient of the Work from You to 422 | exercise the rights granted to that recipient under the terms of 423 | the License. This Section 4(a) applies to the Work as incorporated 424 | in a Collection, but this does not require the Collection apart 425 | from the Work itself to be made subject to the terms of this 426 | License. If You create a Collection, upon notice from any Licensor 427 | You must, to the extent practicable, remove from the Collection 428 | any credit as required by Section 4(c), as requested. If You 429 | create an Adaptation, upon notice from any Licensor You must, to 430 | the extent practicable, remove from the Adaptation any credit as 431 | required by Section 4(c), as requested. 432 | 433 | You may Distribute or Publicly Perform an Adaptation only under 434 | the terms of: (i) this License; (ii) a later version of this 435 | License with the same License Elements as this License; (iii) a 436 | Creative Commons jurisdiction license (either this or a later 437 | license version) that contains the same License Elements as this 438 | License (e.g., Attribution-ShareAlike 3.0 US)); (iv) a Creative 439 | Commons Compatible License. If you license the Adaptation under 440 | one of the licenses mentioned in (iv), you must comply with the 441 | terms of that license. If you license the Adaptation under the 442 | terms of any of the licenses mentioned in (i), (ii) or (iii) (the 443 | "Applicable License"), you must comply with the terms of the 444 | Applicable License generally and the following provisions: (I) You 445 | must include a copy of, or the URI for, the Applicable License 446 | with every copy of each Adaptation You Distribute or Publicly 447 | Perform; (II) You may not offer or impose any terms on the 448 | Adaptation that restrict the terms of the Applicable License or 449 | the ability of the recipient of the Adaptation to exercise the 450 | rights granted to that recipient under the terms of the Applicable 451 | License; (III) You must keep intact all notices that refer to the 452 | Applicable License and to the disclaimer of warranties with every 453 | copy of the Work as included in the Adaptation You Distribute or 454 | Publicly Perform; (IV) when You Distribute or Publicly Perform the 455 | Adaptation, You may not impose any effective technological 456 | measures on the Adaptation that restrict the ability of a 457 | recipient of the Adaptation from You to exercise the rights 458 | granted to that recipient under the terms of the Applicable 459 | License. This Section 4(b) applies to the Adaptation as 460 | incorporated in a Collection, but this does not require the 461 | Collection apart from the Adaptation itself to be made subject to 462 | the terms of the Applicable License. 463 | 464 | If You Distribute, or Publicly Perform the Work or any Adaptations 465 | or Collections, You must, unless a request has been made pursuant 466 | to Section 4(a), keep intact all copyright notices for the Work 467 | and provide, reasonable to the medium or means You are utilizing: 468 | (i) the name of the Original Author (or pseudonym, if applicable) 469 | if supplied, and/or if the Original Author and/or Licensor 470 | designate another party or parties (e.g., a sponsor institute, 471 | publishing entity, journal) for attribution ("Attribution 472 | Parties") in Licensor's copyright notice, terms of service or by 473 | other reasonable means, the name of such party or parties; (ii) 474 | the title of the Work if supplied; (iii) to the extent reasonably 475 | practicable, the URI, if any, that Licensor specifies to be 476 | associated with the Work, unless such URI does not refer to the 477 | copyright notice or licensing information for the Work; and (iv) , 478 | consistent with Ssection 3(b), in the case of an Adaptation, a 479 | credit identifying the use of the Work in the Adaptation (e.g., 480 | "French translation of the Work by Original Author," or 481 | "Screenplay based on original Work by Original Author"). The 482 | credit required by this Section 4(c) may be implemented in any 483 | reasonable manner; provided, however, that in the case of a 484 | Adaptation or Collection, at a minimum such credit will appear, if 485 | a credit for all contributing authors of the Adaptation or 486 | Collection appears, then as part of these credits and in a manner 487 | at least as prominent as the credits for the other contributing 488 | authors. For the avoidance of doubt, You may only use the credit 489 | required by this Section for the purpose of attribution in the 490 | manner set out above and, by exercising Your rights under this 491 | License, You may not implicitly or explicitly assert or imply any 492 | connection with, sponsorship or endorsement by the Original 493 | Author, Licensor and/or Attribution Parties, as appropriate, of 494 | You or Your use of the Work, without the separate, express prior 495 | written permission of the Original Author, Licensor and/or 496 | Attribution Parties. 497 | 498 | Except as otherwise agreed in writing by the Licensor or as may be 499 | otherwise permitted by applicable law, if You Reproduce, 500 | Distribute or Publicly Perform the Work either by itself or as 501 | part of any Adaptations or Collections, You must not distort, 502 | mutilate, modify or take other derogatory action in relation to 503 | the Work which would be prejudicial to the Original Author's honor 504 | or reputation. Licensor agrees that in those jurisdictions 505 | (e.g. Japan), in which any exercise of the right granted in 506 | Section 3(b) of this License (the right to make Adaptations) would 507 | be deemed to be a distortion, mutilation, modification or other 508 | derogatory action prejudicial to the Original Author's honor and 509 | reputation, the Licensor will waive or not assert, as appropriate, 510 | this Section, to the fullest extent permitted by the applicable 511 | national law, to enable You to reasonably exercise Your right 512 | under Section 3(b) of this License (right to make Adaptations) but 513 | not otherwise. 514 | 515 | 5. Representations, Warranties and Disclaimer 516 | 517 | UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN WRITING, 518 | LICENSOR OFFERS THE WORK AS-IS AND MAKES NO REPRESENTATIONS OR 519 | WARRANTIES OF ANY KIND CONCERNING THE WORK, EXPRESS, IMPLIED, 520 | STATUTORY OR OTHERWISE, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF 521 | TITLE, MERCHANTIBILITY, FITNESS FOR A PARTICULAR PURPOSE, 522 | NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, ACCURACY, 523 | OR THE PRESENCE OF ABSENCE OF ERRORS, WHETHER OR NOT 524 | DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED 525 | WARRANTIES, SO SUCH EXCLUSION MAY NOT APPLY TO YOU. 526 | 527 | 6. Limitation on Liability. EXCEPT TO THE EXTENT REQUIRED BY 528 | APPLICABLE LAW, IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY 529 | LEGAL THEORY FOR ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR 530 | EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK, 531 | EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 532 | 533 | 7. Termination 534 | 535 | This License and the rights granted hereunder will terminate 536 | automatically upon any breach by You of the terms of this 537 | License. Individuals or entities who have received Adaptations or 538 | Collections from You under this License, however, will not have 539 | their licenses terminated provided such individuals or entities 540 | remain in full compliance with those licenses. Sections 1, 2, 5, 541 | 6, 7, and 8 will survive any termination of this License. 542 | 543 | Subject to the above terms and conditions, the license granted 544 | here is perpetual (for the duration of the applicable copyright in 545 | the Work). Notwithstanding the above, Licensor reserves the right 546 | to release the Work under different license terms or to stop 547 | distributing the Work at any time; provided, however that any such 548 | election will not serve to withdraw this License (or any other 549 | license that has been, or is required to be, granted under the 550 | terms of this License), and this License will continue in full 551 | force and effect unless terminated as stated above. 552 | 553 | 8. Miscellaneous 554 | 555 | Each time You Distribute or Publicly Perform the Work or a 556 | Collection, the Licensor offers to the recipient a license to the 557 | Work on the same terms and conditions as the license granted to 558 | You under this License. 559 | 560 | Each time You Distribute or Publicly Perform an Adaptation, 561 | Licensor offers to the recipient a license to the original Work on 562 | the same terms and conditions as the license granted to You under 563 | this License. 564 | 565 | If any provision of this License is invalid or unenforceable under 566 | applicable law, it shall not affect the validity or enforceability 567 | of the remainder of the terms of this License, and without further 568 | action by the parties to this agreement, such provision shall be 569 | reformed to the minimum extent necessary to make such provision 570 | valid and enforceable. 571 | 572 | No term or provision of this License shall be deemed waived and no 573 | breach consented to unless such waiver or consent shall be in 574 | writing and signed by the party to be charged with such waiver or 575 | consent. 576 | 577 | This License constitutes the entire agreement between the parties 578 | with respect to the Work licensed here. There are no 579 | understandings, agreements or representations with respect to the 580 | Work not specified here. Licensor shall not be bound by any 581 | additional provisions that may appear in any communication from 582 | You. This License may not be modified without the mutual written 583 | agreement of the Licensor and You. 584 | 585 | The rights granted under, and the subject matter referenced, in 586 | this License were drafted utilizing the terminology of the Berne 587 | Convention for the Protection of Literary and Artistic Works (as 588 | amended on September 28, 1979), the Rome Convention of 1961, the 589 | WIPO Copyright Treaty of 1996, the WIPO Performances and 590 | Phonograms Treaty of 1996 and the Universal Copyright Convention 591 | (as revised on July 24, 1971). These rights and subject matter 592 | take effect in the relevant jurisdiction in which the License 593 | terms are sought to be enforced according to the corresponding 594 | provisions of the implementation of those treaty provisions in the 595 | applicable national law. If the standard suite of rights granted 596 | under applicable copyright law includes additional rights not 597 | granted under this License, such additional rights are deemed to 598 | be included in the License; this License is not intended to 599 | restrict the license of any rights under applicable law. 600 | -------------------------------------------------------------------------------- /Changelog: -------------------------------------------------------------------------------- 1 | 1.2.0 / 2012-05-17 2 | 3 | * Add support for named hooks. 4 | * Add support for Clojure 1.3+. 5 | 6 | 1.1.3 / 2012-01-16 7 | 8 | * Fix clear-hooks when no hooks exists yet. 9 | 10 | 1.1.2 / 2011-06-30 11 | 12 | * Fix compatibility with Clojure 1.3. 13 | 14 | 1.1.1 / 2011-06-02 15 | 16 | * Allow Hooke's functions to be injected into other namespaces. 17 | 18 | 1.1.0 / 2010-11-11 19 | 20 | * Add prepend/append macros. 21 | 22 | * Add with-hooks-disabled macro. 23 | 24 | 1.0.2 / 2010-07-02 25 | 26 | * Fix bug where re-running add-hook would repeatedly nest hook runner. 27 | 28 | 1.0.1 / 2010-06-11 29 | 30 | * Fix documentation bug. 31 | 32 | 1.0.0 / 2010-06-10 33 | 34 | * Initial Commit. 35 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # This place is not a place of honor... no highly esteemed deed is commemorated here... nothing valued is here. 2 | 3 | This project is no longer maintained, and you are strongly advised 4 | against using it. In every case where it was adopted long-term in a 5 | codebase, it created more problems than it solved, causing situations 6 | that were difficult to debug and reason about. If you wish to create 7 | an extension mechanism for your code, it's recommended to develop 8 | something more structured that facilitates debugging and 9 | understanding. 10 | 11 | This code is best left shunned and unused. 12 | 13 | ## Robert Hooke 14 | 15 | Robert Hooke provides a flexible, composable mechanism by which you 16 | can extend behaviour of functions after they've been defined. It's named 17 | after [Robert Hooke FRS](http://en.wikipedia.org/wiki/Robert_Hooke), a 18 | founding member of the Royal Society who made many important 19 | discoveries in the fields of Gravitation, Microscopy, and Astronomy. 20 | 21 | Hooks can change the behaviour of the functions they wrap in many 22 | ways: 23 | 24 | * binding 25 | * conditional execution (may decide not to continue or decide to call 26 | a different function in some circumstances) 27 | * modify arguments 28 | * add side effects 29 | * return different value 30 | 31 | Hooke is inspired by Emacs Lisp's defadvice and clojure.test fixtures. 32 | 33 | ## Usage 34 | 35 | ```clj 36 | (use 'robert.hooke) 37 | 38 | (defn examine [x] 39 | (println x)) 40 | 41 | (defn microscope 42 | "The keen powers of observation enabled by Robert Hooke allow 43 | for a closer look at any object!" 44 | [f x] 45 | (f (.toUpperCase x))) 46 | 47 | (defn doubler [f & args] 48 | (apply f args) 49 | (apply f args)) 50 | 51 | (defn telescope [f x] 52 | (f (apply str (interpose " " x)))) 53 | 54 | (add-hook #'examine #'microscope) 55 | (add-hook #'examine #'doubler) 56 | (add-hook #'examine #'telescope) 57 | 58 | (examine "something") 59 | > S O M E T H I N G 60 | > S O M E T H I N G 61 | ``` 62 | 63 | Hooks are functions that wrap other functions. They receive the 64 | original function and its arguments as their arguments. Hook 65 | functions can wrap the target functions in binding, change the 66 | argument list, only run the target functions conditionally, or all 67 | sorts of other stuff. 68 | 69 | Technically the first argument to a hook function is not always the 70 | target function; if there is more than one hook then the first hook 71 | will receive a function that is a composition of the remaining 72 | hooks. (Dare I say a continuation?) But when you're writing hooks, you 73 | should act as if it is the target function. 74 | 75 | Adding hooks to a defmulti is discouraged as it will make it 76 | impossible to add further methods. Hooks are meant to extend functions 77 | you don't control; if you own the target function there are obviously 78 | better ways to change its behaviour. 79 | 80 | When adding hooks it's best to use vars instead of raw functions in 81 | order to allow the code to be reloaded interactively. If you recompile 82 | a function, it will be re-added as a hook, but if you use a var it 83 | will be able to detect that it's the same thing across reloads and 84 | avoid duplication. 85 | 86 | ```clj 87 | (add-hook #'some.ns/target-var #'hook-function) 88 | ``` 89 | 90 | instead of: 91 | 92 | ```clj 93 | (add-hook #'some.ns/target-var hook-function) 94 | ``` 95 | 96 | ## Bonus Features 97 | 98 | Most of the time you'll never need more than just add-hook. But 99 | there's more! 100 | 101 | If you are using Hooke just to add side-effects to a function, it may 102 | be simpler to use the `append` or `prepend` macros: 103 | 104 | ``` 105 | (prepend print-name 106 | (print "The following person is awesome:")) 107 | 108 | (print-name "Gilbert K. Chesterton") 109 | > The following person is awesome: 110 | > Gilbert K. Chesterton 111 | ``` 112 | 113 | You may also run a block of code with the hooks for a given var 114 | stripped out: 115 | 116 | ```clj 117 | (with-hooks-disabled print-name 118 | (print-name "Alan Moore")) 119 | > Alan Moore 120 | ``` 121 | 122 | The `with-scope` macro provides a scope which records any change to hooks during 123 | the dynamic scope of its body, and restores hooks to their original state on 124 | exit of the scope. Note that all threads share the scope. Using the example 125 | functions above: 126 | 127 | (examine "something") 128 | > something 129 | 130 | (with-scope 131 | (add-hook #'examine #'microscope) 132 | (examine "something")) 133 | > SOMETHING 134 | 135 | (examine "something") 136 | > something 137 | 138 | ## License 139 | 140 | Copyright © 2010-2012 Phil Hagelberg, Kevin Downey, and contributors. 141 | 142 | Distributed under the Eclipse Public License, the same as Clojure. 143 | -------------------------------------------------------------------------------- /project.clj: -------------------------------------------------------------------------------- 1 | (defproject robert/hooke "1.3.0" 2 | :description "Hooke your functions!" 3 | :url "https://github.com/technomancy/robert-hooke" 4 | :profiles {:dev {:dependencies [[org.clojure/clojure "1.4.0"]]}} 5 | :license {:name "Eclipse Public License" 6 | :url "http://www.eclipse.org/legal/epl-v10.html"}) 7 | -------------------------------------------------------------------------------- /src/robert/hooke.clj: -------------------------------------------------------------------------------- 1 | (ns robert.hooke 2 | "Hooke your functions! 3 | 4 | (defn examine [x] 5 | (println x)) 6 | 7 | (defn microscope 8 | \"The keen powers of observation enabled by Robert Hooke allow 9 | for a closer look at any object!\" 10 | [f x] 11 | (f (.toUpperCase (str x)))) 12 | 13 | (defn doubler [f & args] 14 | (apply f args) 15 | (apply f args)) 16 | 17 | (defn telescope [f x] 18 | (f (apply str (interpose \" \" x)))) 19 | 20 | (add-hook #'examine #'microscope) 21 | (add-hook #'examine #'doubler) 22 | (add-hook #'examine #'telescope) 23 | 24 | ;; Now when we examine something: 25 | (examine \"something\") 26 | > S O M E T H I N G 27 | > S O M E T H I N G 28 | 29 | Use the add-hook function to wrap a function in your a hook.") 30 | 31 | (defn- hooks [v] 32 | (-> @v meta ::hooks)) 33 | 34 | (defn- original [v] 35 | (-> @v meta ::original)) 36 | 37 | (defn- compose-hooks [f1 f2] 38 | (fn [& args] 39 | ;; TODO: tracing 40 | (apply f2 f1 args))) 41 | 42 | (defn- join-hooks [original hooks] 43 | (reduce compose-hooks original hooks)) 44 | 45 | (defn- run-hooks [hooks original args] 46 | (apply (join-hooks original hooks) args)) 47 | 48 | (defn- prepare-for-hooks [v] 49 | (when-not (hooks v) 50 | (let [hooks (atom {})] 51 | (alter-var-root v (fn [original] 52 | (with-meta 53 | (fn [& args] 54 | (run-hooks (vals @hooks) original args)) 55 | (assoc (meta original) 56 | ::hooks hooks 57 | ::original original))))))) 58 | 59 | (defonce hook-scopes []) 60 | 61 | (defn start-scope [] 62 | (locking hook-scopes 63 | (alter-var-root #'hook-scopes conj {}))) 64 | 65 | (defn- scope-update-fn 66 | [scopes target-var] 67 | (conj 68 | (pop scopes) 69 | (update-in (peek scopes) [target-var] #(if % % @(hooks target-var))))) 70 | 71 | (defn- possibly-record-in-scope 72 | [target-var] 73 | (locking hook-scopes 74 | (when (seq hook-scopes) 75 | (alter-var-root #'hook-scopes scope-update-fn target-var)))) 76 | 77 | (defn end-scope [] 78 | (locking hook-scopes 79 | (let [head (peek hook-scopes)] 80 | (alter-var-root #'hook-scopes pop) 81 | (doseq [[var old-hooks] head] 82 | (reset! (hooks var) old-hooks))))) 83 | 84 | (defmacro with-scope 85 | "Defines a scope which records any change to hooks during the dynamic extent 86 | of its body, and restores hooks to their original state on exit of the scope." 87 | [& body] 88 | `(try 89 | (start-scope) 90 | ~@body 91 | (finally (end-scope)))) 92 | 93 | (defn add-hook 94 | "Add a hook function f to target-var. Hook functions are passed the 95 | target function and all their arguments and must apply the target to 96 | the args if they wish to continue execution." 97 | ([target-var f] 98 | (add-hook target-var f f)) 99 | ([target-var key f] 100 | (prepare-for-hooks target-var) 101 | (possibly-record-in-scope target-var) 102 | (swap! (hooks target-var) assoc key f))) 103 | 104 | (defn- clear-hook-mechanism [target-var] 105 | (alter-var-root target-var 106 | (constantly (original target-var)))) 107 | 108 | (defn remove-hook 109 | "Remove hook identified by key from target-var." 110 | [target-var key] 111 | (when-let [hooks (hooks target-var)] 112 | (swap! hooks dissoc key) 113 | (when (empty? @hooks) 114 | (clear-hook-mechanism target-var)))) 115 | 116 | (defn clear-hooks 117 | "Remove all hooks from target-var." 118 | [target-var] 119 | (when-let [hooks (hooks target-var)] 120 | (swap! hooks empty) 121 | (clear-hook-mechanism target-var))) 122 | 123 | (defmacro prepend [target-var & body] 124 | `(add-hook (var ~target-var) (fn [f# & args#] 125 | ~@body 126 | (apply f# args#)))) 127 | 128 | (defmacro append [target-var & body] 129 | `(add-hook (var ~target-var) (fn [f# & args#] 130 | (let [val# (apply f# args#)] 131 | ~@body 132 | val#)))) 133 | 134 | (defmacro with-hooks-disabled [f & body] 135 | `(do (when-not (#'hooks (var ~f)) 136 | (throw (Exception. (str "No hooks on " ~f)))) 137 | (with-redefs [~f (#'original (var ~f))] 138 | ~@body))) 139 | -------------------------------------------------------------------------------- /test/robert/test_hooke.clj: -------------------------------------------------------------------------------- 1 | (ns robert.test-hooke 2 | (:use [robert.hooke] :reload-all) 3 | (:use [clojure.test])) 4 | 5 | (deftest test-no-arg 6 | (defn no-args [] 7 | (println "mine")) 8 | (add-hook #'no-args (fn h1 [f] (do (println "h1") (f)))) 9 | (add-hook #'no-args (fn h2 [f & args] (do (println "h2") (apply f args)))) 10 | (is (= "h1\nh2\nmine\n" 11 | (with-out-str (no-args))))) 12 | 13 | (deftest test-one-arg 14 | (defn one-arg [x] 15 | (println "arg" x)) 16 | (add-hook #'one-arg (fn h2 [f & args] (do (println "h2") (apply f args)))) 17 | (is (= "h2\narg hi\n" 18 | (with-out-str (one-arg "hi"))))) 19 | 20 | (defn hooked [] 21 | true) 22 | (defn asplode [f] 23 | (/ 9 0)) 24 | 25 | (deftest test-remove-hook 26 | (let [orig-hooked hooked] 27 | (add-hook #'hooked asplode) 28 | (is (not= hooked orig-hooked)) 29 | (is (thrown? Exception (hooked))) 30 | (remove-hook #'hooked asplode) 31 | (is (= hooked orig-hooked)) 32 | (is (hooked)))) 33 | 34 | (deftest test-clear-hooks 35 | (letfn [(hooked? [v] 36 | (contains? (meta @v) :robert.hooke/hooks))] 37 | (is (not (hooked? #'hooked))) 38 | (add-hook #'hooked #'asplode) 39 | (is (hooked? #'hooked)) 40 | (clear-hooks #'hooked) 41 | (is (not (hooked? #'hooked))) 42 | (is (= nil (clear-hooks #'hooked))) 43 | (is (not (hooked? #'hooked))))) 44 | 45 | (defn print-name [name] 46 | (println name)) 47 | 48 | (deftest test-prepend 49 | (prepend print-name 50 | (println "The following person is awesome:")) 51 | (is (= "The following person is awesome:\nGilbert K. Chesterton\n" 52 | (with-out-str 53 | (print-name "Gilbert K. Chesterton"))))) 54 | 55 | (defn ohai [] 56 | :hello) 57 | 58 | (def appended (atom false)) 59 | 60 | (deftest test-append 61 | (append ohai (reset! appended true)) 62 | (is (= :hello (ohai))) 63 | (is @appended)) 64 | 65 | (defn another-fn [] 66 | true) 67 | 68 | (deftest test-without-hooks 69 | (add-hook #'another-fn asplode) 70 | (is (thrown? Exception (another-fn))) 71 | (with-hooks-disabled another-fn 72 | (is (another-fn)))) 73 | 74 | (defn keyed [x] x) 75 | 76 | (deftest test-hooks-with-keys 77 | (is (= (keyed 1) 1)) 78 | (add-hook #'keyed :inc (fn [f x] (f (inc x)))) 79 | (is (= (keyed 1) 2)) 80 | (add-hook #'keyed :add-3 (fn [f x] (f (+ 3 x)))) 81 | (is (= (keyed 1) 5)) 82 | (remove-hook #'keyed :inc) 83 | (is (= (keyed 1) 4)) 84 | (clear-hooks #'keyed) 85 | (is (= (keyed 1) 1))) 86 | 87 | (deftest hook-scope-test 88 | (is (hooked)) 89 | (with-scope 90 | (add-hook #'hooked asplode) 91 | (is (thrown? Exception (hooked)))) 92 | (is (hooked))) 93 | --------------------------------------------------------------------------------