<commit_before><commit_msg>Added another messenger example.<commit_after>;; Copyright (c) 2013 <NAME> <<EMAIL>>
;;
;; Licensed under the Apache License, Version 2.0 (the "License");
;; you may not use this file except in compliance with the License.
;; You may obtain a copy of the License at
;;
;;     http://www.apache.org/licenses/LICENSE-2.0
;;
;; Unless required by applicable law or agreed to in writing, software
;; distributed under the License is distributed on an "AS IS" BASIS,
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;; See the License for the specific language governing permissions and
;; limitations under the License.

;; File    : messenger-back.lfe
;; Author  : <NAME>
;; Purpose : Demonstrating bidirectional message passing between the shell and
;;           aspawned process.

;; This file contains a simple demo for passing messages to an Erlang process
;; in LFE and the sending a message back to the calling process. To use, do the
;; following:
;;
;;     $ ./bin/lfe -pa ./ebin
;;     > (c '"examples/messenger-back")
;;     #(module messenger-back)
;;     > (: messenger-back send-message (self) '"Well, I was able to extend the original entry a bit, yes.")
;;     #(<0.25.0> "Well, I was able to extend the original entry a bit, yes.")
;;     Received message: 'Well, I was able to extend the original entry a bit, yes.'
;;     > Sending message to process <0.25.0> ...
;;     (: messenger-back send-message (self) '"And what does it say now?")
;;     #(<0.25.0> "And what does it say now?")
;;     Received message: 'And what does it say now?'
;;     > Sending message to process <0.25.0> ...
;;     (: messenger-back send-message (self) '"Mostly harmless.")
;;     #(<0.25.0> "Mostly harmless.")
;;     Received message: 'Mostly harmless.'
;;     > Sending message to process <0.25.0> ...

;; With the messages sent and then resent back to the process whose ID was
;; presented, we can check to see that the calling process received the
;; information, as planned:
;;
;;     > (: c flush)
;;     Shell got {"Well, I was able to extend the original entry a bit, yes."}
;;     Shell got {"And what does it say now?"}
;;     Shell got {"Mostly harmless."}
;;     >
;;
(defmodule messenger-back
 (export (print-result 0) (send-message 2)))

(defun print-result ()
  (receive
    ((tuple pid msg)
      (: io format '"Received message: '~s'~n" (list msg))
      (: io format '"Sending message to process ~p ...~n" (list pid))
      (! pid (tuple msg))
      (print-result))))

(defun send-message (calling-pid msg)
  (let ((spawned-pid (spawn 'messenger-back 'print-result ())))
    (! spawned-pid (tuple calling-pid msg))))
{'fraction_non_alphanumeric': 0.14008941877794337, 'fraction_numerical': 0.012667660208643815, 'mean_word_length': 3.323671497584541, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3191433', 'n_tokens_mistral': 815, 'n_tokens_neox': 772, 'n_words': 336}