gall-guide

#urbit

Skeleton Gall agent:

^-  agent:gall
=|  state=@
|_  bowl:gall
+*  this  .
++  on-init
  `this
::
++  on-save
  !>(state)
::
++  on-load
  |=  =old-state=vase
  `this(state !<(@ old-state-vase))
::
++  on-poke
  |=  [=mark =vase]
  ~&  >  state=state
  ~&  got-poked-with-data=mark
  =.  state  +(state)
  `this
::
++  on-watch
  |=  path
  `this
::
++  on-leave
  |=  path
  `this
::
++  on-peek
  |=  path
  *(unit (unit cage))
::
++  on-agent
  |=  [wire sign:agent:gall]
  `this
::
++  on-arvo
  |=  [wire sign-arvo]
  `this
::
++  on-fail
  |=  [term tang]
  `this
--

default gall agent:

/+  default-agent
^-  agent:gall
=|  state=@
|_  =bowl:gall
+*  this      .
    default   ~(. (default-agent this %|) bowl)
::
++  on-init   on-init:default
++  on-save   on-save:default
++  on-load   on-load:default
++  on-poke
  |=  [=mark =vase]
  ~&  >  state=state
  ~&  got-poked-with-data=mark
  =.  state  +(state)
  `this
::
++  on-watch  on-watch:default
++  on-leave  on-leave:default
++  on-peek   on-peek:default
++  on-agent  on-agent:default
++  on-arvo   on-arvo:default
++  on-fail   on-fail:default
--

Virtual Arms

(more than 10 arms in a core requires virtual arms)

Defined with +*

+*  this  .
    def   ~(. (default-agent this %.n) bowl)

this and def are the deferred statements, the stuff to their right is the hoon evaluated when they’re called.

dbug

import:

/+  dbug

add directly above agent’s door:

%-  agent:dbug

Use:

dojo> :agent-name +dbug
:: all of agent's state

dojo> :agent-name +dbug %bowl
:: agent's bowl

dojo> :agent-name +dbug [%state 'some code']
:: eval some code with agent's state as subject
:: like [%state %a-face-here]
::      print content of wing with a-face-here

dojo> :agent-name [%incoming ...] :: incoming subs
::    [%incoming %ship ~sampel-palnet]
::    [%incoming %path /part/of/path]
::    [%incoming %wire /part/of/wire]

dojo> :agent-name [%outgoing ...] :: outgoing subs
::    [%outgoing %ship ~sampel-palnet]
::    [%outgoing %path /part/of/path]
::    [%outgoing %wire /part/of/wire]
::    [%outgoing %term %agent-name]

Links to this page
#urbit