guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Guile lisp code style (was: [guile] Re: Guile and Swig)


From: Daniel Hartwig
Subject: Re: Guile lisp code style (was: [guile] Re: Guile and Swig)
Date: Fri, 19 Apr 2013 15:46:47 +0800

On 19 April 2013 14:15, Dmitry Bogatov <address@hidden> wrote:
>
> Daniel Hartwig <address@hidden> writes:
>>> Also, question of style of Lisp code. It seems, that most common style
>>> is `(action object arg1 ...)` and I find making object callable is more
>>> elegant: `(object #:action arg1 ...)`. Is it discouraged?
>> On some level both styles are functionally equivalent, although
>> conceptually they are quite different.  It is more or less a matter of
>> taste.  However, certain tasks are easier in one style or the other.
> Of course. Essentially, it is question about object vs procedural style.
>
>> Why do you find the second style more elegant?
> I do not have to create a lot of foo-make-thing, foo-make-other
> functions with, essentially, elisp or C naming conventions.

Ah. The module system in Guile alleviates the need to prefix all
identifiers with ‘foo-’.  You do not have to worry that potentially
common names such as ‘make-session’ or ‘connect’ will interfere with
bindings in other modules as namespaces are kept separate.  In the
event of a clash (i.e. my program imports your module and another
which both define ‘connect’) it is trivial for me to refer precisely
to the binding in your module, or install a prefix *as I use it*,
etc..

This way, you can have short identifiers that are still globally unique.  Bonus!

> I still do not have feeling of functionality paradigm of Lisp, so I am
> trying to use object-oriented paradigm. Probably, it is aganist spirit
> of language.
>

I would not say against the spirit of the language, just uncommon.
One reason to avoid the callable object style is to decouple interface
and data, which is generally more convenient both logically and
technically (i.e. implementing and extending).  Even typical object
systems in lisp (e.g. CLOS, GOOPS) avoid the style, prefering the
common pattern of operator followed by data.  There is nothing more or
less “object oriented” about either style.

It is really only on systems without multiple dispatch (e.g. C++,
Python) that you see the “object”-first style.  Due to requirements of
single dispatch, one of the calls arguments must be blessed to
determine which procedure implements the call.  It is logical to make
that the first argument, and from there only a small matter of
emphasis to use "arg procedure" rather than "procedure arg".

Personally, I say stick with ‘(procedure arg ...)’ unless there is a
compelling logical reason to consider the interface and data tightly
coupled.  Taking a look at the libircclient C API, it does not appear
that there is such a reason.


All about 2c worth.

Regards



reply via email to

[Prev in Thread] Current Thread [Next in Thread]