| … | … | @@ -407,6 +407,25 @@ |
| 407 | 407 | ; --------------------------------------------------------------------- |
| 408 | 408 | ; Assign initial susceptibility and infirmity values to individuals |
| 409 | 409 | ; in the network. These will be randomly generated numbers. |
| 410 | ; |
| 411 | ; This will be done twice, illustrating two different styles of coding. |
| 412 | ; The first style is a traditional, scheme list (srfi-1) style of |
| 413 | ; coding, something that a naive coder might attempt. (This is not |
| 414 | ; scheme-specific; python coders might code the same way, if this |
| 415 | ; demo was written in python.) Despite every attempt to "keep it |
| 416 | ; simple", this code quickly becomes opaque and hard to understand. |
| 417 | ; Thus, the first thing shown is NOT the recommended style. |
| 418 | ; |
| 419 | ; The second time, it will be done in Atomese. The code is recognizably |
| 420 | ; identical to the first attempt, but with far fewer calls to srfi-1 |
| 421 | ; routines to manage and transform lists. This is because Atomese, |
| 422 | ; and specifically, the Atomese query language, is far more compact in |
| 423 | ; managing state. You don't have to juggle things around with maps |
| 424 | ; and lists and functions -- the query language manages all this, |
| 425 | ; automatically. |
| 426 | ; |
| 427 | ; ---------- |
| 428 | ; So: version 1: traditional software proramming style. |
| 410 | 429 | |
| 411 | 430 | ; Each individual is linked back to the anchor node. Each individual |
| 412 | 431 | ; is also represented with a ConceptNode (we have some other junk |
| … | … | @@ -434,9 +453,13 @@ |
| 434 | 453 | (cog-execute! (RandomNumber (Number 0.6) (Number 0.95))))) |
| 435 | 454 | individual-list) |
| 436 | 455 | |
| 456 | ; ---------- |
| 457 | ; So: version 2: Atomese query language proramming style. |
| 458 | |
| 437 | 459 | ; The above uses a very traditional scheme `for-each` loop to perform |
| 438 | | ; the initialization. This could also be done directly, in Atomese, as |
| 439 | | ; shown below. |
| 460 | ; the initialization. The Atomese query language automatically iterates |
| 461 | ; over the entire contents of the AtomSpace, so this loop is not |
| 462 | ; explicitly needed. |
| 440 | 463 | |
| 441 | 464 | ; ------ But first, a handy utility: |
| 442 | 465 | ; Execute some Atomese. Assume that it returns a SetLink. |