Subject: Re: Question: Lisp's power points
From: Erik Naggum <erik@naggum.net>
Date: Sat, 13 Oct 2001 16:43:39 GMT
Newsgroups: comp.lang.lisp
Message-ID: <3211980215750828@naggum.net>

* Rolf Wester
| My question was meant seriously, my point was not to gripe about anything.

  Then you deserve a better answer.

| I'm not very familiar with CL but I'm fascinated by it's capabilities as
| far as I recognized them.  As I mostly programmed in Fortran/C++/Java
| it's not so obvious for me to see in what respect Lisps level of
| abstraction is much higher compared to other languages.

  This is actually a serious problem for Common Lisp, and you are far from
  alone in experiencing its effects.  For instance, take special variables.
  People who do now know how they work, tend to dismiss them as some old
  Lisp concept that should not have survived.  Then they write code that
  uses some global variables and they _set_ their values, they get yelled
  at for using global variables whose values are hard to track, and they
  think that global state is a bad thing.  However, the bad thing about
  global variables is that they do _not_ have the infrstructure offered by
  special binding in Common Lisp.  A function may legitimately desire to
  change the global state for a carefully controlled duration, but in order
  to do so, you have to guarantee that the old state is restored.  This is
  truly hard if the language does not support it.  Exceptions and other
  non-local control transfers intervene.  Storing the variable in some
  local variable is not always trivial -- you need to replicate an object
  with the same type as the global variable, and the language does not give
  you that obvious operation, either -- and then you need to ensure that
  the stored value is put back into the global variable before you return,
  which can be foiled by the kind of unconscious programmers that are
  likely to mess with our code.  So C++ people tend to think that special
  variables are useless, but in fact, they solve a very serious problem
  that C++ programmers do not generally try to solve because it is too hard
  and generally too painful in their language.  Sticking to the convenient,
  they use semi-global state variables and are nervous.  The abstraction
  offered by special variables is thus hard to grasp for the programmer who
  does not even perform the concrete operations the abstraction automates
  and hides.  Even Common Lisp programmers are generally unaware of the
  concrete mechanisms underlying the abstraction.  The impact on threads,
  for instance, is not quite obvious: One variable may be so global that it
  should affect all threads, while another may have a thread-local global
  value.  This means that implementationally, a thread context switch needs
  to re-bind special variables if they share a Lisp image, and involve IPC
  and shared memory between threads if the variable is thread-global.  This
  is so hairy stuff that even good programmers would shy away from thinking
  about using such things if they had to do it manually.  To a Common Lisp
  programmer, it is a natural extension to special variables, even though
  conceptually much more advanced.  Other forms of context switches may
  also be desirable, so it makes sense to expose the control mechanism for
  rebinding special variables, but this could now be done separately from
  the bindings because the infrastructure for bindings is already there.
  Thus the abstraction offered by special binding in Common Lisp spans an
  enormous amount of otherwise manual work, and they are not only "global
  variables", which is how some think of them, it is also a mechanism that
  can be used for variables that are _not_ global, but require the support
  of binding and unbinding of variables that can be shared only among a few
  functions that know about them.  Therefore, there is a local declaration
  to request special binding of an otherwise lexical variable in addition
  to the global declaration to request it of all bindings of a symbols, and
  the global declaration applies to the symbol regardless of its context,
  because specialness of a symbol must be pervasive to work at all.  This
  means that the mechanism behind the special binding is very different
  from the global variable in many other languages, which may be shadowed
  by a lexical binding (except they do not call it that).

| P.S.: My mother language is not English so misunderstandings may arise
| because I can't express myself in English as precisely as I could do in
| German.

  It is probably OK to include the German if you are uncertain about an
  expression -- even if people here write in English, the language skills
  of the community is pretty amazing, and you could get tips and hints that
  would not get anywhere else.  For instance, "Muttersprache" and "mother
  tongue" and "langue maternelle" have the common Latin etymology "lingua
  materna", but still it does not really work all that well to translate
  directly between them in any direction...

///
-- 
  The United Nations before and after the leadership of Kofi Annan are two
  very different organizations.  The "before" United Nations did not deserve
  much credit and certainly not a Nobel peace prize.  The "after" United
  Nations equally certainly does.  I applaud the Nobel committee's choice.