[erlang-questions] Lisp syntax for Erlang

Hynek Vychodil vychodil.hynek@REDACTED
Tue Dec 4 13:21:43 CET 2007


On 12/4/07, YC <yinso.chen@REDACTED> wrote:
>
> On Dec 2, 2007 4:21 AM, Robert Virding <rvirding@REDACTED> wrote:
> >
> >
> >
> > > I mean I have to sensibly be able to handle the case where someone
> writes (cons a mod:fun). What does this mean?
>
> >
> >
> > > - Seeing this is based on Erlang I can't introduce any new data types.
> So with the argument above I can't have variables as a separate > data type,
> separate from symbols/atoms. So Mod:fun will mean the same as mod:fun but
> with a different name. Now that was clear :-)
>
> >
> >
> > > So that is why I have no better suggestion for the moment to the general
> function (remote-call <mod> <fun> ... ) and its short hand > form the macro
> (: mod fun ... )
> >
>
> IMHO, the issues above arise from the goal being unclear: is it a lispy
> syntax for erlang or is it a lisp in erlang?
>
> If it's a lispy syntax, IMO a prefix<->infix transformer can handle a lot of
> cases (below uses vector for tuples):
>
> %% Erlang => ErlangInLisp
> A + 1, => (+ A 1)
> A = 5. => (= A 5).
> [foo | bar] => (| foo bar)
> Pid ! Data => (! Pid Data)
>  A = {foo, bar}. => (= A #(foo bar)) %% or (= A {foo bar}) (either works
> fine, but vector version appears more uniform and in spirit of lisp)
> fun(A) -> A + 1. => (lambda (A) (+ A 1)) %% I think fun is fine.
>  case A of foo -> {foo}; bar -> {foo, bar} end. => (case A ((foo) bar)
> ((bar) #(foo bar)))
You mean
case A of foo -> {foo}; bar -> {foo, bar} end. => (case A ((foo) #(foo))
 ((bar) #(foo bar)))
don't you?
> foo(1) -> 2; foo(abc) -> {foo, bar}. => (defun foo ((1) 2) ((abc) #(foo
> bar)))
> mod:fun(foo) => (mod:fun foo) or ((: mod fun) foo)
> Mod:fun(foo) => (Mod:fun foo) or ((: Mod fun) foo) %% the second style is
> more uniform for both mod & Mod.
> {ok, B} = mod:fun(). => (= #(ok B) (mod:fun))  or  (=  {ok B} ((: mod fun)))
>
>
> (I think "let" is something that'll be handy and can be introduced, as
> commas make the code more spaghetti-ish)
>
> And keep the rest of the erlang syntax such as Camel casing for variable,
> pattern matching built-in default, bare words as atoms unless at the the
> head of a list (or unless in special syntax such as case), etc.
>
> If the goal is to write a lisp compiler, then either CL or Scheme has
> already offered their definitions (of course you can invent your own too).
> In CL mod:fun means calling the function fun in module mod, and in scheme it
> simply is a symbol binding that can mean anything.  By default lisp doesn't
> have pattern matching, but if you are introducing macro then you can of
> course gain it back.
>
> The issue with (remote-call) is that it's tedious.  Think of having to write
> that for all function calls that don't live in the current module namespace.
>  And it also takes on meaning of apply/3.
>
> If mod:fun(Args)  is writtten as (remote-call mod fun Args), then how to
> write apply/3?
>
> Should we write apply(mod, fun, Args) as (apply (remote-call mod fun
> Args))??  Then it's apply/1.
>
> Probably better to have remote-call take on the meaning of apply/3. I don't
> think all function calls should go through apply.
>
> Cheers,
> yc
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>


-- 
--Hynek (Pichi) Vychodil



More information about the erlang-questions mailing list