Hi Jimmy
On 1 July 2012 02:23, Jimmy Ruska <
jimmy...@gmail.com> wrote:
> (funcall (lambda (x) (: erlang hd x)) '(1))
> Is this the easiest way to do something like #'erlang:hd and is that the
> same as what "fun erlang:hd/1" gets converted to in erlang?
Klaus Trainer has a patch which adds writing #'erlang:hd/1 as a
shortcut for (fun erlang hd 2). I have been considering adding it but
have been a bit lazy with LFE for a time now. There are macros (fun
Func Arity) and (fun Mod Func Arity) which build lambdas as in your
example.
Klaus's patch is based on the develop branch of LFE, my suggestion is
to use the develop instead of the master branch. Everything in it
should work. It needs a little cleaning up, mainly an inferior LFE
mode for emacs which works but needs some polish, and I will fix it
and merge it into the master branch.
> I made macro for function composition just messing around
> (defmacro gof (l) (: lists foldr (lambda (x accu) (list 'funcall x
> accu)) (car l) (cdr l)))
> It does this:
> (gof '(1 a b)) -> (a (b 1))
> Does that look ok? If I want to be able to mix lambdas with local and remote
> functions what would be the best way of doing it? Is there a list of all the
> functions available in LFE somewhere? Is there maybe a screencast?
I think that looks fine, my only question would be whether to have it
as (gof '(a b 1)) or (gof a b 1) instead?
The only documentation is in doc/user_guide.txt which does list most,
if not all, of the core functions and predefined macros. It should be
correct as well. There is a definite need for more and better
documentation but there is probably a bit of of a catch-22 here:
should I find the time to write if there aren't any users and there
won't be more users until it is written.
There is now an alternative for lisp on Erlang, Joxa. It is more
clojure like, and of course LFE and Joxa are incompatible. :-) I
naturally prefer my version.
> I had fiddled with LFE in the past but I'm trying to take a more serious
> look at it now. I think it's really great though I wish there was more
> blogs/tutorials online. I wish it had the &body option at least for macros.
The closest you can easily get today is to do
(defmacro a x `(list ,(hd x) ,(tl x)))
where x will be bound to the whole argument list. Or maybe
(defmacro a ((list x y . z) `(list x y z)))
where you have to put the args and body in their own list like in
match-lambda. z will now get the rest of the argument list.
The reason for this is that the argument list of a defmacro is treated
the same way as for a defun to detect whether to expand to a lambda or
match-lambda. It might not have been a good idea to have this
distinction.
> - Jimmy
Robert