OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-generate commits / 481294d

Add notes about coding style.
481294dd6584b1e3f63dfd18c1d2468df3a264d8
by Linas Vepstas <linasvepstas@gmail.com> · 2020-04-22T15:56:10.000Z

Changed files (1) +25 -2

demo/seir.scm +25 -2
……@@ -407,6 +407,25 @@
407407; ---------------------------------------------------------------------
408408; Assign initial susceptibility and infirmity values to individuals
409409; 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.
410429
411430; Each individual is linked back to the anchor node. Each individual
412431; is also represented with a ConceptNode (we have some other junk
……@@ -434,9 +453,13 @@
434453 (cog-execute! (RandomNumber (Number 0.6) (Number 0.95)))))
435454 individual-list)
436455
456; ----------
457; So: version 2: Atomese query language proramming style.
458
437459; 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.
440463
441464; ------ But first, a handy utility:
442465; Execute some Atomese. Assume that it returns a SetLink.