<commit_before>;;;; Erlangen public API.

(in-package :erlangen)

(defun send (message agent)
  "*Arguments and Values:*

   _message_—an _object_.

   _agent_—an _agent_.

   *Description*:

   {send} delivers _message_ to _agent_.

   *Exceptional Situations:*

   If _message_ could not be delivered successfully an _error_ of _type_
   {send-error} is signaled."
  (etypecase agent
    (erlangen.agent:agent (erlangen.agent:send message agent))
    (keyword (erlangen.agent:send message (agent-by-name agent)))
    (string (remote-send message agent))))

(defun exit (&optional (reason :kill) (agent (agent)))
  "*Arguments and Values:*

   _reason_—an _object_.

   _agent_—an _agent_. Default is the _calling agent_.

   *Description*:

   {exit} kills _agent_ with _reason_ as the _exit reason_. Subsequent attempts
   to send messages to _agent_ will fail. If _agent_ is the _calling agent_ it
   exits immediately, otherwise {exit} delivers an _exit message_ to _agent_.

   *Exceptional Situations:*

   If _agent_ is not the _calling agent_, and the _exit message_ could not
   be delivered successfully an _error_ of _type_ {send-error} is
   signaled."
  (etypecase agent
    (erlangen.agent:agent (erlangen.agent:exit reason agent))
    (keyword (erlangen.agent:exit reason (agent-by-name agent)))
    (string (remote-exit reason agent))))

(defun spawn (function &key attach (mailbox-size *default-mailbox-size*)
                            (host (host-name)) node)
  "*Arguments and Values:*

   _function_—a _function designator_ or a _call_.

   _attach_—a _keyword_ or {nil}.

   _mailbox-size_—a positive _unsigned integer_. The default is
   {*default-mailbox-size*}.

   *Description:*

   {spawn} starts and returns a new _agent_ with a mailbox capacity of
   _mailbox-size_. If _attach_ is {:link} or {:monitor} the _calling
   agent_ will be linked to the new _agent_ as if by {link} but before
   the _agent_ is started. Once the _agent_ is started it will execute
   _function_."
  (if (null node)
      (erlangen.agent:spawn (etypecase function
                              ((or function symbol) function)
                              (call (make-function function)))
                            :attach attach
                            :mailbox-size mailbox-size)
      (remote-spawn host
                    node
                    (if (symbolp function)
                        (list function)
                        function)
                    (and attach (agent-id (agent)))
                    attach
                    mailbox-size)))

(defun link (agent &optional (mode :link))
  "*Arguments and Values:*

   _agent_—an _agent_.

   _mode_—a _keyword_. Either {:link} or {:monitor}. Defaults to {:link}.

   *Description*:
<commit_msg>SPAWN: fix bug where calling agent ignored ATTACH for remote agents.<commit_after>;;;; Erlangen public API.

(in-package :erlangen)

(defun send (message agent)
  "*Arguments and Values:*

   _message_—an _object_.

   _agent_—an _agent_.

   *Description*:

   {send} delivers _message_ to _agent_.

   *Exceptional Situations:*

   If _message_ could not be delivered successfully an _error_ of _type_
   {send-error} is signaled."
  (etypecase agent
    (erlangen.agent:agent (erlangen.agent:send message agent))
    (keyword (erlangen.agent:send message (agent-by-name agent)))
    (string (remote-send message agent))))

(defun exit (&optional (reason :kill) (agent (agent)))
  "*Arguments and Values:*

   _reason_—an _object_.

   _agent_—an _agent_. Default is the _calling agent_.

   *Description*:

   {exit} kills _agent_ with _reason_ as the _exit reason_. Subsequent attempts
   to send messages to _agent_ will fail. If _agent_ is the _calling agent_ it
   exits immediately, otherwise {exit} delivers an _exit message_ to _agent_.

   *Exceptional Situations:*

   If _agent_ is not the _calling agent_, and the _exit message_ could not
   be delivered successfully an _error_ of _type_ {send-error} is
   signaled."
  (etypecase agent
    (erlangen.agent:agent (erlangen.agent:exit reason agent))
    (keyword (erlangen.agent:exit reason (agent-by-name agent)))
    (string (remote-exit reason agent))))

(defun spawn (function &key attach (mailbox-size *default-mailbox-size*)
                            (host (host-name)) node)
  "*Arguments and Values:*

   _function_—a _function designator_ or a _call_.

   _attach_—a _keyword_ or {nil}.

   _mailbox-size_—a positive _unsigned integer_. The default is
   {*default-mailbox-size*}.

   *Description:*

   {spawn} starts and returns a new _agent_ with a mailbox capacity of
   _mailbox-size_. If _attach_ is {:link} or {:monitor} the _calling
   agent_ will be linked to the new _agent_ as if by {link} but before
   the _agent_ is started. Once the _agent_ is started it will execute
   _function_."
  (if (null node)
      (erlangen.agent:spawn (etypecase function
                              ((or function symbol) function)
                              (call (make-function function)))
                            :attach attach
                            :mailbox-size mailbox-size)
      (let ((agent (remote-spawn host
                                 node
                                 (if (symbolp function)
                                     (list function)
                                     function)
                                 (and attach (agent-id (agent)))
                                 attach
                                 mailbox-size)))
        (when attach
          (erlangen.agent:link agent attach))
        agent)))

(defun link (agent &optional (mode :link))
  "*Arguments and Values:*

   _agent_—an _agent_.

   _mode_—a _keyword_. Either {:link} or {:monitor}. Defaults to {:link}.

   *Description*:

{'fraction_non_alphanumeric': 0.08960882302257453, 'fraction_numerical': 0.0, 'mean_word_length': 2.370499419279907, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4173833', 'n_tokens_mistral': 1712, 'n_tokens_neox': 1637, 'n_words': 582}