--- layout: ../Site.layout.js --- # Leonardo Calculus Knowledge Representation: Fleshing out organism's attributes [Over here](/lispgames/plant-insect-bird-ontology) we got to `{plant insect bird}` `thingtype`s all being `subsumed-by` the `organism` `thingtype` for the purpose of a [Braitenberg's Vehicles](/complex/book-review-braitenberg-vehicles)-esque simulation redux of [a lispgamejam week of mine](/lispgames/last-five-hours-lispgame) using [Sandewall's Leonardo System (link is my involved academic openaccess bibliography collection)](/complex/Sandewall-caisor-bibliography). Rather than argue with some hypothetical expert locked into some knowledge representation framework vendor being unfamiliar with [Erik Sandewall](https://liu.se/en/news-item/erik-sandewall-har-avlidit)'s [Leonardo System](https://www.ida.liu.se/ext/leonardo) ([Franz success story](https://franz.com/success/customer_apps/knowledge_mgmt/leordo.lhtml)) and half-century of academic work building into it and eventually, treating it. let us simply continue exercising Sandewall's Leonardo Calculus together. The `organisms` `entityfile` `organism` `entity`, then. I will keep working on my language (last article, I had some confusion between "universe" and "knowledgebase" - this is similar to mistaking between the software engineering terms "superclass" and "parent class" which is a mistake I also make sometimes). ## Quick peek at the initial underlying logical structure after the last article After the previously mentioned starting point, `organisms`' [low level persisted logical state can be read directly over here](/lispgames/organisms.leo.0.txt) (very readable but it *is* a dense logic language clearly hosted by ANSI common lisp). The version persisted at the end of this small article will be available for your review. ``` --------------------------------------------------------- -- organisms [: type entityfile] [: latest-written "2025-07-13/09:06.+12"] [: contents ] [: changed-since-archived t] [: nullvalued {has-purpose has-author requires mustload removed-entities leos-extension has-profile overlay-on overlay-types overlay-own leos-use dont-display sections local-ents purpose author latest-archived-entity latest-rearchived}] --------------------------------------------------------- -- organism [: type thingtype] [: nullvalued {description subsumed-by attributes has-attributes has-categories create-proc registr-proc latest-rearchived}] ooooooooooooooooooooooooooooooooooooooooooooooooooooooooo ``` ## Setup [Exactly the same as the setup before (also linked above)](/lispgames/plant-insect-bird-ontology). If your environment was less comfy than mine, you would not have to get yourself comfy in quite the same way, but that would not be comfy, so. ` (setq eepitch-buffer-name "*slime-repl clisp*")` ## Quick recap of `thingtype`s We persist things in `entityfile`s. A thing without a `type` that is a currently loaded `thingtype` is not persisted. Setting a thing's `type` to `NIL` and persisting the entityfile is a basic way to get it removed from that entityfile (technically, it gets removed from the `entityfile`'s `contents` when it's loaded next after being written with a type of NIL, but this is a low level detail). Obviously the `thingtype` `type` is always made available to us for adding our own new `type`s. When a thing of a currently known `thingtype` is saved in an `entityfile` by `writefil`, only the `attributes` it is currently defined to have get written. This is the meaning of the `attributes` we are about to add to our `organism` `thingtype`. ## Adding `organism`'s attributes Since all of `{plant insect bird}` get `subsumed-by` our `organism`, I guess this is the important one. `loadk organisms-kb` `loadk organisms` `(get organism attributes)` => nil by the way, we can sneak a look at the underlying common lisp implementation here `. (symbol-plist 'organism)` => ``` ses.019) loadk organisms Load-ef: organisms at ../../../demus/Organisms/organisms.leo ses.020) (get organism attributes) => nil ses.021) . (symbol-plist 'organism) (has-phrases nil latest-rearchived nil registr-proc nil create-proc nil has-categories nil has-attributes nil attributes nil subsumed-by nil description nil textprops nil read-in-file organisms nullvalued (set& (description subsumed-by attributes has-attributes has-categories create-proc registr-proc latest-rearchived)) type thingtype) ses.022) ``` for everyone not playing along, this is what we are seeing in the other half of our screens as we keep pressing `F8` at interesting lines in these articles. Let's get to adding some attributes to our `organism`. ### `x-position` and `y-position` Remembering we're making a game/simulation. `put organism attributes {x-position y-position}` Now if we `writefil organisms` `loadk organisms` `(get organism attributes)` => ``` ses.028) writefil organisms writeloc-file-leo: ../../../demus/Organisms/organisms.leo ses.029) loadk organisms Load-ef: organisms at ../../../demus/Organisms/organisms.leo ses.030) (get organism attributes) => {x-position y-position} ``` how exciting. Actually, let's ### Add some organism to the `world` `entityfile` we made before `loadk world` Let's make a `coelacanth` with the `organism` type `put coelacanth type organism` Some values for our `attributes` so far `put coelacanth x-position 1` `put coelacanth y-position -3/2` And an unspecified attribute `put coelacanth extinct t` then put the `coelacanth` in the `world` and `writefil` `addmember (get world contents) coelacanth` `writefil world` and let's manually nuke the attributes from lisp to simulate cold booting between accesses. `. (setf (symbol-plist 'coelacanth) nil)` `loadk world` `(get coelacanth extinct)` `(get coelacanth y-position)` => ``` ses.042) loadk world Load-ef: world at ../../../demus/Organisms/world.leo ses.043) (get coelacanth extinct) => nil ses.044) (Get coelacanth y-position) evexprec: undefined function Get => nil ses.045) (get coelacanth y-position) => -3/2 ``` just as we want. ### Propagation Admittedly, around now I am just saying ideas of mine for the simulation game. `addmember (get organism attributes) natality-rate` `addmember (get organism attributes) mortality-rate` `addmember (get organism attributes) propagation-distance` ### Related to eating `addmember (get organism attributes) eating-distance` `addmember (get organism attributes) lethality-rate` i.e. likelihood the target of eating dies. I'm imagining that `insect` stands for swarm-of-insects- so a bird eating an `insect` may or may not lead to dispersal of the `insect` as such. `addmember (get organism attributes) starvation-rate` thinking that if an organism fails to eat, it has some probability of dying. `addmember (get organism attributes) prey-species` e.g. trees don't have any prey, birds don't eat trees, insects might not eat birds. ### Sensing oriented attributes Listen, and separately to the knowledge representation framework stuff, my idea for Breitenbergian Vehicles oriented sensors in this game simulation is that the sensors "look" in knights-moves relative to their `current-direction` orientation, where the orientation lies on 8 compass points. So the sensors are always left or right. Then there should be an `opening-angle` attribute. Sensors that see larger areas could follow the same pattern, but zoomed out with a `sensor-scale`. `polarity` so we can turn towards or away. `put organism attributes (union (get organism attributes) {current-direction opening-angle sensor-scale polarity})` okay, I was fishing a bit to show `union` being used. And we added everything that occurs to me for the simulation to be *done right this time*. Addition: It occured to me, different `organism` `type`s could register at different strengths with the `sensor` mechanism. `addmember (get organism attributes) sensor-weights` which will be a mapping of `organism`-descent `thingtype`s to numeric weights. ## Write our changes `writefil organisms` `loadk organisms` and the latest `organisms` logic is: ``` --------------------------------------------------------- -- organisms [: type entityfile] [: latest-written "2025-07-13/20:14.+12"] [: contents ] [: changed-since-archived t] [: nullvalued {has-purpose has-author requires mustload removed-entities leos-extension has-profile overlay-on overlay-types overlay-own leos-use dont-display sections local-ents purpose author latest-archived-entity latest-rearchived}] --------------------------------------------------------- -- organism [: type thingtype] [: attributes {x-position y-position starvation-rate current-direction opening-angle sensor-scale natality-rate mortality-rate propagation-distance eating-distance lethality-rate prey-species sensor-weights}] [: nullvalued {description subsumed-by has-attributes has-categories create-proc registr-proc latest-rearchived}] ooooooooooooooooooooooooooooooooooooooooooooooooooooooooo ``` You can see our `attributes` are now in that `thingtype`. Let's check out that `coelacanth` we put in the `world` as well actually ``` --------------------------------------------------------- -- world [: type entityfile] [: latest-written "2025-07-13/09:14.+12"] [: contents ] [: changed-since-archived t] [: nullvalued {has-purpose has-author requires mustload removed-entities leos-extension has-profile overlay-on overlay-types overlay-own leos-use dont-display sections local-ents purpose author latest-archived-entity latest-rearchived}] --------------------------------------------------------- -- coelacanth [: type organism] [: x-position 1] [: y-position -3/2] [: latest-rearchived nil] ooooooooooooooooooooooooooooooooooooooooooooooooooooooooo ``` Remembering world was written when the `organism` `thingtype` only had those two attributes so the `coelacanth` lost its `extinct` attribute value when 'cold-booted'. # Conclusion We learned how known (maybe new) `thingtype` entities can be `type`s for other entities, and that only currently known `attributes` of a given `thingtype` will be recorded for entities having that `type`. Then we just added a bunch of these for my simulation game idea at that jam, incidentally seeing `union` in action, which is actually a more subtle point than I'm making it out to be (why are `get` and `union` special?), but let us just leave it here for this article. Next article we should add some actions to our knowledgebase, I think. I'm holding off on getting into the low level underlying basis of Leonardo calculus formal onotologies, which is basically a first order logic extended in the direction of action calculus. In my opinion we should avoid swamping a useful and productive conversation with hypothetical arguements about what its low level details might be: You are very welcome to directly check details in Sandewall's fifty years of supporting academic publications and two handbooks on the leonardo calculus yourself. My decision is to focus on practical utility first. It took me quite a long time to get my head around the metacircularly defined implementation (the Leonardo system is written in the Leonardo system) and read much of Sandewall's life bibliography. In my view this is a good starting point. # Fin See you to talk about this [on the Mastodon thread please everyone](https://gamerplus.org/@screwlisp/114847907897334628). This arc of articles, I want to reconnect with gamedev as a central theme, and introduce Sandewall's external-release paradigm from his *Biological Software* for https://itch.io games. You are very welcome to share this article how and where occurs to you. Broadening our conversation to include others will be good for everyone.