Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

LFE (programming language)

From Wikipedia, the free encyclopedia
Coding language, extension for Erlang
icon
This articlerelies excessively onreferences toprimary sources. Please improve this article by addingsecondary or tertiary sources.
Find sources: "LFE" programming language – news ·newspapers ·books ·scholar ·JSTOR
(August 2020) (Learn how and when to remove this message)
LFE
ParadigmMulti-paradigm:concurrent,functional
FamilyErlang,Lisp
Designed byRobert Virding
DeveloperRobert Virding
First appeared2008; 18 years ago (2008)
Stable release
2.1.1 / 6 January 2023; 3 years ago (2023-01-06)
Typing disciplinedynamic,strong
Implementation languageErlang
OSCross-platform
LicenseApache 2.0
Filename extensions.lfe .hrl
Websitelfe.io
Influenced by
Erlang,Common Lisp,Maclisp,Scheme,Elixir,Clojure,Hy
Influenced
Joxa, Concurrent Schemer

Lisp Flavored Erlang (LFE) is afunctional,concurrent,garbage collected, general-purposeprogramming language andLispdialect built on CoreErlang and the Erlang virtual machine (BEAM). LFE builds on Erlang to provide a Lisp syntax for writing distributed,fault-tolerant, softreal-time, non-stop applications. LFE also extends Erlang to supportmetaprogramming with Lisp macros and an improved developer experience with a feature-richread–eval–print loop (REPL).[1] LFE is actively supported on all recent releases of Erlang; the oldest version of Erlang supported is R14.

History

[edit]
Robert Virding

Initial release

[edit]

Initial work on LFE began in 2007, when Robert Virding started creating a prototype of Lisp running on Erlang.[2] This work was focused primarily on parsing and exploring what an implementation might look like. No version control system was being used at the time, so tracking exact initial dates is somewhat problematic.[2]

Virding announced the first release of LFE on theErlang Questions mail list in March 2008.[3] This release of LFE was very limited: it did not handle recursiveletrecs,binarys,receive, ortry; it also did not support a Lisp shell.[4]

Initial development of LFE was done with version R12B-0 of Erlang[5] on a Dell XPS laptop.[4]

Timeline of Lisp dialects
19581960196519701975198019851990199520002005201020152020
 LISP 1, 1.5,LISP 2(abandoned)
 Maclisp
 Interlisp
 MDL
 Lisp Machine Lisp
 Scheme R5RS R6RS R7RS small
 NIL
 ZIL (Zork Implementation Language)
 Franz Lisp
 muLisp
 Common Lisp ANSI standard
 Le Lisp
 MIT Scheme
 XLISP
 T
 Chez Scheme
 Emacs Lisp
 AutoLISP
 PicoLisp
 Gambit
 EuLisp
 ISLISP
 OpenLisp
 PLT Scheme Racket
 newLISP
 GNU Guile
 Visual LISP
 Clojure
 Arc
 LFE
 Hy

Motives

[edit]

Robert Virding has stated that there were several reasons why he started the LFE programming language:[2]

  • He had prior experience programming in Lisp.
  • Given his prior experience, he was interested in implementing his own Lisp.
  • In particular, he wanted to implement a Lisp in Erlang: not only was he curious to see how it would run on and integrate with Erlang, he wanted to see what it wouldlook like.
  • Since helping to create the Erlang programming language, he had had the goal of making a Lisp which was specifically designed to run on the BEAM and able to fully interact with Erlang/OTP.
  • He wanted to experiment withcompiling another language on Erlang. As such, he saw LFE as a means to explore this by generating Core Erlang and plugging it into the backend of the Erlang compiler.

Features

[edit]

Syntax and semantics

[edit]

Symbolic expressions (S-expressions)

[edit]

Like Lisp, LFE is anexpression-oriented language. Unlike non-homoiconic programming languages, Lisps make no or little syntactic distinction betweenexpressions andstatements: all code and data are written as expressions. LFE brought homoiconicity to the Erlang VM.

Lists

[edit]

In LFE, the list data type is written with its elements separated by whitespace, and surrounded by parentheses. For example,(list12'foo) is a list whose elements are the integers1 and2, and the atom [[foo|foo]]. These values are implicitly typed: they are respectively two integers and a Lisp-specific data type called asymbolic atom, and need not be declared as such.

As seen in the example above, LFE expressions are written as lists, usingprefix notation. The first element in the list is the name of aform, i.e., a function, operator, or macro. The remainder of the list are the arguments.

Operators

[edit]

The LFE-Erlang operators are used in the same way. The expression

(*(+123456)2)

evaluates to 42. Unlike functions in Erlang and LFE, arithmetic operators in Lisp arevariadic (orn-ary), able to take any number of arguments.

Lambda expressions and function definition

[edit]

LFE haslambda, just like Common Lisp. It also, however, haslambda-match to account for Erlang's pattern-matching abilities in anonymous function calls.

Erlang idioms in LFE

[edit]

This section does not represent a complete comparison between Erlang and LFE, but should give a taste.

Pattern matching

[edit]

Erlang:

1>{Len,Status,Msg}={8,ok,"Trillian"}.{8,ok,"Trillian"}2>Msg."Trillian"

LFE:

lfe>(set(tuplelenstatusmsg)#(8ok"Trillian"))lfe>;; or with LFE literal tuple syntax:lfe>(set`#(,len,status,msg)#(8ok"Trillian"))#(8ok"Trillian")lfe>msg"Trillian"

List comprehensions

[edit]

Erlang:

1>[trunc(math:pow(3,X))||X<-[0,1,2,3]].[1,3,9,27]

LFE:

lfe>(list-comp((<-x'(0123)))(trunc(math:pow3x)))(13927)

Or idiomatic functional style:

lfe>(lists:map(lambda(x)(trunc(math:pow3x)))'(0123))(13927)

Guards

[edit]

Erlang:

right_number(X)whenX==42;X==276709->true;right_number(_)->false.

LFE:

(defunright-number?((x)(when(orelse(==x42)(==x276709)))'true)((_)'false))

cons'ing in function heads

[edit]

Erlang:

sum(L)->sum(L,0).sum([],Total)->Total;sum([H|T],Total)->sum(T,H+Total).

LFE:

(defunsum(l)(suml0))(defunsum(('()total)total)(((consht)total)(sumt(+htotal))))

or using a ``cons`` literal instead of the constructor form:

(defunsum(l)(suml0))(defunsum(('()total)total)((`(,h.,t)total)(sumt(+htotal))))

Matching records in function heads

[edit]

Erlang:

handle_info(ping,#state{remote_pid=undefined}=State)->gen_server:cast(self(),ping),{noreply,State};handle_info(ping,State)->{noreply,State};

LFE:

(defunhandle_info(('ping(=(match-stateremote-pid'undefined)state))(gen_server:cast(self)'ping)`#(noreply,state))(('pingstate)`#(noreply,state)))

Receiving messages

[edit]

Erlang:

universal_server()->receive{become,Func}->Func()end.

LFE:

(defununiversal-server()(receive((tuple'becomefunc)(funcallfunc))))

or:

(defununiversal-server()(receive(`#(become,func)(funcallfunc))))

Examples

[edit]

Erlang interoperability

[edit]

Calls to Erlang functions take the form(<module>:<function> <arg1> ... <argn>):

(io:format"Hello, World!")

Functional paradigm

[edit]

Using recursion to define theAckermann function:

(defunackermann((0n)(+n1))((m0)(ackermann(-m1)1))((mn)(ackermann(-m1)(ackermannm(-n1)))))

Composing functions:

(defuncompose(fg)(lambda(x)(funcallf(funcallgx))))(defuncheck()(let*((sin-asin(compose#'sin/1#'asin/1))(expected(sin(asin0.5)))(compose-result(funcallsin-asin0.5)))(io:format"Expected answer: ~p~n"(listexpected))(io:format"Answer with compose: ~p~n"(listcompose-result))))

Concurrency

[edit]

Message-passing with Erlang's light-weight "processes":

(defmodulemessenger-back(export(print-result0)(send-message2)))(defunprint-result()(receive((tuplepidmsg)(io:format"Received message: '~s'~n"(listmsg))(io:format"Sending message to process ~p ...~n"(listpid))(!pid(tuplemsg))(print-result))))(defunsend-message(calling-pidmsg)(let((spawned-pid(spawn'messenger-back'print-result())))(!spawned-pid(tuplecalling-pidmsg))))

Multiple simultaneous HTTP requests:

(defunparse-args(flag)"Given one or more command-line arguments, extract the passed values.  For example, if the following was passed via the command line:    $ erl -my-flag my-value-1 -my-flag my-value-2  One could then extract it in an LFE program by calling this function:    (let ((args (parse-args 'my-flag)))      ...      )  In this example, the value assigned to the arg variable would be a list  containing the values my-value-1 and my-value-2."(let((`#(ok,data)(init:get_argumentflag)))(lists:mergedata)))(defunget-pages()"With no argument, assume 'url parameter was passed via command line."(let((urls(parse-args'url)))(get-pagesurls)))(defunget-pages(urls)"Start inets and make (potentially many) HTTP requests."(inets:start)(plists:map(lambda(x)(get-pagex))urls))(defunget-page(url)"Make a single HTTP request."(let*((method'get)(headers'())(request-data`#(,url,headers))(http-options())(request-options'(#(syncfalse))))(httpc:requestmethodrequest-datahttp-optionsrequest-options)(receive(`#(http#(,request-id#(error,reason)))(io:format"Error: ~p~n"`(,reason)))(`#(http#(,request-id,result))(io:format"Result: ~p~n"`(,result))))))

References

[edit]
  1. ^Virding, Robert."Lisp Flavored Erlang"(PDF).Erlang Factory. Retrieved2014-01-17.
  2. ^abc"LFE History on the Lisp Flavored Erlang mail list". Retrieved2014-05-28.
  3. ^"LFE announcement on Erlang Questions mail list". Retrieved2014-01-17.
  4. ^abArmstrong, Joe; Virding, Robert (2013-12-30)."Hardware used in the development of Erlang and LFE" (Email exchange). Interviewed by Duncan McGreggor. Retrieved2014-01-17.
  5. ^"Follow-up to LFE announcement on Erlang Questions mail list". Retrieved2014-01-17.

External links

[edit]
Features
Object systems
Implementations
Standardized
Common
Lisp
Scheme
ISLISP
Unstandardized
Logo
POP
Operating system
Hardware
Community
of practice
Technical standards
Education
Books
Curriculum
Organizations
Business
Education
People
Common
Lisp
Scheme
Logo
POP
Retrieved from "https://en.wikipedia.org/w/index.php?title=LFE_(programming_language)&oldid=1327584240"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp