lisp - Value from binding in LFE interpreter using Erlang -


i'd use lisp flavored erlang scripting extension language erlang application. if want, in similar way gnu emacs configured , extended via emacs lisp.

i know argument wide , structured; in specific case of question i'd being able read binding name (or variable, if prefer) defined in lfe erlang code.

i'm not expert of lfe internal architecture (which excellent example of software engineering , erlang programming), not able find answer neither in sources nor in documentation. looking @ sources can see lfe contains both compiler target erlang vm , interpreter. latter 1 i'm trying use.

if start erlang shell/repl in lfe installation path (on system $home/opt/lfe):

 $ cd /path/to/lfe-install-dir $ erl -pa ./ebin 

i'm able calculate value:

 1> {ok, expr} = lfe_io:read_string("(+ 1 10)"). {ok,['+',1,10]} 2> result = lfe_eval:expr(expr). 11 

this first step, not want. i'd rather bind variable , read value; that's issue:

 3> {ok, expr2} = lfe_io:read_string("(set 10)"). {ok,[set,a,10]} 4> lfe_eval:expr(expr2). ** exception error: {unbound_func,{set,2}}      in function  lfe_eval:eval_expr/2 

why set recognized unbound function? in lfe repl expression valid:

 erlang/otp 17 [erts-6.4] [source] [64-bit] [smp:4:4] ... lfe shell v6.4 (abort ^g) > (set 10) 10 > 10 

i'm using api in wrong way. how can read content of a and/or initialize lfe interpreter?

(if explained somewhere, please provide reference).

i won't attempt answer broader question "best practices" of adding scripting. seems me choosing between "hook-based" solution (in define hook implementations name convention , automatically recognized) , "explicit api" solution (in use functions predefinied in scripting enviroment register hooks or otherwise call configuration functions) largely matter of taste. explicit calls (set-connection-timeout-handler ...) may more readable, easier debug (no misspelling problems, no surprises on api changes), easier document, , bit more flexible, more, well, explicit.

building simple variable definition example, here few ways started going further "interpreted" path:

1> {ok, expr} = lfe_io:read_string("'((a 10))"). {ok,[quote,[[a,10]]]} 2> lfe_eval:expr (expr). [[a,10]]  3> evalall = fun (conf) -> {ok, e} = lfe_io:read_string("'(" ++ conf ++ ")"), lfe_eval:expr(e) end. #fun<erl_eval.6.90072148> 4> evalall ("(a 10) (b 11)").                                                                       [[a,10],[b,11]]  5> evalalll = fun (conf) -> {ok, e} = lfe_io:read_string("(list " ++ conf ++ ")"), lfe_eval:expr(e) end. #fun<erl_eval.6.90072148> 6> [{f, f}] = evalalll ("(tuple 'f (lambda (x) (+ 10 x)))"). [{f,#fun<lfe_eval.12.2018457>}] 7> f (12). 22  8> g = fun (x) -> x * 2 end. #fun<erl_eval.6.90072148> 9> lfe_eval:expr (element (2, lfe_io:read_string ("(g 15)")), lfe_eval:add_lexical_func(g, 1, g, lfe_env:new ())). 30 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -