Re: A few questions

53 views
Skip to first unread message

Steve Freitas

unread,
Jul 1, 2012, 3:04:44 PM7/1/12
to lisp-flavo...@googlegroups.com
On 06/30/12 17:23, Jimmy Ruska wrote:
> Btw https://github.com/rvirding/lfe/wiki links to this google groups
> with .se instead of .com so it turns the buttons swedish.

Not seeing this problem here.

Steve

Robert Virding

unread,
Jul 1, 2012, 8:34:46 PM7/1/12
to lisp-flavo...@googlegroups.com, jimmy...@gmail.com
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.

> Btw https://github.com/rvirding/lfe/wiki links to this google groups with
> .se instead of .com so it turns the buttons swedish.
>
> 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

Jimmy Ruska

unread,
Jul 1, 2012, 10:36:20 PM7/1/12
to lisp-flavo...@googlegroups.com, jimmy...@gmail.com
> 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?

That is why I would like to have the &body thing. Then I could do a variable number of functions to use for composition without using the list like (gof SomeVar #'print #'trim #'reverse #'lower) instead of (gof '(SomeVar #'print #'trim #'reverse #'lower)). In elisp I can accomplish this with (defmacro gof (x &rest args) (reduce #'list args :from-end t :initial-value x)). Making a macro version of andalso, orelse that take multiple args also comes to mind. I'm not a lisp pro by any means so I may just be not understanding.  It's not a big difference using a list so no big deal if I can't make it work with macros.

I appreciate the explanation. I'll try to fiddle with macros you mentioned, if I ever make anything useful I'll try to post it back here. I've liked playing with it so far and the pattern matching / guard setup with lisp syntax is really neat.

>Steve: Not seeing this problem here.

It adds hl=sv in the query string of url when I click it. Maybe it's because I haven't set some option in preferences.

Thanks for your time,
Jimmy
Reply all
Reply to author
Forward
0 new messages