Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lisp Flavored Erlang - Messaging primitives

Tags:

erlang

lisp

lfe

I've read through all the documentation, and most of the source of LFE. All the presentations emphasize basic lisp in traditional lisp roles - General Problem Solving, Hello world and syntax emulating macros.

Does anyone know how LFE handles messaging primitives? To specify a more precise question, how would you express this erlang:

A = 2,  
Pid = spawn(fun()->  
    receive  
        B when is_integer(B) -> io:format("Added: ~p~n",[A+B]);  
        _ -> nan  
    end  
end), 
Pid ! 5.  

And then, you know, it mumbles something about having added up some numbers and the answer being 7.

like image 883
Chris Hagan Avatar asked Feb 03 '23 08:02

Chris Hagan


1 Answers

I'm not an LFE user, but there is a user guide in the source tree. From reading it I would guess it is something like this:

(let ((A 2))
  (let ((Pid (spawn (lambda ()
                      (receive
                        (B (when (is_integer B))
                          (: io format "Added: ~p~n" (list (+ A B))))
                        (_ nan))))))
    (! Pid 5)))

But I'm very likely to have made a mistake since I haven't even evaluated it in LFE.

Some questions of mine:

  • Is there a LET* form or is it behaving like one already?
  • Are guards called the more lispy is-integer and not is_integer as I wrote?
like image 75
Christian Avatar answered Feb 14 '23 07:02

Christian